--- name: Deploy Web - Non-Prod run-name: Deploy Web ${{ inputs.environment }} on: workflow_dispatch: inputs: environment: description: 'Environment' default: 'QA' type: choice options: - QA - EUQA workflow_call: inputs: environment: description: 'Environment' default: 'QA' type: string jobs: setup: name: Setup runs-on: ubuntu-20.04 outputs: environment: ${{ steps.config.outputs.environment }} environment-url: ${{ steps.config.outputs.environment-url }} environment-name: ${{ steps.config.outputs.environment-name }} environment-branch: ${{ steps.config.outputs.environment-branch }} environment-artifact: ${{ steps.config.outputs.environment-artifact }} azure-login-creds: ${{ steps.config.outputs.azure-login-creds }} retrieve-secrets-keyvault: ${{ steps.config.outputs.retrieve-secrets-keyvault }} steps: - name: Configure id: config run: | ENV_NAME_LOWER=$(echo "${{ inputs.environment }}" | awk '{print tolower($0)}') echo "configuring the Web deploy for ${{ inputs.environment }}" echo "environment=${{ inputs.environment }}" >> $GITHUB_OUTPUT echo "environment-url=http://vault.$ENV_NAME_LOWER.bitwarden.pw" >> $GITHUB_OUTPUT echo "environment-name=Web Vault - ${{ inputs.environment }}" >> $GITHUB_OUTPUT echo "environment-branch=cf-pages-$ENV_NAME_LOWER" >> $GITHUB_OUTPUT if [ ${{ inputs.environment }} == "QA" ]; then echo "azure-login-creds=AZURE_KV_US_QA_SERVICE_PRINCIPAL" >> $GITHUB_OUTPUT echo "retrieve-secrets-keyvault=bw-webvault-rlktusqa-kv" >> $GITHUB_OUTPUT echo "environment-artifact=web-*-cloud-QA.zip" >> $GITHUB_OUTPUT elif [ ${{ inputs.environment }} == "EUQA" ]; then echo "azure-login-creds=AZURE_KV_EU_QA_SERVICE_PRINCIPAL" >> $GITHUB_OUTPUT echo "retrieve-secrets-keyvault=webvaulteu-westeurope-qa" >> $GITHUB_OUTPUT echo "environment-artifact=web-*-cloud-euqa.zip" >> $GITHUB_OUTPUT fi artifact-check: name: Check if Web artifact is present runs-on: ubuntu-22.04 needs: setup env: _ENVIRONMENT_ARTIFACT: ${{ needs.setup.outputs.environment-artifact }} steps: - name: Download latest cloud asset uses: bitwarden/gh-actions/download-artifacts@main id: download-artifacts continue-on-error: true with: workflow: build-web.yml path: apps/web workflow_conclusion: success branch: ${{ github.ref_name }} artifacts: ${{ env._ENVIRONMENT_ARTIFACT }} - name: Login to Azure if: ${{ steps.download-artifacts.outcome == 'failure' }} uses: Azure/login@92a5484dfaf04ca78a94597f4f19fea633851fa2 # v1.4.7 with: creds: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }} - name: Retrieve secrets for Build trigger if: ${{ steps.download-artifacts.outcome == 'failure' }} id: retrieve-secret uses: bitwarden/gh-actions/get-keyvault-secrets@main with: keyvault: "bitwarden-ci" secrets: "github-pat-bitwarden-devops-bot-repo-scope" - name: Build server missing branch if: ${{ steps.download-artifacts.outcome == 'failure' }} uses: convictional/trigger-workflow-and-wait@f69fa9eedd3c62a599220f4d5745230e237904be # v1.6.5 with: owner: bitwarden repo: clients github_token: ${{ steps.retrieve-secret.outputs.github-pat-bitwarden-devops-bot-repo-scope }} workflow_file_name: build-web.yml ref: ${{ github.ref_name }} wait_interval: 100 azure-deploy: name: Deploy Web Vault to ${{ inputs.environment }} Storage Account needs: - setup - artifact-check runs-on: ubuntu-22.04 env: _ENVIRONMENT_ARTIFACT: ${{ needs.setup.outputs.environment-artifact }} steps: - name: Login to Azure uses: Azure/login@92a5484dfaf04ca78a94597f4f19fea633851fa2 # v1.4.7 with: creds: ${{ secrets[needs.setup.outputs.azure-login-creds] }} - name: Retrieve Storage Account connection string id: retrieve-secrets uses: bitwarden/gh-actions/get-keyvault-secrets@main with: keyvault: ${{ needs.setup.outputs.retrieve-secrets-keyvault }} secrets: "sa-bitwarden-web-vault-dev-key-temp" - name: Download latest cloud asset uses: bitwarden/gh-actions/download-artifacts@main with: workflow: build-web.yml path: apps/web workflow_conclusion: success branch: ${{ github.event.inputs.tag }} artifacts: ${{ env._ENVIRONMENT_ARTIFACT }} - name: Unzip build asset working-directory: apps/web run: unzip ${{ env._ENVIRONMENT_ARTIFACT }} - name: Empty container in Storage Account run: | az storage blob delete-batch \ --source '$web' \ --pattern '*' \ --connection-string "${{ steps.retrieve-secrets.outputs.sa-bitwarden-web-vault-dev-key-temp }}" - name: Deploy to Azure Storage Account working-directory: apps/web run: | az storage blob upload-batch \ --source "./build" \ --destination '$web' \ --connection-string "${{ steps.retrieve-secrets.outputs.sa-bitwarden-web-vault-dev-key-temp }}" \ --overwrite \ --no-progress notify: name: Notify Slack with result runs-on: ubuntu-22.04 if: always() needs: - cfpages-deploy - setup steps: - uses: bitwarden/gh-actions/report-deployment-status-to-slack@main with: project: Web environment: US ${{ inputs.environment }} Cloud tag: ${{ github.ref_name }} slack-channel: team-eng-qa-devops failure: ${{ needs.cfpages-deploy.result == 'failure' }} AZURE_KV_CI_SERVICE_PRINCIPAL: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }}