|
| 1 | +# This workflow will build and push a Docker container to an Azure Web App when a commit is pushed to your default branch. |
| 2 | +# |
| 3 | +# This workflow assumes you have already created the target Azure App Service web app. |
| 4 | +# For instructions see https://docs.microsoft.com/en-us/azure/app-service/quickstart-custom-container?tabs=dotnet&pivots=container-linux |
| 5 | +# |
| 6 | +# To configure this workflow: |
| 7 | +# |
| 8 | +# 1. Download the Publish Profile for your Azure Web App. You can download this file from the Overview page of your Web App in the Azure Portal. |
| 9 | +# For more information: https://docs.microsoft.com/en-us/azure/app-service/deploy-github-actions?tabs=applevel#generate-deployment-credentials |
| 10 | +# |
| 11 | +# 2. Create a secret in your repository named AZURE_WEBAPP_PUBLISH_PROFILE, paste the publish profile contents as the value of the secret. |
| 12 | +# For instructions on obtaining the publish profile see: https://docs.microsoft.com/azure/app-service/deploy-github-actions#configure-the-github-secret |
| 13 | +# |
| 14 | +# 3. Create a GitHub Personal access token with "repo" and "read:packages" permissions. |
| 15 | +# |
| 16 | +# 4. Create three app settings on your Azure Web app: |
| 17 | +# DOCKER_REGISTRY_SERVER_URL: Set this to "https://ghcr.io" |
| 18 | +# DOCKER_REGISTRY_SERVER_USERNAME: Set this to the GitHub username or organization that owns the repository |
| 19 | +# DOCKER_REGISTRY_SERVER_PASSWORD: Set this to the value of your PAT token from the previous step |
| 20 | +# |
| 21 | +# 5. Change the value for the AZURE_WEBAPP_NAME. |
| 22 | +# |
| 23 | +# For more information on GitHub Actions for Azure: https://github.com/Azure/Actions |
| 24 | +# For more information on the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy |
| 25 | +# For more samples to get started with GitHub Action workflows to deploy to Azure: https://github.com/Azure/actions-workflow-samples |
| 26 | + |
| 27 | +name: Build and deploy a container to an Azure Web App |
| 28 | + |
| 29 | +env: |
| 30 | + AZURE_WEBAPP_NAME: your-app-name # set this to the name of your Azure Web App |
| 31 | + |
| 32 | +on: |
| 33 | + push: |
| 34 | + branches: [ "master" ] |
| 35 | + workflow_dispatch: |
| 36 | + |
| 37 | +permissions: |
| 38 | + contents: read |
| 39 | + |
| 40 | +jobs: |
| 41 | + build: |
| 42 | + runs-on: ubuntu-latest |
| 43 | + |
| 44 | + steps: |
| 45 | + - uses: actions/checkout@v4 |
| 46 | + |
| 47 | + - name: Set up Docker Buildx |
| 48 | + uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0 |
| 49 | + |
| 50 | + - name: Log in to GitHub container registry |
| 51 | + uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0 |
| 52 | + with: |
| 53 | + registry: ghcr.io |
| 54 | + username: ${{ github.actor }} |
| 55 | + password: ${{ github.token }} |
| 56 | + |
| 57 | + - name: Lowercase the repo name and username |
| 58 | + run: echo "REPO=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV} |
| 59 | + |
| 60 | + - name: Build and push container image to registry |
| 61 | + uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0 |
| 62 | + with: |
| 63 | + push: true |
| 64 | + tags: ghcr.io/${{ env.REPO }}:${{ github.sha }} |
| 65 | + file: ./Dockerfile |
| 66 | + |
| 67 | + deploy: |
| 68 | + permissions: |
| 69 | + contents: none |
| 70 | + runs-on: ubuntu-latest |
| 71 | + needs: build |
| 72 | + environment: |
| 73 | + name: 'Development' |
| 74 | + url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} |
| 75 | + |
| 76 | + steps: |
| 77 | + - name: Lowercase the repo name and username |
| 78 | + run: echo "REPO=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV} |
| 79 | + |
| 80 | + - name: Deploy to Azure Web App |
| 81 | + id: deploy-to-webapp |
| 82 | + uses: azure/webapps-deploy@v2 |
| 83 | + with: |
| 84 | + app-name: ${{ env.AZURE_WEBAPP_NAME }} |
| 85 | + publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} |
| 86 | + images: 'ghcr.io/${{ env.REPO }}:${{ github.sha }}' |
0 commit comments