2

My knowledge of Azure is pretty limited - this is the first project where I've worked with it.

We are deploying Azure webapps in docker containers via an Azure pipeline configured with the classic interface. The pipeline has one agent job that looks like this when I click the "View YAML" button:

pool:
  name: Azure Pipelines
steps:
- task: Docker@0
  displayName: 'Build an image'
  inputs:
    azureSubscription: '<omitted>'
    azureContainerRegistry: '{"loginServer":"<omitted>", "id" : "<omitted>"}'
    dockerFile: Dockerfile
    includeSourceTags: true
    includeLatestTag: true

- task: Docker@0
  displayName: 'Push an image'
  inputs:
    azureSubscription: '<omitted>'
    azureContainerRegistry: '{"loginServer":"<omitted>", "id" : "<omitted>"}'
    action: 'Push an image'
    includeSourceTags: true
    includeLatestTag: true

The pipeline isn't really "mine" so I don't want to make any crazy changes but I do have access to edit it and can discuss with the third party admin to make changes if need be.

I need to run a post deployment script to clear caches and such in a container (the app will likely run multiple web containers, it doesn't matter which one the script runs in) after the pipeline finishes.

Unfortunately I just cannot figure out how to do that. Options I've considered:

  • Run it in the container's startup script: containers will also be spun up when the app scales and we don't want to clear the caches in that case
  • Use a container job - this seems to be exactly what I want but unfortunately is not supported in the classic editor. I'd prefer not to rework the devops pipeline entirely since, as mentioned, it's not really "mine"
  • Add a "Docker" task of version 0 with the "Run a Docker command" action and set it to run the "docker exec" command. This seems the most promising but unfortunately there isn't any way I can tell to collect the ID or a name of a just-pushed container (which is a required argument to docker exec). I don't think there's an option to set a name that I can use with docker exec either (I see I can set several tags in the build and push steps but on the image only?), but I'm not too familiar with docker exec either so not 100% sure of that.
  • Add an Azure CLI task that SSHs in to the container and runs a command. Unfortunately it seems like there's no easy way to directly execute a command over Azure's SSH (e.g. via az webapp ssh or az webapp create-remote-connection) so I'm not totally sure whether this would work at all and I suspect it would take many hours of debugging and waiting for containers to deploy to even find out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.