Last active
October 28, 2020 23:27
-
-
Save ahmedig/f37c083d0977de0da96b3e5c0bd7f330 to your computer and use it in GitHub Desktop.
Github workflow - Build, push to ACR and deploy to App Service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Push Docker Image to ACR | |
# Controls when the action will run. Triggers the workflow on push or pull request | |
# events but only for the master branch | |
on: | |
push: | |
branches: [ master ] | |
# paths: | |
# - "src/**" | |
pull_request: | |
branches: [ master ] | |
# paths: | |
# - "src/**" | |
workflow_dispatch: | |
inputs: | |
InvokedBy: | |
description: 'Name' | |
required: false | |
env: | |
CONTAINER_REGISTRY: ahmedigregistry.azurecr.io | |
image_name: appdemo | |
AZURE_WEBAPP_NAME: ahmedigwebapp | |
# defaults: | |
# run: | |
# working-directory: IaC | |
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | |
jobs: | |
# This workflow contains a job called "build" | |
build: | |
# The type of runner that the job will run on | |
runs-on: ubuntu-latest | |
# Steps represent a sequence of tasks that will be executed as part of the job | |
steps: | |
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | |
- uses: actions/checkout@v2 | |
# Runs a single command using the runners shell | |
- name: Run a one-line script | |
run: echo Hello, world! | |
- name: Azure Container Registry Login | |
uses: Azure/docker-login@v1 | |
with: | |
# Container registry username | |
username: ${{ secrets.ACR_USERNAME }} | |
# Container registry password | |
password: ${{ secrets.ACR_PASSWORD }} | |
# Container registry server url | |
login-server: ${{env.CONTAINER_REGISTRY}} | |
- name: Push Container to ACR | |
working-directory: src | |
run: | | |
docker build . -t ${{env.CONTAINER_REGISTRY}}/${{env.image_name}}:${{ github.sha }} | |
docker push ${{env.CONTAINER_REGISTRY}}/${{env.image_name}}:${{ github.sha }} | |
DeployWebApp: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | |
- uses: actions/checkout@v2 | |
- name: Azure authentication | |
uses: azure/login@v1 | |
with: | |
creds: ${{ secrets.AZURE_CREDENTIALS }} | |
# - name: Azure CLI script to provision a new Web App for Container | |
# uses: azure/CLI@v0-beta | |
# with: | |
# azcliversion: latest | |
# inlineScript: | | |
# az webapp create --resource-group ${{ env.AZURE_RESOURCE_GROUP }} --plan ${{ env.AZURE_APP_PLAN }} --name ${{ env.AZURE_WEBAPP_NAME }} -i nginx | |
- name: Azure Container Registry Login | |
uses: Azure/docker-login@v1 | |
with: | |
# Container registry username | |
username: ${{ secrets.ACR_USERNAME }} | |
# Container registry password | |
password: ${{ secrets.ACR_PASSWORD }} | |
# Container registry server url | |
login-server: ${{env.CONTAINER_REGISTRY}} | |
- name: Set Web App ACR authentication | |
uses: Azure/appservice-settings@v1 | |
with: | |
app-name: ${{ env.AZURE_WEBAPP_NAME }} | |
app-settings-json: | | |
[ | |
{ | |
"name": "DOCKER_REGISTRY_SERVER_PASSWORD", | |
"value": "${{ secrets.ACR_PASSWORD }}", | |
"slotSetting": false | |
}, | |
{ | |
"name": "DOCKER_REGISTRY_SERVER_URL", | |
"value": "https://${{env.CONTAINER_REGISTRY}}", | |
"slotSetting": false | |
}, | |
{ | |
"name": "DOCKER_REGISTRY_SERVER_USERNAME", | |
"value": "${{ secrets.ACR_USERNAME }}", | |
"slotSetting": false | |
} | |
] | |
- name: 'Deploy to Azure Web App for Container' | |
uses: azure/webapps-deploy@v2 | |
with: | |
app-name: ${{ env.AZURE_WEBAPP_NAME }} | |
images: ${{ env.CONTAINER_REGISTRY }}/${{env.image_name}}:${{ github.sha }} |
Author
ahmedig
commented
Oct 22, 2020
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment