Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Unify rollback & deployment, simplify deployment workflow (#767)

Madison Swain-Bowdena705b4fae18d
diff --git a/.github/actions/production-nuxt-deploy/action.yml b/.github/actions/production-nuxt-deploy/action.yml
index 886ddcf15..1e21fe090 100644
--- a/.github/actions/production-nuxt-deploy/action.yml
+++ b/.github/actions/production-nuxt-deploy/action.yml
@@ -66,6 +66,34 @@ runs:
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()
diff --git a/.github/actions/staging-api-deploy/action.yml b/.github/actions/staging-api-deploy/action.yml
index a1ed7e6ff..944325e30 100644
--- a/.github/actions/staging-api-deploy/action.yml
+++ b/.github/actions/staging-api-deploy/action.yml
@@ -66,6 +66,62 @@ runs:
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()
diff --git a/.github/actions/staging-nuxt-deploy/action.yml b/.github/actions/staging-nuxt-deploy/action.yml
index 5d86dc87f..b5546225f 100644
--- a/.github/actions/staging-nuxt-deploy/action.yml
+++ b/.github/actions/staging-nuxt-deploy/action.yml
@@ -66,6 +66,34 @@ runs:
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()
diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml
index 08326eedf..319dece49 100644
--- a/.github/workflows/ci_cd.yml
+++ b/.github/workflows/ci_cd.yml
@@ -10,7 +10,7 @@ on:
- published
workflow_dispatch:
inputs:
- image_tag:
+ image-tag:
description: "The tag to assign to the images built in the workflow."
type: string
required: true
@@ -58,7 +58,7 @@ jobs:
id: get-image-tag
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
- echo "image-tag=${{ inputs.image_tag }}" >> "$GITHUB_OUTPUT"
+ echo "image-tag=${{ inputs.image-tag }}" >> "$GITHUB_OUTPUT"
elif [[ "${{ github.event_name }}" == "release" ]]; then
echo "image-tag=${{ github.ref_name }}" >> "$GITHUB_OUTPUT"
else
diff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.yml
new file mode 100644
index 000000000..c29f4c6c7
--- /dev/null
+++ b/.github/workflows/deployment.yml
@@ -0,0 +1,63 @@
+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 }}-${{ 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
+
+ - uses: ./.github/actions/${{ inputs.environment }}-${{ inputs.service }}-deploy
+ 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/rollback.yml b/.github/workflows/rollback.yml
deleted file mode 100644
index 643c8fd1f..000000000
--- a/.github/workflows/rollback.yml
+++ /dev/null
@@ -1,93 +0,0 @@
-name: Rollback Frontend
-
-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
- 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.'
- )
- }
-
- - uses: ./.github/actions/production-nuxt-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-nuxt-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 }}