Skip to content

Commit

Permalink
adjusted node.js deploy script blue/green (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
adriandevopsstuff committed Jun 9, 2021
1 parent e1805f9 commit 04f193a
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 1 deletion.
84 changes: 84 additions & 0 deletions .github/workflows/node-CD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ on:
defaults:
run:
working-directory: apis/userprofile

env:
webappName: openhackkkg4t772userprofile
resourceGroup: openhackkkg4t772rg
subscriptionId: 03a6d591-1096-4413-9cf4-ae9bb9a8f348
healthCheckUrl: https://openhackkkg4t772userprofile-staging.azurewebsites.net/api/healthcheck/userprofile
dockerImageName: api-userprofile

jobs:
build-and-deploy:
runs-on: ubuntu-latest
Expand All @@ -26,10 +34,21 @@ jobs:
- name: Output Run Number
run: echo ${{ github.run_number }}

- name: create .env
run: |
touch .env
VERSION=${{ github.run_number }} > .env
- name: Docker build and push
run: |
docker build . -t openhackkkg4t772acr.azurecr.io/devopsoh/api-userprofile:${{ github.run_number }}
docker push openhackkkg4t772acr.azurecr.io/devopsoh/api-userprofile:${{ github.run_number }}
- name: Ensure slot is started
uses: azure/CLI@v1
with:
inlineScript: |
az webapp start --slot staging --name ${{ env.webappName }} --resource-group ${{ env.resourceGroup }} --subscription ${{ env.subscriptionId }}
- name: Deploy on staging
uses: azure/webapps-deploy@v2
Expand All @@ -39,6 +58,58 @@ jobs:
publish-profile: ${{ secrets.API_USERPROFILE_STAGING_DEPLOYMENT_PROFILE }} #TODO: add userprofile
images: 'openhackkkg4t772acr.azurecr.io/devopsoh/api-userprofile:${{ github.run_number }}'

- name: Restart the slot
uses: azure/CLI@v1
with:
inlineScript: |
az webapp restart --slot staging --name ${{ env.webappName }} --resource-group ${{ env.resourceGroup }} --subscription ${{ env.subscriptionId }}
- name: Check the image tag
uses: azure/CLI@v1
with:
inlineScript: |
for i in $(seq 1 10)
do
dockerVersion=$(az webapp show --slot staging --name ${{ env.webappName }} --resource-group ${{ env.resourceGroup }} --subscription ${{ env.subscriptionId }} --query "siteConfig.linuxFxVersion" --output tsv)
dockerVersion=$(echo $dockerVersion | cut -d ':' -f2)
echo "DockerVersion $dockerVersion"
if [[ "$dockerVersion" = "${{ github.run_number }}" ]]; then
exit 0
fi
echo "Attempt #$i failed"
sleep 10
done
echo "Found a wrong version ($dockerVersion)."
# It failed a lot of time
exit 1
- name: Check deployment
if: success()
id: 'checkDeployment'
continue-on-error: true
run: |
url=${{ env.healthCheckUrl }}
for i in $(seq 1 10)
do
result=$(curl -i $url 2>/dev/null | grep HTTP/2)
status=${result:7:3}
if [[ "$status" = "200" ]]; then
echo "200"
exit 0
fi
sleep 10
done
# It failed a lot of time
exit 1
# Execute the create-an-issue task if the previous task fails
- name: Create Issue
if: failure()
Expand All @@ -48,3 +119,16 @@ jobs:
with:
title: ${{ env.GITHUB_WORKFLOW }}
filename: .github/ISSUE_TEMPLATE_HACK.md

- name: Swap slot
uses: azure/CLI@v1
if: success()
with:
inlineScript: |
az webapp deployment slot swap --slot staging --target-slot production --name ${{ env.webappName }} --resource-group ${{ env.resourceGroup }} --subscription ${{ env.subscriptionId }}
- name: Stop slot
uses: azure/CLI@v1
with:
inlineScript: |
az webapp stop --slot staging --name ${{ env.webappName }} --resource-group ${{ env.resourceGroup }} --subscription ${{ env.subscriptionId }}
2 changes: 1 addition & 1 deletion apis/userprofile/data/healthcheck/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = {
res.json({
message: 'healthcheck',
status: 'healthy',
additional: true,
version: process.env.VERSION || 1,
});
callback;
},
Expand Down

0 comments on commit 04f193a

Please sign in to comment.