Skip to content

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

Add user validation, concurrency, manual runs to deployment workflow (#910)

Madison Swain-Bowden3887509e8415
diff --git a/.github/workflows/deploy-production-api.yml b/.github/workflows/deploy-production-api.yml
index 6b4f22ae8..87c78ede3 100644
--- a/.github/workflows/deploy-production-api.yml
+++ b/.github/workflows/deploy-production-api.yml
@@ -8,6 +8,12 @@
name: "Deployment: production-api"
on:
+ workflow_dispatch:
+ inputs:
+ tag:
+ type: string
+ required: true
+ description: Image tag to deploy.
workflow_call:
inputs:
tag:
@@ -15,6 +21,9 @@ on:
required: true
description: Image tag to deploy.
secrets:
+ ACCESS_TOKEN:
+ required: true
+ description: GitHub access token.
AWS_ACCESS_KEY_ID:
required: true
description: AWS access key ID.
@@ -28,6 +37,11 @@ on:
required: true
description: JSON mapping of GitHub usernames to Slack user IDs.
+# Only allow a single deployment workflow (service + environment) to happen at a time
+# If you need to stop an in-progress deployment of a service to force another for
+# the same environment, you'll need to manually cancel it
+concurrency: ${{ github.workflow }}
+
jobs:
deploy:
name: Deploy production-api
@@ -37,6 +51,24 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3
+ - name: Validate initiation user
+ 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."
+ )
+ }
+
- name: Set the Slack user
shell: python
env:
@@ -62,7 +94,7 @@ jobs:
"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."
+ "text": ":spinning-cd: A deployment of *production-api* triggered by <@${{ env.SLACK_USER_ID }}> is starting using the `${{ inputs.tag }}` tag."
}
},
{
@@ -188,7 +220,7 @@ jobs:
"type": "section",
"text": {
"type": "mrkdwn",
- "text": ":tadaco: The deployment of production-api triggered by <@${{ env.SLACK_USER_ID }}> using the `${{ inputs.tag }}` tag *succeeded*."
+ "text": ":tadaco: The deployment of *production-api* triggered by <@${{ env.SLACK_USER_ID }}> using the `${{ inputs.tag }}` tag *succeeded*."
}
},
{
@@ -216,7 +248,7 @@ jobs:
"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:"
+ "text": ":alert: The deployment of *production-api* triggered by <@${{ env.SLACK_USER_ID }}> using the `${{ inputs.tag }}` tag *failed* :alert:"
}
},
{
diff --git a/.github/workflows/deploy-production-nuxt.yml b/.github/workflows/deploy-production-nuxt.yml
index 2a169acda..431679f82 100644
--- a/.github/workflows/deploy-production-nuxt.yml
+++ b/.github/workflows/deploy-production-nuxt.yml
@@ -8,6 +8,12 @@
name: "Deployment: production-nuxt"
on:
+ workflow_dispatch:
+ inputs:
+ tag:
+ type: string
+ required: true
+ description: Image tag to deploy.
workflow_call:
inputs:
tag:
@@ -15,6 +21,9 @@ on:
required: true
description: Image tag to deploy.
secrets:
+ ACCESS_TOKEN:
+ required: true
+ description: GitHub access token.
AWS_ACCESS_KEY_ID:
required: true
description: AWS access key ID.
@@ -28,6 +37,11 @@ on:
required: true
description: JSON mapping of GitHub usernames to Slack user IDs.
+# Only allow a single deployment workflow (service + environment) to happen at a time
+# If you need to stop an in-progress deployment of a service to force another for
+# the same environment, you'll need to manually cancel it
+concurrency: ${{ github.workflow }}
+
jobs:
deploy:
name: Deploy production-nuxt
@@ -37,6 +51,24 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3
+ - name: Validate initiation user
+ 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."
+ )
+ }
+
- name: Set the Slack user
shell: python
env:
@@ -62,7 +94,7 @@ jobs:
"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."
+ "text": ":spinning-cd: A deployment of *production-nuxt* triggered by <@${{ env.SLACK_USER_ID }}> is starting using the `${{ inputs.tag }}` tag."
}
},
{
@@ -152,7 +184,7 @@ jobs:
"type": "section",
"text": {
"type": "mrkdwn",
- "text": ":tadaco: The deployment of production-nuxt triggered by <@${{ env.SLACK_USER_ID }}> using the `${{ inputs.tag }}` tag *succeeded*."
+ "text": ":tadaco: The deployment of *production-nuxt* triggered by <@${{ env.SLACK_USER_ID }}> using the `${{ inputs.tag }}` tag *succeeded*."
}
},
{
@@ -180,7 +212,7 @@ jobs:
"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:"
+ "text": ":alert: The deployment of *production-nuxt* triggered by <@${{ env.SLACK_USER_ID }}> using the `${{ inputs.tag }}` tag *failed* :alert:"
}
},
{
diff --git a/.github/workflows/deploy-staging-api.yml b/.github/workflows/deploy-staging-api.yml
index 5774693df..8aa8e9b6b 100644
--- a/.github/workflows/deploy-staging-api.yml
+++ b/.github/workflows/deploy-staging-api.yml
@@ -8,6 +8,12 @@
name: "Deployment: staging-api"
on:
+ workflow_dispatch:
+ inputs:
+ tag:
+ type: string
+ required: true
+ description: Image tag to deploy.
workflow_call:
inputs:
tag:
@@ -15,6 +21,9 @@ on:
required: true
description: Image tag to deploy.
secrets:
+ ACCESS_TOKEN:
+ required: true
+ description: GitHub access token.
AWS_ACCESS_KEY_ID:
required: true
description: AWS access key ID.
@@ -28,6 +37,11 @@ on:
required: true
description: JSON mapping of GitHub usernames to Slack user IDs.
+# Only allow a single deployment workflow (service + environment) to happen at a time
+# If you need to stop an in-progress deployment of a service to force another for
+# the same environment, you'll need to manually cancel it
+concurrency: ${{ github.workflow }}
+
jobs:
deploy:
name: Deploy staging-api
@@ -37,6 +51,24 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3
+ - name: Validate initiation user
+ 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."
+ )
+ }
+
- name: Set the Slack user
shell: python
env:
@@ -62,7 +94,7 @@ jobs:
"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."
+ "text": ":spinning-cd: A deployment of *staging-api* triggered by <@${{ env.SLACK_USER_ID }}> is starting using the `${{ inputs.tag }}` tag."
}
},
{
@@ -188,7 +220,7 @@ jobs:
"type": "section",
"text": {
"type": "mrkdwn",
- "text": ":tadaco: The deployment of staging-api triggered by <@${{ env.SLACK_USER_ID }}> using the `${{ inputs.tag }}` tag *succeeded*."
+ "text": ":tadaco: The deployment of *staging-api* triggered by <@${{ env.SLACK_USER_ID }}> using the `${{ inputs.tag }}` tag *succeeded*."
}
},
{
@@ -216,7 +248,7 @@ jobs:
"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:"
+ "text": ":alert: The deployment of *staging-api* triggered by <@${{ env.SLACK_USER_ID }}> using the `${{ inputs.tag }}` tag *failed* :alert:"
}
},
{
diff --git a/.github/workflows/deploy-staging-nuxt.yml b/.github/workflows/deploy-staging-nuxt.yml
index 626970c54..231a346d9 100644
--- a/.github/workflows/deploy-staging-nuxt.yml
+++ b/.github/workflows/deploy-staging-nuxt.yml
@@ -8,6 +8,12 @@
name: "Deployment: staging-nuxt"
on:
+ workflow_dispatch:
+ inputs:
+ tag:
+ type: string
+ required: true
+ description: Image tag to deploy.
workflow_call:
inputs:
tag:
@@ -15,6 +21,9 @@ on:
required: true
description: Image tag to deploy.
secrets:
+ ACCESS_TOKEN:
+ required: true
+ description: GitHub access token.
AWS_ACCESS_KEY_ID:
required: true
description: AWS access key ID.
@@ -28,6 +37,11 @@ on:
required: true
description: JSON mapping of GitHub usernames to Slack user IDs.
+# Only allow a single deployment workflow (service + environment) to happen at a time
+# If you need to stop an in-progress deployment of a service to force another for
+# the same environment, you'll need to manually cancel it
+concurrency: ${{ github.workflow }}
+
jobs:
deploy:
name: Deploy staging-nuxt
@@ -37,6 +51,24 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3
+ - name: Validate initiation user
+ 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."
+ )
+ }
+
- name: Set the Slack user
shell: python
env:
@@ -62,7 +94,7 @@ jobs:
"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."
+ "text": ":spinning-cd: A deployment of *staging-nuxt* triggered by <@${{ env.SLACK_USER_ID }}> is starting using the `${{ inputs.tag }}` tag."
}
},
{
@@ -152,7 +184,7 @@ jobs:
"type": "section",
"text": {
"type": "mrkdwn",
- "text": ":tadaco: The deployment of staging-nuxt triggered by <@${{ env.SLACK_USER_ID }}> using the `${{ inputs.tag }}` tag *succeeded*."
+ "text": ":tadaco: The deployment of *staging-nuxt* triggered by <@${{ env.SLACK_USER_ID }}> using the `${{ inputs.tag }}` tag *succeeded*."
}
},
{
@@ -180,7 +212,7 @@ jobs:
"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:"
+ "text": ":alert: The deployment of *staging-nuxt* triggered by <@${{ env.SLACK_USER_ID }}> using the `${{ inputs.tag }}` tag *failed* :alert:"
}
},
{