generated from Azure-Samples/openhack-devops-team
-
Notifications
You must be signed in to change notification settings - Fork 4
72 lines (67 loc) · 2.46 KB
/
trips-cd.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# This workflow will build and push a Docker container to an Azure Web App when a commit is pushed to your default branch.
#
name: Build and deploy a trips container to an Azure Web App
env:
AZURE_WEBAPP_NAME: openhackyvs74zq0trips
BASEIMAGETAG: ${{github.sha}}
ACRNAME: openhackyvs74zq0acr.azurecr.io
GITOHTEAMDIRPATH: .
RESOURCE_GROUP: openhackyvs74zq0rg
on:
push:
branches:
- $default-branch
paths:
- 'apis/trips/**'
- '.github/workflows/trips-cd.yml'
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Build and push container to ACR
run: |
echo "Building API-TRIPS image..."
echo "Changing directory to $GITOHTEAMDIRPATH/apis/trips..."
cd "$GITOHTEAMDIRPATH/apis/trips"
az acr build --image "devopsoh/api-trips:${BASEIMAGETAG}" --registry $ACRNAME --file Dockerfile .
#<Azure Container Registry URI>/<ACR_repository_name>:<Revision Number> where the ACR_repository_name follows the naming convention devopsoh/<image_name>:<tag>.
#openhackyvs74zq0acr.azurecr.io/devopsoh/api-poi:
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Development'
steps:
- uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: 'Debug'
run: |
echo "Deploying ${{ env.ACRNAME }}/devopsoh/api-trips:${{ env.BASEIMAGETAG }}"
- name: 'Deploy to Azure Web App for Container'
id: deploy-staging
uses: azure/webapps-deploy@v2
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
images: ${{ env.ACRNAME }}/devopsoh/api-trips:${{ env.BASEIMAGETAG }}
slot-name: 'staging'
# check
- uses: actions/checkout@v2
- name: 'Check staging deployment is successful'
run: |
echo "Running polling.sh from $GITOHTEAMDIRPATH/resources/polling.sh"
cd "$GITOHTEAMDIRPATH/resources"
# make file runnable
chmod +x "./polling.sh"
./polling.sh "${{ steps.deploy-staging.outputs.webapp-url }}/api/healthcheck/trips" 90
shell: bash
# if successful swap stage to prod
- name: 'Swap web app deployment slots for blue/green'
id: swap-to-prod
run: |
az webapp deployment slot swap -g ${{env.RESOURCE_GROUP}} -n ${{ env.AZURE_WEBAPP_NAME }} --slot staging --target-slot production