Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Split deployment workflow into 4 separate workflows (#886)
Madison Swain-Bowden6d601a30ebf3
diff --git a/.github/actions/production-api-deploy/action.yml b/.github/actions/production-api-deploy/action.ymldeleted file mode 100644index 3bf32c4a7..000000000--- a/.github/actions/production-api-deploy/action.yml+++ /dev/null@@ -1,221 +0,0 @@-### !!!-# 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/production-api-deploy-description: Update the task definition for a production-api 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 production-api",- "blocks": [- {- "type": "section",- "text": {- "type": "mrkdwn",- "text": ":spinning-cd: A deployment of production-api 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: Validate `tag` input for Nginx- uses: actions/github-script@v6- with:- script: |- let exists = undefined,- page = 0- while (!exists) {- page += 1- const { data: versions } =- await github.rest.packages.getAllPackageVersionsForPackageOwnedByOrg({- package_type: 'container',- package_name: 'openverse-api_nginx',- org: 'WordPress',- page,- // max of `per_page`- per_page: 100,- })- if (!versions.length) {- break- }- exists = versions.some((v) => v.metadata.container.tags.includes('${{ inputs.tag }}'))- }- if (!exists) {- throw new Error(- `'${{ inputs.tag }}' does not appear to be a valid tag for the ghcr.io/wordpress/openverse-api_nginx image.`- )- }-- - name: Validate `tag` input for Django- uses: actions/github-script@v6- with:- script: |- let exists = undefined,- page = 0- while (!exists) {- page += 1- const { data: versions } =- await github.rest.packages.getAllPackageVersionsForPackageOwnedByOrg({- package_type: 'container',- package_name: 'openverse-api',- org: 'WordPress',- page,- // max of `per_page`- per_page: 100,- })- if (!versions.length) {- break- }- exists = versions.some((v) => v.metadata.container.tags.includes('${{ inputs.tag }}'))- }- if (!exists) {- throw new Error(- `'${{ inputs.tag }}' does not appear to be a valid tag for the ghcr.io/wordpress/openverse-api image.`- )- }-- - 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 production-api-template \- --query taskDefinition > task-definition.json-- # Remove template from the family name (the render action does not support this)- sed -i 's/"family": "production-api-template"/"family": "production-api"/g' task-definition.json-- - name: "Fill in the new nginx image ID in the Amazon ECS task definition"- id: "task-def-nginx"- uses: "aws-actions/amazon-ecs-render-task-definition@v1"- with:- task-definition: task-definition.json- container-name: nginx- image: "ghcr.io/wordpress/openverse-api_nginx:${{ inputs.tag }}"-- - name: "Fill in the new django image ID in the Amazon ECS task definition"- id: "task-def-django"- uses: "aws-actions/amazon-ecs-render-task-definition@v1"- with:- task-definition: ${{ steps.task-def-nginx.outputs.task-definition }}- container-name: django- image: "ghcr.io/wordpress/openverse-api:${{ inputs.tag }}"-- - name: Deploy Amazon ECS task definition- uses: aws-actions/amazon-ecs-deploy-task-definition@v1- with:- task-definition: ${{ steps.task-def-django.outputs.task-definition }}- service: production-api- cluster: production-default- wait-for-service-stability: true- wait-for-minutes: 10-- - name: Notify deployment finished- uses: slackapi/[email protected]- with:- payload: |- {- "text": "Deployment of production-api successful",- "blocks": [- {- "type": "section",- "text": {- "type": "mrkdwn",- "text": ":tadaco: The deployment of production-api 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 production-api failed!",- "blocks": [- {- "type": "section",- "text": {- "type": "mrkdwn",- "text": ":alert: The deployment of production-api 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/actions/production-nuxt-deploy/action.yml b/.github/actions/production-nuxt-deploy/action.ymldeleted file mode 100644index 1e21fe090..000000000--- a/.github/actions/production-nuxt-deploy/action.yml+++ /dev/null@@ -1,185 +0,0 @@-### !!!-# 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/production-nuxt-deploy-description: Update the task definition for a production-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 production-nuxt",- "blocks": [- {- "type": "section",- "text": {- "type": "mrkdwn",- "text": ":spinning-cd: A deployment of production-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: Validate `tag` input for Nuxt- uses: actions/github-script@v6- with:- script: |- let exists = undefined,- page = 0- while (!exists) {- page += 1- const { data: versions } =- await github.rest.packages.getAllPackageVersionsForPackageOwnedByOrg({- package_type: 'container',- package_name: 'openverse-frontend',- org: 'WordPress',- page,- // max of `per_page`- per_page: 100,- })- if (!versions.length) {- break- }- exists = versions.some((v) => v.metadata.container.tags.includes('${{ inputs.tag }}'))- }- if (!exists) {- throw new Error(- `'${{ inputs.tag }}' does not appear to be a valid tag for the ghcr.io/wordpress/openverse-frontend image.`- )- }-- - 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 production-nuxt-template \- --query taskDefinition > task-definition.json-- # Remove template from the family name (the render action does not support this)- sed -i 's/"family": "production-nuxt-template"/"family": "production-nuxt"/g' task-definition.json-- - name: "Fill in the new nuxt image ID in the Amazon ECS task definition"- id: "task-def-nuxt"- 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-nuxt.outputs.task-definition }}- service: production-nuxt- cluster: production-default- wait-for-service-stability: true- wait-for-minutes: 10-- - name: Notify deployment finished- uses: slackapi/[email protected]- with:- payload: |- {- "text": "Deployment of production-nuxt successful",- "blocks": [- {- "type": "section",- "text": {- "type": "mrkdwn",- "text": ":tadaco: The deployment of production-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 production-nuxt failed!",- "blocks": [- {- "type": "section",- "text": {- "type": "mrkdwn",- "text": ":alert: The deployment of production-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/actions/staging-api-deploy/action.yml b/.github/actions/staging-api-deploy/action.ymldeleted file mode 100644index 944325e30..000000000--- a/.github/actions/staging-api-deploy/action.yml+++ /dev/null@@ -1,221 +0,0 @@-### !!!-# 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-api-deploy-description: Update the task definition for a staging-api 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-api",- "blocks": [- {- "type": "section",- "text": {- "type": "mrkdwn",- "text": ":spinning-cd: A deployment of staging-api 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: Validate `tag` input for Nginx- uses: actions/github-script@v6- with:- script: |- let exists = undefined,- page = 0- while (!exists) {- page += 1- const { data: versions } =- await github.rest.packages.getAllPackageVersionsForPackageOwnedByOrg({- package_type: 'container',- package_name: 'openverse-api_nginx',- org: 'WordPress',- page,- // max of `per_page`- per_page: 100,- })- if (!versions.length) {- break- }- exists = versions.some((v) => v.metadata.container.tags.includes('${{ inputs.tag }}'))- }- if (!exists) {- throw new Error(- `'${{ inputs.tag }}' does not appear to be a valid tag for the ghcr.io/wordpress/openverse-api_nginx image.`- )- }-- - name: Validate `tag` input for Django- uses: actions/github-script@v6- with:- script: |- let exists = undefined,- page = 0- while (!exists) {- page += 1- const { data: versions } =- await github.rest.packages.getAllPackageVersionsForPackageOwnedByOrg({- package_type: 'container',- package_name: 'openverse-api',- org: 'WordPress',- page,- // max of `per_page`- per_page: 100,- })- if (!versions.length) {- break- }- exists = versions.some((v) => v.metadata.container.tags.includes('${{ inputs.tag }}'))- }- if (!exists) {- throw new Error(- `'${{ inputs.tag }}' does not appear to be a valid tag for the ghcr.io/wordpress/openverse-api image.`- )- }-- - 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-api-template \- --query taskDefinition > task-definition.json-- # Remove template from the family name (the render action does not support this)- sed -i 's/"family": "staging-api-template"/"family": "staging-api"/g' task-definition.json-- - name: "Fill in the new nginx image ID in the Amazon ECS task definition"- id: "task-def-nginx"- uses: "aws-actions/amazon-ecs-render-task-definition@v1"- with:- task-definition: task-definition.json- container-name: nginx- image: "ghcr.io/wordpress/openverse-api_nginx:${{ inputs.tag }}"-- - name: "Fill in the new django image ID in the Amazon ECS task definition"- id: "task-def-django"- uses: "aws-actions/amazon-ecs-render-task-definition@v1"- with:- task-definition: ${{ steps.task-def-nginx.outputs.task-definition }}- container-name: django- image: "ghcr.io/wordpress/openverse-api:${{ inputs.tag }}"-- - name: Deploy Amazon ECS task definition- uses: aws-actions/amazon-ecs-deploy-task-definition@v1- with:- task-definition: ${{ steps.task-def-django.outputs.task-definition }}- service: staging-api- 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-api successful",- "blocks": [- {- "type": "section",- "text": {- "type": "mrkdwn",- "text": ":tadaco: The deployment of staging-api 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-api failed!",- "blocks": [- {- "type": "section",- "text": {- "type": "mrkdwn",- "text": ":alert: The deployment of staging-api 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/actions/staging-nuxt-deploy/action.yml b/.github/actions/staging-nuxt-deploy/action.ymldeleted file mode 100644index b5546225f..000000000--- a/.github/actions/staging-nuxt-deploy/action.yml+++ /dev/null@@ -1,185 +0,0 @@-### !!!-# 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-deploy-description: Update the task definition for a staging-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: Validate `tag` input for Nuxt- uses: actions/github-script@v6- with:- script: |- let exists = undefined,- page = 0- while (!exists) {- page += 1- const { data: versions } =- await github.rest.packages.getAllPackageVersionsForPackageOwnedByOrg({- package_type: 'container',- package_name: 'openverse-frontend',- org: 'WordPress',- page,- // max of `per_page`- per_page: 100,- })- if (!versions.length) {- break- }- exists = versions.some((v) => v.metadata.container.tags.includes('${{ inputs.tag }}'))- }- if (!exists) {- throw new Error(- `'${{ inputs.tag }}' does not appear to be a valid tag for the ghcr.io/wordpress/openverse-frontend image.`- )- }-- - 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 nuxt image ID in the Amazon ECS task definition"- id: "task-def-nuxt"- 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-nuxt.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/api-rollback.yml b/.github/workflows/api-rollback.ymldeleted file mode 100644index 464310910..000000000--- a/.github/workflows/api-rollback.yml+++ /dev/null@@ -1,122 +0,0 @@-### !!!-# 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/api-rollback--on:- workflow_dispatch:- inputs:- environment:- required: true- description: The environment to roll back. `staging` or `production`.- tag:- required: true- description: The GHCR image tag to which the environment should be rolled back--# Only allow a single rollback to happen at a time-# If you need to stop an in-progress rollback to force-# another for the same environment, you'll need to manually cancel it-concurrency: ${{ github.workflow }}-${{ inputs.environment }}--jobs:- rollback:- name: Perform Rollback- runs-on: ubuntu-latest-- 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-- - name: Validate `tag` input for nginx- uses: actions/github-script@v6- with:- script: |- let exists = undefined,- page = 0- while (!exists) {- page += 1- const { data: versions } =- await github.rest.packages.getAllPackageVersionsForPackageOwnedByOrg({- package_type: 'container',- package_name: 'openverse-api_nginx',- org: 'WordPress',- page,- // max of `per_page`- per_page: 100,- })- if (!versions.length) {- break- }- exists = versions.some((v) => v.metadata.container.tags.includes('${{ inputs.tag }}'))- }- if (!exists) {- throw new Error(- '`${{ inputs.tag }}` does not appear to be a valid tag for the ghcr.io/wordpress/openverse-api_nginx image.'- )- }-- - name: Validate `tag` input for django- uses: actions/github-script@v6- with:- script: |- let exists = undefined,- page = 0- while (!exists) {- page += 1- const { data: versions } =- await github.rest.packages.getAllPackageVersionsForPackageOwnedByOrg({- package_type: 'container',- package_name: 'openverse-api',- org: 'WordPress',- page,- // max of `per_page`- per_page: 100,- })- if (!versions.length) {- break- }- exists = versions.some((v) => v.metadata.container.tags.includes('${{ inputs.tag }}'))- }- if (!exists) {- throw new Error(- '`${{ inputs.tag }}` does not appear to be a valid tag for the ghcr.io/wordpress/openverse-api image.'- )- }-- - uses: ./.github/actions/production-api-deploy- if: inputs.environment == 'production'- 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 }}-- - uses: ./.github/actions/staging-api-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 }}diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.ymlindex 22bf673af..b7de15dce 100644--- a/.github/workflows/ci_cd.yml+++ b/.github/workflows/ci_cd.yml@@ -921,7 +921,6 @@ jobs:deploy-frontend:name: Deploy staging frontend- runs-on: ubuntu-latestif: |!failure() && !cancelled() &&github.event_name == 'push' && needs.get-changes.outputs.frontend == 'true' &&@@ -934,23 +933,13 @@ jobs:- nuxt-playwright-vr- storybook-playwright- publish-images-- steps:- - name: Checkout repository- uses: actions/checkout@v3-- - name: Deploy to staging- uses: ./.github/actions/staging-nuxt-deploy- with:- tag: ${{ needs.get-image-tag.outputs.image-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 }}+ uses: ./.github/workflows/deploy-staging-nuxt.yml+ with:+ tag: ${{ needs.get-image-tag.outputs.image-tag }}+ secrets: inheritdeploy-api:name: Deploy staging API- runs-on: ubuntu-latestif: |!failure() && !cancelled() &&github.event_name == 'push' && needs.get-changes.outputs.api == 'true' &&@@ -960,16 +949,7 @@ jobs:- get-changes- test-api- publish-images-- steps:- - name: Checkout repository- uses: actions/checkout@v3-- - name: Deploy to staging- uses: ./.github/actions/staging-api-deploy- with:- tag: ${{ needs.get-image-tag.outputs.image-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 }}+ uses: ./.github/workflows/deploy-staging-api.yml+ with:+ tag: ${{ needs.get-image-tag.outputs.image-tag }}+ secrets: inheritdiff --git a/.github/workflows/deploy-production-api.yml b/.github/workflows/deploy-production-api.ymlnew file mode 100644index 000000000..6b4f22ae8--- /dev/null+++ b/.github/workflows/deploy-production-api.yml@@ -0,0 +1,233 @@+### !!!+# 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: "Deployment: production-api"++on:+ workflow_call:+ inputs:+ tag:+ type: string+ required: true+ description: Image tag to deploy.+ secrets:+ AWS_ACCESS_KEY_ID:+ required: true+ description: AWS access key ID.+ AWS_SECRET_ACCESS_KEY:+ required: true+ description: AWS secret access key.+ SLACK_WEBHOOK_URL:+ required: true+ description: Slack webhook URL.+ GH_SLACK_USERNAME_MAP:+ required: true+ description: JSON mapping of GitHub usernames to Slack user IDs.++jobs:+ deploy:+ name: Deploy production-api+ runs-on: ubuntu-latest++ steps:+ - name: Checkout repository+ uses: actions/checkout@v3++ - name: Set the Slack user+ shell: python+ env:+ GH_SLACK_USERNAME_MAP: ${{ secrets.GH_SLACK_USERNAME_MAP }}+ run: |+ import json+ import os+ mapping = json.loads('${{ env.GH_SLACK_USERNAME_MAP }}')+ github_user = "${{ github.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 production-api",+ "blocks": [+ {+ "type": "section",+ "text": {+ "type": "mrkdwn",+ "text": ":spinning-cd: A deployment of production-api 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: ${{ secrets.SLACK_WEBHOOK_URL }}+ SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK++ - name: Validate `tag` input for Nginx+ uses: actions/github-script@v6+ with:+ script: |+ let exists = undefined,+ page = 0+ while (!exists) {+ page += 1+ const { data: versions } =+ await github.rest.packages.getAllPackageVersionsForPackageOwnedByOrg({+ package_type: 'container',+ package_name: 'openverse-api_nginx',+ org: 'WordPress',+ page,+ // max of `per_page`+ per_page: 100,+ })+ if (!versions.length) {+ break+ }+ exists = versions.some((v) => v.metadata.container.tags.includes('${{ inputs.tag }}'))+ }+ if (!exists) {+ throw new Error(+ `'${{ inputs.tag }}' does not appear to be a valid tag for the ghcr.io/wordpress/openverse-api_nginx image.`+ )+ }++ - name: Validate `tag` input for Django+ uses: actions/github-script@v6+ with:+ script: |+ let exists = undefined,+ page = 0+ while (!exists) {+ page += 1+ const { data: versions } =+ await github.rest.packages.getAllPackageVersionsForPackageOwnedByOrg({+ package_type: 'container',+ package_name: 'openverse-api',+ org: 'WordPress',+ page,+ // max of `per_page`+ per_page: 100,+ })+ if (!versions.length) {+ break+ }+ exists = versions.some((v) => v.metadata.container.tags.includes('${{ inputs.tag }}'))+ }+ if (!exists) {+ throw new Error(+ `'${{ inputs.tag }}' does not appear to be a valid tag for the ghcr.io/wordpress/openverse-api image.`+ )+ }++ - name: Configure AWS credentials+ uses: aws-actions/configure-aws-credentials@v1+ if: success() || failure()+ with:+ aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}+ aws-secret-access-key: ${{ secrets.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 production-api-template \+ --query taskDefinition > task-definition.json++ # Remove template from the family name (the render action does not support this)+ sed -i 's/"family": "production-api-template"/"family": "production-api"/g' task-definition.json++ - name: "Fill in the new nginx image ID in the Amazon ECS task definition"+ id: "task-def-nginx"+ uses: "aws-actions/amazon-ecs-render-task-definition@v1"+ with:+ task-definition: task-definition.json+ container-name: nginx+ image: "ghcr.io/wordpress/openverse-api_nginx:${{ inputs.tag }}"++ - name: "Fill in the new django image ID in the Amazon ECS task definition"+ id: "task-def-django"+ uses: "aws-actions/amazon-ecs-render-task-definition@v1"+ with:+ task-definition: ${{ steps.task-def-nginx.outputs.task-definition }}+ container-name: django+ image: "ghcr.io/wordpress/openverse-api:${{ inputs.tag }}"++ - name: Deploy Amazon ECS task definition+ uses: aws-actions/amazon-ecs-deploy-task-definition@v1+ with:+ task-definition: ${{ steps.task-def-django.outputs.task-definition }}+ service: production-api+ cluster: production-default+ wait-for-service-stability: true+ wait-for-minutes: 10++ - name: Notify deployment finished+ uses: slackapi/[email protected]+ with:+ payload: |+ {+ "text": "Deployment of production-api successful",+ "blocks": [+ {+ "type": "section",+ "text": {+ "type": "mrkdwn",+ "text": ":tadaco: The deployment of production-api 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: ${{ secrets.SLACK_WEBHOOK_URL }}+ SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK++ - name: Notify deployment failure+ if: failure()+ uses: slackapi/[email protected]+ with:+ payload: |+ {+ "text": "Deployment of production-api failed!",+ "blocks": [+ {+ "type": "section",+ "text": {+ "type": "mrkdwn",+ "text": ":alert: The deployment of production-api 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: ${{ secrets.SLACK_WEBHOOK_URL }}+ SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOKdiff --git a/.github/workflows/deploy-production-nuxt.yml b/.github/workflows/deploy-production-nuxt.ymlnew file mode 100644index 000000000..2a169acda--- /dev/null+++ b/.github/workflows/deploy-production-nuxt.yml@@ -0,0 +1,197 @@+### !!!+# 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: "Deployment: production-nuxt"++on:+ workflow_call:+ inputs:+ tag:+ type: string+ required: true+ description: Image tag to deploy.+ secrets:+ AWS_ACCESS_KEY_ID:+ required: true+ description: AWS access key ID.+ AWS_SECRET_ACCESS_KEY:+ required: true+ description: AWS secret access key.+ SLACK_WEBHOOK_URL:+ required: true+ description: Slack webhook URL.+ GH_SLACK_USERNAME_MAP:+ required: true+ description: JSON mapping of GitHub usernames to Slack user IDs.++jobs:+ deploy:+ name: Deploy production-nuxt+ runs-on: ubuntu-latest++ steps:+ - name: Checkout repository+ uses: actions/checkout@v3++ - name: Set the Slack user+ shell: python+ env:+ GH_SLACK_USERNAME_MAP: ${{ secrets.GH_SLACK_USERNAME_MAP }}+ run: |+ import json+ import os+ mapping = json.loads('${{ env.GH_SLACK_USERNAME_MAP }}')+ github_user = "${{ github.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 production-nuxt",+ "blocks": [+ {+ "type": "section",+ "text": {+ "type": "mrkdwn",+ "text": ":spinning-cd: A deployment of production-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: ${{ secrets.SLACK_WEBHOOK_URL }}+ SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK++ - name: Validate `tag` input for Nuxt+ uses: actions/github-script@v6+ with:+ script: |+ let exists = undefined,+ page = 0+ while (!exists) {+ page += 1+ const { data: versions } =+ await github.rest.packages.getAllPackageVersionsForPackageOwnedByOrg({+ package_type: 'container',+ package_name: 'openverse-frontend',+ org: 'WordPress',+ page,+ // max of `per_page`+ per_page: 100,+ })+ if (!versions.length) {+ break+ }+ exists = versions.some((v) => v.metadata.container.tags.includes('${{ inputs.tag }}'))+ }+ if (!exists) {+ throw new Error(+ `'${{ inputs.tag }}' does not appear to be a valid tag for the ghcr.io/wordpress/openverse-frontend image.`+ )+ }++ - name: Configure AWS credentials+ uses: aws-actions/configure-aws-credentials@v1+ if: success() || failure()+ with:+ aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}+ aws-secret-access-key: ${{ secrets.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 production-nuxt-template \+ --query taskDefinition > task-definition.json++ # Remove template from the family name (the render action does not support this)+ sed -i 's/"family": "production-nuxt-template"/"family": "production-nuxt"/g' task-definition.json++ - name: "Fill in the new nuxt image ID in the Amazon ECS task definition"+ id: "task-def-nuxt"+ 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-nuxt.outputs.task-definition }}+ service: production-nuxt+ cluster: production-default+ wait-for-service-stability: true+ wait-for-minutes: 10++ - name: Notify deployment finished+ uses: slackapi/[email protected]+ with:+ payload: |+ {+ "text": "Deployment of production-nuxt successful",+ "blocks": [+ {+ "type": "section",+ "text": {+ "type": "mrkdwn",+ "text": ":tadaco: The deployment of production-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: ${{ secrets.SLACK_WEBHOOK_URL }}+ SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK++ - name: Notify deployment failure+ if: failure()+ uses: slackapi/[email protected]+ with:+ payload: |+ {+ "text": "Deployment of production-nuxt failed!",+ "blocks": [+ {+ "type": "section",+ "text": {+ "type": "mrkdwn",+ "text": ":alert: The deployment of production-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: ${{ secrets.SLACK_WEBHOOK_URL }}+ SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOKdiff --git a/.github/workflows/deploy-staging-api.yml b/.github/workflows/deploy-staging-api.ymlnew file mode 100644index 000000000..5774693df--- /dev/null+++ b/.github/workflows/deploy-staging-api.yml@@ -0,0 +1,233 @@+### !!!+# 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: "Deployment: staging-api"++on:+ workflow_call:+ inputs:+ tag:+ type: string+ required: true+ description: Image tag to deploy.+ secrets:+ AWS_ACCESS_KEY_ID:+ required: true+ description: AWS access key ID.+ AWS_SECRET_ACCESS_KEY:+ required: true+ description: AWS secret access key.+ SLACK_WEBHOOK_URL:+ required: true+ description: Slack webhook URL.+ GH_SLACK_USERNAME_MAP:+ required: true+ description: JSON mapping of GitHub usernames to Slack user IDs.++jobs:+ deploy:+ name: Deploy staging-api+ runs-on: ubuntu-latest++ steps:+ - name: Checkout repository+ uses: actions/checkout@v3++ - name: Set the Slack user+ shell: python+ env:+ GH_SLACK_USERNAME_MAP: ${{ secrets.GH_SLACK_USERNAME_MAP }}+ run: |+ import json+ import os+ mapping = json.loads('${{ env.GH_SLACK_USERNAME_MAP }}')+ github_user = "${{ github.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-api",+ "blocks": [+ {+ "type": "section",+ "text": {+ "type": "mrkdwn",+ "text": ":spinning-cd: A deployment of staging-api 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: ${{ secrets.SLACK_WEBHOOK_URL }}+ SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK++ - name: Validate `tag` input for Nginx+ uses: actions/github-script@v6+ with:+ script: |+ let exists = undefined,+ page = 0+ while (!exists) {+ page += 1+ const { data: versions } =+ await github.rest.packages.getAllPackageVersionsForPackageOwnedByOrg({+ package_type: 'container',+ package_name: 'openverse-api_nginx',+ org: 'WordPress',+ page,+ // max of `per_page`+ per_page: 100,+ })+ if (!versions.length) {+ break+ }+ exists = versions.some((v) => v.metadata.container.tags.includes('${{ inputs.tag }}'))+ }+ if (!exists) {+ throw new Error(+ `'${{ inputs.tag }}' does not appear to be a valid tag for the ghcr.io/wordpress/openverse-api_nginx image.`+ )+ }++ - name: Validate `tag` input for Django+ uses: actions/github-script@v6+ with:+ script: |+ let exists = undefined,+ page = 0+ while (!exists) {+ page += 1+ const { data: versions } =+ await github.rest.packages.getAllPackageVersionsForPackageOwnedByOrg({+ package_type: 'container',+ package_name: 'openverse-api',+ org: 'WordPress',+ page,+ // max of `per_page`+ per_page: 100,+ })+ if (!versions.length) {+ break+ }+ exists = versions.some((v) => v.metadata.container.tags.includes('${{ inputs.tag }}'))+ }+ if (!exists) {+ throw new Error(+ `'${{ inputs.tag }}' does not appear to be a valid tag for the ghcr.io/wordpress/openverse-api image.`+ )+ }++ - name: Configure AWS credentials+ uses: aws-actions/configure-aws-credentials@v1+ if: success() || failure()+ with:+ aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}+ aws-secret-access-key: ${{ secrets.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-api-template \+ --query taskDefinition > task-definition.json++ # Remove template from the family name (the render action does not support this)+ sed -i 's/"family": "staging-api-template"/"family": "staging-api"/g' task-definition.json++ - name: "Fill in the new nginx image ID in the Amazon ECS task definition"+ id: "task-def-nginx"+ uses: "aws-actions/amazon-ecs-render-task-definition@v1"+ with:+ task-definition: task-definition.json+ container-name: nginx+ image: "ghcr.io/wordpress/openverse-api_nginx:${{ inputs.tag }}"++ - name: "Fill in the new django image ID in the Amazon ECS task definition"+ id: "task-def-django"+ uses: "aws-actions/amazon-ecs-render-task-definition@v1"+ with:+ task-definition: ${{ steps.task-def-nginx.outputs.task-definition }}+ container-name: django+ image: "ghcr.io/wordpress/openverse-api:${{ inputs.tag }}"++ - name: Deploy Amazon ECS task definition+ uses: aws-actions/amazon-ecs-deploy-task-definition@v1+ with:+ task-definition: ${{ steps.task-def-django.outputs.task-definition }}+ service: staging-api+ 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-api successful",+ "blocks": [+ {+ "type": "section",+ "text": {+ "type": "mrkdwn",+ "text": ":tadaco: The deployment of staging-api 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: ${{ secrets.SLACK_WEBHOOK_URL }}+ SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK++ - name: Notify deployment failure+ if: failure()+ uses: slackapi/[email protected]+ with:+ payload: |+ {+ "text": "Deployment of staging-api failed!",+ "blocks": [+ {+ "type": "section",+ "text": {+ "type": "mrkdwn",+ "text": ":alert: The deployment of staging-api 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: ${{ secrets.SLACK_WEBHOOK_URL }}+ SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOKdiff --git a/.github/workflows/deploy-staging-nuxt.yml b/.github/workflows/deploy-staging-nuxt.ymlnew file mode 100644index 000000000..626970c54--- /dev/null+++ b/.github/workflows/deploy-staging-nuxt.yml@@ -0,0 +1,197 @@+### !!!+# 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: "Deployment: staging-nuxt"++on:+ workflow_call:+ inputs:+ tag:+ type: string+ required: true+ description: Image tag to deploy.+ secrets:+ AWS_ACCESS_KEY_ID:+ required: true+ description: AWS access key ID.+ AWS_SECRET_ACCESS_KEY:+ required: true+ description: AWS secret access key.+ SLACK_WEBHOOK_URL:+ required: true+ description: Slack webhook URL.+ GH_SLACK_USERNAME_MAP:+ required: true+ description: JSON mapping of GitHub usernames to Slack user IDs.++jobs:+ deploy:+ name: Deploy staging-nuxt+ runs-on: ubuntu-latest++ steps:+ - name: Checkout repository+ uses: actions/checkout@v3++ - name: Set the Slack user+ shell: python+ env:+ GH_SLACK_USERNAME_MAP: ${{ secrets.GH_SLACK_USERNAME_MAP }}+ run: |+ import json+ import os+ mapping = json.loads('${{ env.GH_SLACK_USERNAME_MAP }}')+ github_user = "${{ github.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: ${{ secrets.SLACK_WEBHOOK_URL }}+ SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK++ - name: Validate `tag` input for Nuxt+ uses: actions/github-script@v6+ with:+ script: |+ let exists = undefined,+ page = 0+ while (!exists) {+ page += 1+ const { data: versions } =+ await github.rest.packages.getAllPackageVersionsForPackageOwnedByOrg({+ package_type: 'container',+ package_name: 'openverse-frontend',+ org: 'WordPress',+ page,+ // max of `per_page`+ per_page: 100,+ })+ if (!versions.length) {+ break+ }+ exists = versions.some((v) => v.metadata.container.tags.includes('${{ inputs.tag }}'))+ }+ if (!exists) {+ throw new Error(+ `'${{ inputs.tag }}' does not appear to be a valid tag for the ghcr.io/wordpress/openverse-frontend image.`+ )+ }++ - name: Configure AWS credentials+ uses: aws-actions/configure-aws-credentials@v1+ if: success() || failure()+ with:+ aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}+ aws-secret-access-key: ${{ secrets.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 nuxt image ID in the Amazon ECS task definition"+ id: "task-def-nuxt"+ 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-nuxt.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: ${{ secrets.SLACK_WEBHOOK_URL }}+ 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: ${{ secrets.SLACK_WEBHOOK_URL }}+ SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOKdiff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.ymldeleted file mode 100644index c8e1b1ff4..000000000--- a/.github/workflows/deployment.yml+++ /dev/null@@ -1,94 +0,0 @@-name: Deployment--on:- workflow_dispatch:- inputs:- environment:- required: true- description: The environment to deploy to.- type: choice- default: staging- options:- - staging- - production- service:- required: true- description: The service to deploy.- type: choice- options:- - nuxt- - api- tag:- required: true- description: The GHCR image tag to which the environment should be deployed.--# Only allow a single deploy to happen at a time-# If you need to stop an in-progress deployment to force # another for the same-# environment, you'll need to manually cancel it-concurrency: ${{ github.workflow }}-${{ github.event.inputs.environment }}--jobs:- deploy:- name: Perform Deploy- runs-on: ubuntu-latest-- 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-- # Cannot dynamically set "uses" due to security implications:- # https://github.com/orgs/community/discussions/25446-- - uses: ./.github/actions/staging-nuxt-deploy- if: ${{ github.event.inputs.environment == 'staging' && github.event.inputs.service == 'nuxt' }}- with:- tag: ${{ github.event.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 }}-- - uses: ./.github/actions/production-nuxt-deploy- if: ${{ github.event.inputs.environment == 'production' && github.event.inputs.service == 'nuxt' }}- with:- tag: ${{ github.event.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 }}-- - uses: ./.github/actions/staging-api-deploy- if: ${{ github.event.inputs.environment == 'staging' && github.event.inputs.service == 'api' }}- with:- tag: ${{ github.event.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 }}-- - uses: ./.github/actions/production-api-deploy- if: ${{ github.event.inputs.environment == 'production' && github.event.inputs.service == 'api' }}- with:- tag: ${{ github.event.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 }}