Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Add new deployment action for staging.openverse.org (#2086)
Zack Kridab43e959e9505
diff --git a/.github/actions/staging-deploy/action.yml b/.github/actions/staging-deploy/action.ymlnew file mode 100644index 000000000..e9ceaf79b--- /dev/null+++ b/.github/actions/staging-deploy/action.yml@@ -0,0 +1,157 @@+### !!!+# This file is automatically generated using Terraform.+# Do not update it manually. If changes need to be made,+# please request help from a maintainer to generate the+# updated version.+### !!!++name: openverse/staging-nuxt-nuxt-deploy+description: Update the task definition for a staging-nuxt-nuxt deployment++inputs:+ tag:+ required: true+ description: Image tag to deploy.+ aws-access-key-id:+ required: true+ aws-secret-access-key:+ required: true+ slack-webhook:+ required: true+ gh-slack-username-map:+ required: true++runs:+ using: "composite"++ steps:+ - name: Set the Slack user+ shell: python+ env:+ GH_SLACK_USERNAME_MAP: ${{ inputs.gh-slack-username-map }}+ run: |+ import json+ import os+ mapping = json.loads('${{ env.GH_SLACK_USERNAME_MAP }}')+ github_user = "${{ github.triggering_actor }}"+ slack_id = mapping[github_user]+ with open(os.getenv('GITHUB_ENV'), "a") as env_file:+ env_file.write(f"SLACK_USER_ID={slack_id}")++ - name: Notify deployment start+ uses: slackapi/[email protected]+ if: success() || failure()+ with:+ payload: |+ {+ "text": "Starting deployment of staging-nuxt",+ "blocks": [+ {+ "type": "section",+ "text": {+ "type": "mrkdwn",+ "text": ":spinning-cd: A deployment of staging-nuxt triggered by <@${{ env.SLACK_USER_ID }}> is starting using the `${{ inputs.tag }}` tag."+ }+ },+ {+ "type": "section",+ "text": {+ "type": "mrkdwn",+ "text": "<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|Click here to monitor the deployment>."+ }+ }+ ]+ }+ env:+ SLACK_WEBHOOK_URL: ${{ inputs.slack-webhook }}+ SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK++ - name: Configure AWS credentials+ uses: aws-actions/configure-aws-credentials@v1+ if: success() || failure()+ with:+ aws-access-key-id: ${{ inputs.aws-access-key-id }}+ aws-secret-access-key: ${{ inputs.aws-secret-access-key }}+ aws-region: us-east-1++ - name: Download task definition template and update family name+ shell: bash+ run: |+ aws ecs describe-task-definition \+ --task-definition staging-nuxt-template \+ --query taskDefinition > task-definition.json++ # Remove template from the family name (the render action does not support this)+ sed -i 's/"family": "staging-nuxt-template"/"family": "staging-nuxt"/g' task-definition.json++ - name: Fill in the new image ID in the Amazon ECS task definition+ id: task-def+ uses: aws-actions/amazon-ecs-render-task-definition@v1+ with:+ task-definition: task-definition.json+ container-name: nuxt+ image: ghcr.io/wordpress/openverse-frontend:${{ inputs.tag }}++ - name: Deploy Amazon ECS task definition+ uses: aws-actions/amazon-ecs-deploy-task-definition@v1+ with:+ task-definition: ${{ steps.task-def.outputs.task-definition }}+ service: staging-nuxt+ cluster: staging-default+ wait-for-service-stability: true+ wait-for-minutes: 10++ - name: Notify deployment finished+ uses: slackapi/[email protected]+ with:+ payload: |+ {+ "text": "Deployment of staging-nuxt successful",+ "blocks": [+ {+ "type": "section",+ "text": {+ "type": "mrkdwn",+ "text": ":tadaco: The deployment of staging-nuxt triggered by <@${{ env.SLACK_USER_ID }}> using the `${{ inputs.tag }}` tag *succeeded*."+ }+ },+ {+ "type": "section",+ "text": {+ "type": "mrkdwn",+ "text": "<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|Click here to review the completed deployment workflow>."+ }+ }+ ]+ }+ env:+ SLACK_WEBHOOK_URL: ${{ inputs.slack-webhook }}+ SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK++ - name: Notify deployment failure+ if: failure()+ uses: slackapi/[email protected]+ with:+ payload: |+ {+ "text": "Deployment of staging-nuxt failed!",+ "blocks": [+ {+ "type": "section",+ "text": {+ "type": "mrkdwn",+ "text": ":alert: The deployment of staging-nuxt triggered by <@${{ env.SLACK_USER_ID }}> using the `${{ inputs.tag }}` tag *failed* :alert:"+ }+ },+ {+ "type": "section",+ "text": {+ "type": "mrkdwn",+ "text": "<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|Click here to review the failed deployment workflow>."+ }+ }+ ]+ }+ env:+ SLACK_WEBHOOK_URL: ${{ inputs.slack-webhook }}+ SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOKdiff --git a/.github/workflows/ghcr.yml b/.github/workflows/ghcr.ymlindex 68ea26ace..dc080466f 100644--- a/.github/workflows/ghcr.yml+++ b/.github/workflows/ghcr.yml@@ -84,6 +84,24 @@ jobs:build-args: |RELEASE=${{ steps.get-version.outputs.version }}+ # TODO: Remove once this install redirects to the new one.+ deploy-old-staging:+ name: Deploy old staging frontend+ runs-on: ubuntu-latest+ if: github.event_name == 'push'+ needs: push-to-ghcr++ steps:+ - uses: actions/checkout@v3++ - uses: ./.github/actions/staging-frontend-deploy+ with:+ tag: ${{ needs.push-to-ghcr.outputs.pushed-version }}+ aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}+ aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}+ slack-webhook: ${{ secrets.SLACK_WEBHOOK_URL }}+ gh-slack-username-map: ${{ secrets.GH_SLACK_USERNAME_MAP }}+deploy-staging:name: Deploy staging frontendruns-on: ubuntu-latest@@ -93,7 +111,7 @@ jobs:steps:- uses: actions/checkout@v3- - uses: ./.github/actions/staging-frontend-deploy+ - uses: ./.github/actions/staging-deploywith:tag: ${{ needs.push-to-ghcr.outputs.pushed-version }}aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}diff --git a/.github/workflows/rollback.yml b/.github/workflows/rollback.ymlindex 42b545d74..8e744c1e5 100644--- a/.github/workflows/rollback.yml+++ b/.github/workflows/rollback.yml@@ -83,6 +83,7 @@ jobs:slack-webhook: ${{ secrets.SLACK_WEBHOOK_URL }}gh-slack-username-map: ${{ secrets.GH_SLACK_USERNAME_MAP }}+ # TODO: Remove once this install redirects to the new one.- uses: ./.github/actions/staging-frontend-deployif: inputs.environment == 'staging'with:@@ -91,3 +92,12 @@ jobs:aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}slack-webhook: ${{ secrets.SLACK_WEBHOOK_URL }}gh-slack-username-map: ${{ secrets.GH_SLACK_USERNAME_MAP }}++ - uses: ./.github/actions/staging-deploy+ if: inputs.environment == 'staging'+ with:+ tag: ${{ inputs.tag }}+ aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}+ aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}+ slack-webhook: ${{ secrets.SLACK_WEBHOOK_URL }}+ gh-slack-username-map: ${{ secrets.GH_SLACK_USERNAME_MAP }}