Skip to content
Enable GitHub developers to deploy to Azure WebApp for containers using GitHub Actions
TypeScript JavaScript
Branch: master
Clone or download

Latest commit

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/workflows Adding CI Mar 28, 2020
lib updating package Dec 10, 2019
src Adding CI Mar 28, 2020
.gitignore Adding CI Mar 28, 2020
.nycrc Adding CI Mar 28, 2020
CODE_OF_CONDUCT.md Initial commit Sep 19, 2019
LICENSE Initial commit Sep 19, 2019
README.md Update README.md Mar 26, 2020
SECURITY.md Initial commit Sep 19, 2019
action.yml updating package Dec 10, 2019
package-lock.json Adding CI Mar 28, 2020
package.json Adding CI Mar 28, 2020
tsconfig.json Adding CI Mar 28, 2020

README.md

GitHub Action for deploying to Azure Web App for Containers

GitHub Actions gives you the flexibility to build an automated software development lifecycle workflow.

You can automate your workflows to deploy Azure Web Apps for Containers using GitHub Actions.

Get started today with a free Azure account!

This repository contains GitHub Action for Azure WebApp for containers to deploy to Azure WebApp for Containers. Supports deploying a single container image or multiple containers.

If you are looking for a Github Action to deploy to an Azure WebApp (Windows or Linux), consider using Azure WebApp action.

For deploying container images to Kubernetes, consider using Kubernetes deploy action. This action requires that the cluster context be set earlier in the workflow by using either the Azure/aks-set-context action or the Azure/k8s-set-context action.

The definition of this Github Action is in action.yml.

End-to-End Sample Workflows

Dependencies on other Github Actions

  • Checkout Checkout your Git repository content into Github Actions agent.
  • Azure Login Login with your Azure credentials for Web app deployment authentication. Once login is done, the next set of Azure actions in the workflow can re-use the same session within the job.
  • docker-login : Actions to log in to a private container registry such as Azure Container registry. Once login is done, the next set of Actions in the workflow can perform tasks such as building, tagging and pushing containers.

Azure Service Principle for RBAC

For using any credentials like Azure Service Principal in your workflow, add them as secrets in the GitHub repository and then refer them in the workflow.

  1. Download Azure CLI from here, run az login to login with your Azure credentials.
  2. Run Azure CLI command to create an Azure Service Principal for RBAC:
   az ad sp create-for-rbac --name "myApp" --role contributor \
                            --scopes /subscriptions/{subscription-id}/resourceGroups/{resource-group} \
                            --sdk-auth
                            
  # Replace {subscription-id}, {resource-group} with the subscription, resource group details of the WebApp
  # The command should output a JSON object similar to this:

  {
    "clientId": "<GUID>",
    "clientSecret": "<GUID>",
    "subscriptionId": "<GUID>",
    "tenantId": "<GUID>",
    (...)
  }
  • You can further scope down the Azure Credentials to the Web App using scope attribute. For example,
 az ad sp create-for-rbac --name "myApp" --role contributor \
                          --scopes /subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.Web/sites/{app-name} \
                          --sdk-auth

# Replace {subscription-id}, {resource-group}, and {app-name} with the names of your subscription, resource group, and Azure Web App.
  1. Paste the json response from above Azure CLI to your Github Repository > Settings > Secrets > Add a new secret > AZURE_CREDENTIALS
  2. Now in the workflow file in your branch: .github/workflows/workflow.yml replace the secret in Azure login action with your secret (Refer to the example below)

Build and deploy a Node.js app to Azure WebApp Container

on: [push]

name: Linux_Container_Node_Workflow

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
    # checkout the repo
    - name: 'Checkout Github Action' 
      uses: actions/checkout@master
    
    - name: 'Login via Azure CLI'
      uses: azure/login@v1
      with:
        creds: ${{ secrets.AZURE_CREDENTIALS }}
    
    - uses: azure/docker-login@v1
      with:
        login-server: contoso.azurecr.io
        username: ${{ secrets.REGISTRY_USERNAME }}
        password: ${{ secrets.REGISTRY_PASSWORD }}
    
    - run: |
        docker build . -t contoso.azurecr.io/nodejssampleapp:${{ github.sha }}
        docker push contoso.azurecr.io/nodejssampleapp:${{ github.sha }} 
      
    - uses: azure/webapps-container-deploy@v1
      with:
        app-name: 'node-rnc'
        images: 'contoso.azurecr.io/nodejssampleapp:${{ github.sha }}'
    
    - name: Azure logout
      run: |
        az logout

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

You can’t perform that action at this time.