Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Add thumbnails staging deployment (#814)
sarayourfriend199f72a947de
diff --git a/.github/actions/staging-thumbnails-deploy/action.yml b/.github/actions/staging-thumbnails-deploy/action.ymlnew file mode 100644index 000000000..88e21cc6f--- /dev/null+++ b/.github/actions/staging-thumbnails-deploy/action.yml@@ -0,0 +1,136 @@+### !!!+# 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-thumbnails-imaginary-deploy+description: Update the task definition for a staging-thumbnails-imaginary 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++runs:+ using: "composite"++ steps:+ - name: Notify deployment start+ uses: slackapi/[email protected]+ with:+ payload: |+ {+ "text": "Starting deployment of staging-thumbnails",+ "blocks": [+ {+ "type": "section",+ "text": {+ "type": "mrkdwn",+ "text": ":spinning-cd: A deployment of staging-thumbnails 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+ 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+ shell: bash+ run: |+ aws ecs describe-task-definition \+ --task-definition staging-thumbnails-template \+ --query taskDefinition > 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: imaginary+ image: ghcr.io/wordpress/openverse-imaginary:${{ 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-thumbnails+ cluster: staging-default+ wait-for-service-stability: true++ - name: Notify deployment finished+ uses: slackapi/[email protected]+ with:+ payload: |+ {+ "text": "Deployment of staging-thumbnails successful",+ "blocks": [+ {+ "type": "section",+ "text": {+ "type": "mrkdwn",+ "text": ":tadaco: The deployment of staging-thumbnails 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-thumbnails failed!",+ "blocks": [+ {+ "type": "section",+ "text": {+ "type": "mrkdwn",+ "text": ":alert: The deployment of staging-thumbnails 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/build_imaginary.yml b/.github/workflows/build_imaginary.ymlindex 28b7bf39c..83debe6ef 100644--- a/.github/workflows/build_imaginary.yml+++ b/.github/workflows/build_imaginary.yml@@ -1,10 +1,21 @@name: Build imaginaryon:workflow_dispatch:+ inputs:+ deploy-to:+ type: string+ default: null+ description: The environment to deploy to, if a deploy is desired. Currently only `staging` is available.++ deploy-only:+ type: boolean+ default: false+ description: Set to `true` to trigger _just_ a redeploymentjobs:build:name: Build+ if: github.event.inputs.deploy-only == falseruns-on: ubuntu-lateststeps:- name: Checkout h2non/imaginary repository@@ -55,3 +66,39 @@ jobs:push: truetags: |ghcr.io/wordpress/openverse-imaginary:latest++ deploy:+ name: Deploy Imaginary+ runs-on: ubuntu-latest+ if: github.event.inputs.deploy-to != null+ needs: [build]++ steps:+ - uses: actions/github-script@v6+ with:+ github-token: ${{ secrets.ACCESS_TOKEN }}+ script: |+ const { data: members } = await github.rest.teams.listMembersInOrg({+ org: 'WordPress',+ team_slug: 'openverse-maintainers',+ });++ const isAllowed = members.some(m => m.login === "${{ github.actor }}")++ if (!isAllowed) {+ throw new Error(+ "Only GitHub users in the @WordPress/openverse-maintainers "+ + "team are allowed to run this workflow. If you need to run "+ + "this workflow, please reach out to that group for help."+ )+ }++ - uses: actions/checkout@v3++ - uses: ./.github/actions/staging-thumbnails-deploy+ if: github.event.inputs.deploy-to == 'staging'+ with:+ tag: latest+ aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}+ aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}+ slack-webhook: ${{ secrets.SLACK_WEBHOOK_URL }}