2021-05-04 22:41:49 +02:00
|
|
|
name: QA Deploy
|
|
|
|
|
|
|
|
on:
|
|
|
|
workflow_dispatch:
|
|
|
|
inputs:
|
|
|
|
migrateDb:
|
|
|
|
required: true
|
|
|
|
default: "true"
|
|
|
|
resetDb:
|
|
|
|
required: true
|
|
|
|
default: "false"
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
build:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
strategy:
|
|
|
|
fail-fast: false
|
|
|
|
matrix:
|
|
|
|
include:
|
|
|
|
- name: Api
|
|
|
|
base_path: .
|
|
|
|
- name: Admin
|
|
|
|
base_path: .
|
|
|
|
gulp: true
|
|
|
|
- name: Billing
|
|
|
|
base_path: .
|
|
|
|
- name: Events
|
|
|
|
base_path: .
|
|
|
|
- name: Notifications
|
|
|
|
base_path: .
|
|
|
|
- name: Sso
|
|
|
|
base_path: ./bitwarden_license
|
|
|
|
gulp: true
|
|
|
|
- name: Portal
|
|
|
|
base_path: ./bitwarden_license
|
|
|
|
gulp: true
|
|
|
|
- name: Identity
|
|
|
|
base_path: .
|
|
|
|
steps:
|
|
|
|
- name: Checkout repo
|
2021-05-17 21:15:01 +02:00
|
|
|
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f
|
2021-05-04 22:41:49 +02:00
|
|
|
|
|
|
|
- name: Set up Node
|
2021-05-17 21:15:01 +02:00
|
|
|
uses: actions/setup-node@46071b5c7a2e0c34e49c3cb8a0e792e86e18d5ea
|
2021-05-04 22:41:49 +02:00
|
|
|
with:
|
2021-05-17 21:15:01 +02:00
|
|
|
node-version: '14'
|
2021-05-04 22:41:49 +02:00
|
|
|
|
|
|
|
- name: Print Environment
|
|
|
|
run: |
|
|
|
|
dotnet --info
|
|
|
|
node --version
|
|
|
|
npm --version
|
|
|
|
gulp --version
|
|
|
|
|
|
|
|
- name: load env vars
|
|
|
|
run: |
|
|
|
|
echo "Base Path: ${BASE_PATH}"
|
|
|
|
echo "Name: ${NAME}"
|
|
|
|
env:
|
|
|
|
BASE_PATH: ${{ matrix.base_path }}
|
|
|
|
NAME: ${{ matrix.name }}
|
|
|
|
|
|
|
|
- name: Build Service
|
|
|
|
run: |
|
|
|
|
work_dir=$(pwd)
|
|
|
|
dir=$BASE_PATH/src/$SERVICE_NAME
|
|
|
|
|
|
|
|
cd $dir
|
|
|
|
echo "Restore"
|
|
|
|
dotnet restore $SERVICE_NAME.csproj
|
|
|
|
echo "Clean"
|
2021-05-27 18:16:12 +02:00
|
|
|
dotnet clean $SERVICE_NAME.csproj -c "Release" -o obj/build-output/publish
|
2021-05-04 22:41:49 +02:00
|
|
|
|
|
|
|
if [ "$GULP" == "true" ]; then
|
|
|
|
npm install
|
|
|
|
npm install gulp
|
|
|
|
gulp --gulpfile gulpfile.js build
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Publish"
|
2021-05-27 18:16:12 +02:00
|
|
|
dotnet publish $SERVICE_NAME.csproj -c "Release" -o obj/build-output/publish
|
2021-05-04 22:41:49 +02:00
|
|
|
|
2021-05-27 18:16:12 +02:00
|
|
|
cd obj/build-output/publish
|
2021-05-04 22:41:49 +02:00
|
|
|
zip -r $SERVICE_NAME.zip .
|
|
|
|
mv $SERVICE_NAME.zip ../../../
|
|
|
|
env:
|
|
|
|
SERVICE_NAME: ${{ matrix.name }}
|
|
|
|
BASE_PATH: ${{ matrix.base_path }}
|
|
|
|
GULP: ${{ matrix.gulp }}
|
|
|
|
|
|
|
|
- name: Upload build artifact
|
2021-05-17 21:15:01 +02:00
|
|
|
uses: actions/upload-artifact@ee69f02b3dfdecd58bb31b4d133da38ba6fe3700
|
2021-05-04 22:41:49 +02:00
|
|
|
with:
|
|
|
|
name: ${{ env.SERVICE_NAME }}.zip
|
|
|
|
path: ${{ env.BASE_PATH }}/src/${{ env.SERVICE_NAME }}/${{ env.SERVICE_NAME }}.zip
|
|
|
|
env:
|
|
|
|
BASE_PATH: ${{ matrix.base_path }}
|
|
|
|
SERVICE_NAME: ${{ matrix.name }}
|
|
|
|
|
|
|
|
- name: Test build dir
|
|
|
|
run: ls $BASE_PATH/src/$SERVICE_NAME
|
|
|
|
env:
|
|
|
|
SERVICE_NAME: ${{ matrix.name }}
|
|
|
|
BASE_PATH: ${{ matrix.base_path }}
|
|
|
|
|
|
|
|
|
|
|
|
reset-db:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
needs: build
|
|
|
|
steps:
|
|
|
|
- name: Reset Test Data - Stub
|
|
|
|
if: ${{ github.events.inputs.resetDb }} == "true"
|
|
|
|
run: |
|
|
|
|
echo "placeholder for cleaning DB"
|
|
|
|
echo "placeholder for loading test dataset"
|
|
|
|
|
2021-06-10 22:14:15 +02:00
|
|
|
|
2021-05-04 22:41:49 +02:00
|
|
|
update-db:
|
|
|
|
if: ${{ github.events.inputs.migrateDb }} == "true"
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
needs: build
|
|
|
|
steps:
|
|
|
|
- name: migrate db
|
|
|
|
if: ${{ github.events.inputs.resetDb }} == "true"
|
|
|
|
run: |
|
|
|
|
echo "placeholder for updateing DB"
|
|
|
|
|
|
|
|
|
2021-06-10 22:14:15 +02:00
|
|
|
deploy:
|
2021-05-04 22:41:49 +02:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
needs:
|
|
|
|
- reset-db
|
|
|
|
- update-db
|
2021-06-10 22:14:15 +02:00
|
|
|
strategy:
|
|
|
|
fail-fast: false
|
|
|
|
matrix:
|
|
|
|
include:
|
|
|
|
- name: Api
|
|
|
|
- name: Admin
|
|
|
|
- name: Billing
|
|
|
|
- name: Events
|
|
|
|
- name: Sso
|
|
|
|
- name: Portal
|
|
|
|
- name: Identity
|
2021-05-04 22:41:49 +02:00
|
|
|
steps:
|
2021-06-10 22:14:15 +02:00
|
|
|
- name: Setup
|
|
|
|
id: setup
|
|
|
|
run: |
|
|
|
|
NAME_LOWER=$(echo "${{ matrix.name }}" | awk '{print tolower($0)}')
|
|
|
|
echo "Matrix name: ${{ matrix.name }}"
|
|
|
|
echo "NAME_LOWER: $NAME_LOWER"
|
|
|
|
echo "::set-output name=name_lower::$NAME_LOWER"
|
|
|
|
|
2021-05-04 22:41:49 +02:00
|
|
|
- name: Download aritifacts
|
2021-06-10 22:14:15 +02:00
|
|
|
uses: actions/download-artifact@158ca71f7c614ae705e79f25522ef4658df18253
|
2021-05-04 22:41:49 +02:00
|
|
|
with:
|
2021-06-10 22:14:15 +02:00
|
|
|
name: ${{ matrix.name }}.zip
|
2021-05-04 22:41:49 +02:00
|
|
|
|
|
|
|
- name: Login to Azure
|
|
|
|
uses: Azure/login@77f1b2e3fb80c0e8645114159d17008b8a2e475a
|
|
|
|
with:
|
|
|
|
creds: ${{ secrets.AZURE_QA_KV_CREDENTIALS }}
|
|
|
|
|
|
|
|
- name: Retrieve secrets
|
|
|
|
id: retrieve-secrets
|
2021-06-10 22:14:15 +02:00
|
|
|
env:
|
|
|
|
VAULT_NAME: "bitwarden-qa-kv"
|
|
|
|
run: |
|
|
|
|
webapp_name=$(az keyvault secret show --vault-name $VAULT_NAME --name appservices-${{ steps.setup.outputs.name_lower }}-webapp-name --query value --output tsv)
|
|
|
|
echo "::add-mask::$webapp_name"
|
|
|
|
echo "::set-output name=webapp-name::$webapp_name"
|
2021-05-04 22:41:49 +02:00
|
|
|
|
2021-06-10 22:14:15 +02:00
|
|
|
- name: Deploy App
|
2021-05-17 21:15:01 +02:00
|
|
|
uses: azure/webapps-deploy@798e43877120eda6a2a690a4f212c545e586ae31
|
2021-05-04 22:41:49 +02:00
|
|
|
with:
|
2021-06-10 22:14:15 +02:00
|
|
|
app-name: ${{ steps.retrieve-secrets.outputs.webapp-name }}
|
2021-05-04 22:41:49 +02:00
|
|
|
slot-name: "staging"
|
2021-06-10 22:14:15 +02:00
|
|
|
package: ./${{ matrix.name }}.zip
|
2021-05-04 22:41:49 +02:00
|
|
|
|
|
|
|
|
2021-06-10 22:14:15 +02:00
|
|
|
swap-identity:
|
2021-05-04 22:41:49 +02:00
|
|
|
runs-on: ubuntu-latest
|
2021-06-10 22:14:15 +02:00
|
|
|
needs: deploy
|
2021-05-04 22:41:49 +02:00
|
|
|
steps:
|
|
|
|
- name: Login to Azure
|
|
|
|
uses: Azure/login@77f1b2e3fb80c0e8645114159d17008b8a2e475a
|
|
|
|
with:
|
|
|
|
creds: ${{ secrets.AZURE_QA_KV_CREDENTIALS }}
|
|
|
|
|
|
|
|
- name: Retrieve secrets
|
|
|
|
id: retrieve-secrets
|
2021-06-10 22:14:15 +02:00
|
|
|
env:
|
|
|
|
VAULT_NAME: "bitwarden-qa-kv"
|
|
|
|
run: |
|
|
|
|
identity_webapp_name=$(az keyvault secret show --vault-name $VAULT_NAME --name appservices-identity-webapp-name --query value --output tsv)
|
|
|
|
echo "::add-mask::$identity_webapp_name"
|
|
|
|
echo "::set-output name=identity-webapp-name::$identity_webapp_name"
|
2021-05-04 22:41:49 +02:00
|
|
|
|
2021-06-10 22:14:15 +02:00
|
|
|
- name: Start staging slot
|
|
|
|
run: az webapp start --name ${{ steps.retrieve-secrets.outputs.identity-webapp-name }} --resource-group bitwarden-qa --slot staging
|
2021-05-04 22:41:49 +02:00
|
|
|
|
2021-06-10 22:14:15 +02:00
|
|
|
- name: Make sure staging endpoint is alive
|
|
|
|
run: |
|
|
|
|
SUCCESS="no"
|
|
|
|
while read OUTPUT
|
|
|
|
do
|
|
|
|
STATUS=$( curl -is https://${{ steps.retrieve-secrets.outputs.identity-webapp-name }}-staging.azurewebsites.net/.well-known/openid-configuration/jwks | head -1 )
|
|
|
|
if [[ "$STATUS" == *"200 OK"* ]]; then
|
|
|
|
echo "It is live!"
|
|
|
|
SUCCESS="yes"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
echo -e "STAUS=$STATUS\nRetrying: $OUTPUT"
|
|
|
|
sleep 4;
|
|
|
|
done < <(seq 15)
|
|
|
|
|
|
|
|
if [[ "$SUCCESS" == "no" ]]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-05-04 22:41:49 +02:00
|
|
|
|
2021-06-10 22:14:15 +02:00
|
|
|
- name: Swap Identity
|
|
|
|
run: az webapp deployment slot swap -g bitwarden-qa -n ${{ steps.retrieve-secrets.outputs.identity-webapp-name }} --slot staging --target-slot production
|
2021-05-04 22:41:49 +02:00
|
|
|
|
2021-06-10 22:14:15 +02:00
|
|
|
- name: Stop staging slot
|
|
|
|
run: az webapp stop --name ${{ steps.retrieve-secrets.outputs.identity-webapp-name }} --resource-group bitwarden-qa --slot staging
|
2021-05-04 22:41:49 +02:00
|
|
|
|
|
|
|
|
2021-06-10 22:14:15 +02:00
|
|
|
swap-slots:
|
2021-05-04 22:41:49 +02:00
|
|
|
runs-on: ubuntu-latest
|
2021-06-10 22:14:15 +02:00
|
|
|
needs: swap-identity
|
|
|
|
strategy:
|
|
|
|
fail-fast: false
|
|
|
|
matrix:
|
|
|
|
include:
|
|
|
|
- name: Api
|
|
|
|
- name: Billing
|
|
|
|
- name: Events
|
|
|
|
- name: Sso
|
|
|
|
- name: Portal
|
2021-05-04 22:41:49 +02:00
|
|
|
steps:
|
2021-06-10 22:14:15 +02:00
|
|
|
- name: Setup
|
|
|
|
id: setup
|
|
|
|
run: |
|
|
|
|
NAME_LOWER=$(echo "${{ matrix.name }}" | awk '{print tolower($0)}')
|
|
|
|
echo "::set-output name=name_lower::$NAME_LOWER"
|
2021-05-04 22:41:49 +02:00
|
|
|
|
|
|
|
- name: Login to Azure
|
|
|
|
uses: Azure/login@77f1b2e3fb80c0e8645114159d17008b8a2e475a
|
|
|
|
with:
|
|
|
|
creds: ${{ secrets.AZURE_QA_KV_CREDENTIALS }}
|
|
|
|
|
|
|
|
- name: Retrieve secrets
|
|
|
|
id: retrieve-secrets
|
2021-06-10 22:14:15 +02:00
|
|
|
env:
|
|
|
|
VAULT_NAME: "bitwarden-qa-kv"
|
|
|
|
run: |
|
|
|
|
webapp_name=$(az keyvault secret show --vault-name $VAULT_NAME --name appservices-${{ steps.setup.outputs.name_lower }}-webapp-name --query value --output tsv)
|
|
|
|
echo "::add-mask::$webapp_name"
|
|
|
|
echo "::set-output name=webapp-name::$webapp_name"
|
2021-05-04 22:41:49 +02:00
|
|
|
|
2021-06-10 22:14:15 +02:00
|
|
|
- name: Start staging slot
|
|
|
|
run: az webapp start --name ${{ steps.retrieve-secrets.outputs.webapp-name }} --resource-group bitwarden-qa --slot staging
|
2021-05-04 22:41:49 +02:00
|
|
|
|
2021-06-10 22:14:15 +02:00
|
|
|
- name: Make sure staging endpoint is alive
|
|
|
|
run: |
|
|
|
|
SUCCESS="no"
|
|
|
|
while read OUTPUT
|
|
|
|
do
|
|
|
|
STATUS=$( curl -is https://${{ steps.retrieve-secrets.outputs.webapp-name }}-staging.azurewebsites.net/alive | head -1 )
|
|
|
|
if [[ "$STATUS" == *"200 OK"* ]]; then
|
|
|
|
echo "It is live!"
|
|
|
|
SUCCESS="yes"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
echo -e "STAUS=$STATUS\nRetrying: $OUTPUT"
|
|
|
|
sleep 4;
|
|
|
|
done < <(seq 15)
|
|
|
|
|
|
|
|
if [[ "$SUCCESS" == "no" ]]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-05-04 22:41:49 +02:00
|
|
|
|
2021-06-10 22:14:15 +02:00
|
|
|
- name: Swap slots
|
|
|
|
run: az webapp deployment slot swap -g bitwarden-qa -n ${{ steps.retrieve-secrets.outputs.webapp-name }} --slot staging --target-slot production
|
2021-05-04 22:41:49 +02:00
|
|
|
|
2021-06-10 22:14:15 +02:00
|
|
|
- name: Stop staging slot
|
|
|
|
run: az webapp stop --name ${{ steps.retrieve-secrets.outputs.webapp-name }} --resource-group bitwarden-qa --slot staging
|
2021-05-04 22:41:49 +02:00
|
|
|
|
|
|
|
|
2021-06-10 22:14:15 +02:00
|
|
|
swap-admin:
|
2021-05-04 22:41:49 +02:00
|
|
|
runs-on: ubuntu-latest
|
2021-06-10 22:14:15 +02:00
|
|
|
needs: swap-slots
|
2021-05-04 22:41:49 +02:00
|
|
|
steps:
|
|
|
|
- name: Login to Azure
|
|
|
|
uses: Azure/login@77f1b2e3fb80c0e8645114159d17008b8a2e475a
|
|
|
|
with:
|
|
|
|
creds: ${{ secrets.AZURE_QA_KV_CREDENTIALS }}
|
|
|
|
|
|
|
|
- name: Retrieve secrets
|
|
|
|
id: retrieve-secrets
|
2021-06-10 22:14:15 +02:00
|
|
|
env:
|
|
|
|
VAULT_NAME: "bitwarden-qa-kv"
|
|
|
|
run: |
|
|
|
|
admin_webapp_name=$(az keyvault secret show --vault-name $VAULT_NAME --name appservices-admin-webapp-name --query value --output tsv)
|
|
|
|
echo "::add-mask::$admin_webapp_name"
|
|
|
|
echo "::set-output name=admin-webapp-name::$admin_webapp_name"
|
2021-05-04 22:41:49 +02:00
|
|
|
|
2021-06-10 22:14:15 +02:00
|
|
|
- name: Start staging slot
|
|
|
|
run: az webapp start --name ${{ steps.retrieve-secrets.outputs.admin-webapp-name }} --resource-group bitwarden-qa --slot staging
|
2021-05-04 22:41:49 +02:00
|
|
|
|
2021-06-10 22:14:15 +02:00
|
|
|
- name: Make sure staging endpoint is alive
|
|
|
|
run: |
|
|
|
|
sleep 60 # I don't think the admin portal has an alive endpoint
|
2021-05-04 22:41:49 +02:00
|
|
|
|
2021-06-10 22:14:15 +02:00
|
|
|
- name: Swap Admin
|
|
|
|
run: az webapp deployment slot swap -g bitwarden-qa -n ${{ steps.retrieve-secrets.outputs.admin-webapp-name }} --slot staging --target-slot production
|
2021-05-04 22:41:49 +02:00
|
|
|
|
2021-06-10 22:14:15 +02:00
|
|
|
- name: Stop staging slot
|
|
|
|
run: az webapp stop --name ${{ steps.retrieve-secrets.outputs.admin-webapp-name }} --resource-group bitwarden-qa --slot staging
|