I’m trying to set up an Azure App Service using custom docker images. The images are built in one of my private repo on github and pushed to the github registry. In another repository, I’m setting up the deploy workflow through Github Actions and I followed the steps in this guide.
The current workflow is defined as follows:
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: azure/docker-login@v1
with:
login-server: ghcr.io/
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- uses: azure/webapps-deploy@v2
with:
app-name: 'my-app-name'
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
images: 'ghcr.io/${{ secrets.REGISTRY_USERNAME}}/my-repo-name:my-tag'
Once pushed, the action runs successfully. But when I go to the app URL, it is not displayed due to errors.
The following are the Azure App Service logs related to Docker Engine:
where red is my github username, green is my private repo (which is also the image name), blue is the image tag and yellow the Azure App Service name.
What is going wrong?
The only hint I have is that the azure/docker-login
action only logs to the private github registry within the action workflow, but when the App Service is started it requires to log in again to the private registry to pull the image. But I could not find any instruction on how to provide again the credentials to log in.
EDIT 1:
I set secrets.REGISTRY_USERNAME
to my github username and secrets.REGISTRY_PASSWORD
to my github account password, since I think these are the right credentials to log in into my private github registry.
2
Answers
You can use the below code to publish the docker image using git repository (code-base). Code build and push build artifacts part in another action and this action read those build artifacts and builds a docker image.
The best practice is to push the image to the Azure container registry and use that image in Azure web app
You are missing the push part.
Here you have an example how to use it with ghcr and some style.
docker/login-action
– you can use built in variables for authdocker/metadata-action
– generates tags for you. See docs for more config options.docker/build-push-action
– exactly what the name says. This is what you were missing the most.images: "${{ steps.meta.outputs.tags }}"
– use autogenerated tag 🙂To further improve this job could be split into two
build
anddeploy