Skip to content

Commit

Permalink
fix(deployment): staging deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhi Markan committed Jun 2, 2023
1 parent 0734cb7 commit f3894d0
Showing 1 changed file with 83 additions and 3 deletions.
86 changes: 83 additions & 3 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ env:
FROM: latest

jobs:
# 1. Setup deployment variables

setup:
name: Setup πŸ”§
runs-on: [self-hosted, EXIP, deployment]
Expand All @@ -57,7 +57,7 @@ jobs:
- name: Timezone 🌐
run: echo "Timezone set to ${{ env.TIMEZONE }}"

# 2. DB - Initialisation

database:
name: Database πŸ“¦οΈ
needs: setup
Expand Down Expand Up @@ -86,7 +86,6 @@ jobs:
#TODO: EMS-1176: MS SQL DB setup

# 3. API - Deployment
api:
name: API πŸ“¦οΈ
needs: setup
Expand Down Expand Up @@ -169,3 +168,84 @@ jobs:
inlineScript: |
az webapp restart \
--name ${{ env.WEBAPP }}
ui:
name: UI πŸ“¦οΈ
needs: setup
environment: ${{ needs.setup.outputs.environment }}
env:
NAME: ui
ENVIRONMENT: ${{ needs.setup.outputs.environment }}
runs-on: [self-hosted, EXIP, deployment]
steps:
- name: Repository πŸ—ƒοΈ
uses: actions/checkout@v3

- name: Azure πŸ”
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}

- name: Defaults ✨
uses: Azure/cli@v1.0.7
with:
inlineScript: |
# Basic
az configure --defaults location=${{ vars.REGION }}
az configure --defaults group=rg-${{ env.PRODUCT }}-staging-${{ vars.VERSION }}
- name: CLI πŸ“
run: |
echo ACR=$(az acr show -n $(az resource list --resource-type 'Microsoft.ContainerRegistry/registries' --query '[0].name' -o tsv) --query loginServer -o tsv) >> $GITHUB_ENV
echo ACR_USER=$(az acr show -n $(az resource list --resource-type 'Microsoft.ContainerRegistry/registries' --query '[0].name' -o tsv) --query name -o tsv) >> $GITHUB_ENV
echo WEBAPP=$(az resource list --resource-type 'Microsoft.Web/sites' --query '[?contains(name, `${{ env.NAME }}`)].name' -o tsv) >> $GITHUB_ENV
- name: ACR πŸ”
uses: azure/docker-login@v1
with:
login-server: ${{ env.ACR }}
username: ${{ env.ACR_USER }}
password: ${{ secrets.ACR_PASSWORD }}

- name: Artifacts πŸ—ƒοΈ
working-directory: src/${{ env.NAME }}
run: |
# Build images
docker build . \
-t ${{ env.ACR }}/${{ env.NAME }}:${{ github.sha }} \
-t ${{ env.ACR }}/${{ env.NAME }}:${{ env.FROM }} \
--build-arg GITHUB_SHA=${{ github.sha }}
# Push images
docker push ${{ env.ACR }}/${{ env.NAME }}:${{ github.sha }}
docker push ${{ env.ACR }}/${{ env.NAME }}:${{ env.FROM }}
- name: Slot πŸ”€
uses: azure/cli@v1.0.7
with:
inlineScript: |
# Create new temporary slot
az webapp deployment slot create \
--slot ${{ github.sha }} \
--name ${{ env.WEBAPP }} \
--configuration-source ${{ env.WEBAPP }}
# Swap slot
az webapp deployment slot swap \
--slot ${{ github.sha }} \
--name ${{ env.WEBAPP }} \
--action swap
# Delete temporary slot
az webapp deployment slot delete \
--slot ${{ github.sha }} \
--name ${{ env.WEBAPP }}
- name: Reboot ♻️
uses: azure/cli@v1.0.7
with:
inlineScript: |
az webapp restart \
--name ${{ env.WEBAPP }}

0 comments on commit f3894d0

Please sign in to comment.