|
| 1 | +# This workflow will build a container and deploy it to an Azure Functions App on Linux when a commit is pushed to your default branch. |
| 2 | +# |
| 3 | +# This workflow assumes you have already created the target Azure Functions app. |
| 4 | +# For instructions see https://learn.microsoft.com/en-us/azure/azure-functions/functions-create-function-linux-custom-image?tabs=in-process%2Cbash%2Cazure-cli&pivots=programming-language-csharp |
| 5 | +# |
| 6 | +# To configure this workflow: |
| 7 | +# 1. Set up the following secrets in your repository: |
| 8 | +# - AZURE_RBAC_CREDENTIALS |
| 9 | +# - REGISTRY_USERNAME |
| 10 | +# - REGISTRY_PASSWORD |
| 11 | +# 2. Change env variables for your configuration. |
| 12 | +# |
| 13 | +# For more information on: |
| 14 | +# - GitHub Actions for Azure: https://github.com/Azure/Actions |
| 15 | +# - Azure Functions Container Action: https://github.com/Azure/functions-container-action |
| 16 | +# - Azure Service Principal for RBAC: https://github.com/Azure/functions-action#using-azure-service-principal-for-rbac-as-deployment-credential |
| 17 | +# |
| 18 | +# For more samples to get started with GitHub Action workflows to deploy to Azure: https://github.com/Azure/actions-workflow-samples/tree/master/FunctionApp |
| 19 | + |
| 20 | +name: Deploy container to Azure Functions App |
| 21 | + |
| 22 | +on: |
| 23 | + push: |
| 24 | + branches: ["main"] |
| 25 | + |
| 26 | +permissions: |
| 27 | + contents: read |
| 28 | + |
| 29 | +env: |
| 30 | + AZURE_FUNCTIONAPP_NAME: 'your-app-name' # set this to your function app name on Azure |
| 31 | + LOGIN_SERVER: 'login-server' # set this to login server for your private container registry (e.g. 'contoso.azurecr.io', 'index.docker.io' ) |
| 32 | + REGISTRY: 'your-registry' # set this to proper value for REGISTRY |
| 33 | + NAMESPACE: 'your-namespace' # set this to proper value for NAMESPACE |
| 34 | + IMAGE: 'your-image' # set this to proper value for IMAGE |
| 35 | + TAG: 'your-tag' # set this to proper value for TAG |
| 36 | + |
| 37 | +jobs: |
| 38 | + build-and-deploy: |
| 39 | + runs-on: ubuntu-latest |
| 40 | + environment: dev |
| 41 | + steps: |
| 42 | + - name: 'Checkout GitHub Action' |
| 43 | + uses: actions/checkout@v4 |
| 44 | + |
| 45 | + - name: 'Login via Azure CLI' |
| 46 | + uses: azure/login@v1 |
| 47 | + with: |
| 48 | + creds: ${{ secrets.AZURE_RBAC_CREDENTIALS }} |
| 49 | + |
| 50 | + - name: 'Docker Login' |
| 51 | + uses: azure/docker-login@v1 |
| 52 | + with: |
| 53 | + login-server: ${{ env.LOGIN_SERVER }} |
| 54 | + username: ${{ secrets.REGISTRY_USERNAME }} |
| 55 | + password: ${{ secrets.REGISTRY_PASSWORD }} |
| 56 | + |
| 57 | + - name: 'Compose Customized Docker Image' |
| 58 | + shell: bash |
| 59 | + run: | |
| 60 | + # If your function app project is not located in your repository's root |
| 61 | + # Please change the path to your directory for docker build |
| 62 | + docker build . -t ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE }}:${{ env.TAG }} |
| 63 | + docker push ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE }}:${{ env.TAG }} |
| 64 | +
|
| 65 | + - name: 'Run Azure Functions Container Action' |
| 66 | + uses: Azure/functions-container-action@v1 |
| 67 | + id: fa |
| 68 | + with: |
| 69 | + app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }} |
| 70 | + image: ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE }}:${{ env.TAG }} |
| 71 | + |
| 72 | + # If you want to display or use the functionapp url, then uncomment the task below |
| 73 | + #- name: 'Published functionapp url' |
| 74 | + # run: | |
| 75 | + # echo "${{ steps.fa.outputs.app-url }}" |
| 76 | + |
| 77 | + - name: Azure logout |
| 78 | + run: | |
| 79 | + az logout |
0 commit comments