Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Staging and production deployment workflows #563

Merged
merged 27 commits into from
Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a4c6fef
feat: added deploy workflows for staging and production
rbadillap Dec 27, 2021
47cca89
merge conflicts before undraft the PR
rbadillap Jan 11, 2022
a833c36
feat: rename the event that triggers the deploy to production
rbadillap Jan 11, 2022
a6ac112
format files
zackkrida Feb 1, 2022
54b9d7f
Merge branch 'main' into ci/actions
rbadillap Feb 2, 2022
ad503dd
feat: switch prerelease event to release
rbadillap Feb 2, 2022
f6f8763
feat: change the url of the deployment workflow for visual reference …
rbadillap Feb 2, 2022
4056491
test: deploying to staging and production environments
rbadillap Feb 2, 2022
5b83ee4
test: point the branch in the action name to avoid errors
rbadillap Feb 2, 2022
6a8d006
fix: point the right name of the build workflow file
rbadillap Feb 2, 2022
689ae5f
fix: name of the branch when calling the action
rbadillap Feb 2, 2022
529fff2
feat: relocate the build workflow as an action
rbadillap Feb 3, 2022
c059921
feat: point the right name of the action
rbadillap Feb 3, 2022
9424da8
feat: try using the branch to reference the action file
rbadillap Feb 3, 2022
70bf20a
Update push_staging.yaml
rbadillap Feb 3, 2022
6ae3554
Update push_staging.yaml
rbadillap Feb 3, 2022
ef1d0bd
Update push_staging.yaml
rbadillap Feb 3, 2022
5e44560
Update push_staging.yaml
rbadillap Feb 3, 2022
d2b4e03
feat: fix the inputs and env vars in the action file
rbadillap Feb 3, 2022
2fb595e
Update action.yml
rbadillap Feb 3, 2022
5db5964
Update action.yml
rbadillap Feb 3, 2022
8d3a737
Update action.yml
rbadillap Feb 3, 2022
af9cb5c
Update action.yml
rbadillap Feb 3, 2022
bcce151
Update action.yml
rbadillap Feb 3, 2022
5eb2272
Update action.yml
rbadillap Feb 3, 2022
2b78775
Update action.yml
rbadillap Feb 3, 2022
acc8fc2
feat: stabilize the workflows and propagate the same configuration to…
rbadillap Feb 3, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 49 additions & 18 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
# this build is triggered when a new pre-release has been created
# it creates a new docker build image based on the tag associated
# this is a reusable workflow that will be called by the
# push_staging and push_production workflows
# more info: https://docs.github.com/en/actions/learn-github-actions/reusing-workflows

name: build

on:
release:
types:
- "prereleased"
workflow_call:
inputs:
is_production:
required: true
type: boolean
description: Determine whether the current workflow is executed against production or not

# TODO: get the secrets via inputs, so we let the staging/production workflows retrieve their corresponding credentials
env:
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
Expand All @@ -19,17 +25,6 @@ jobs:
runs-on: ubuntu-latest

steps:
# download the source code into the runner
- name: checkout
uses: actions/checkout@v2

# gather metadata from git & github actions to reference in docker
- name: git & github metadata
id: metadata
uses: docker/metadata-action@v3
with:
images: ${{ env.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/openverse/frontend

# setup docker buildx
- name: setup docker buildx
uses: docker/setup-buildx-action@v1
Expand All @@ -40,11 +35,47 @@ jobs:
- name: docker login
uses: aws-actions/amazon-ecr-login@v1

# for staging
# gather metadata from git & github actions to reference in docker
- name: git & github metadata staging
id: metadata_staging
uses: docker/metadata-action@v3
if: ${{ github.event.inputs.is_production == false }}
with:
images: ${{ env.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/openverse/frontend
tags: |
latest=auto
type=edge,branch=main

# build a docker image
- name: build docker image
uses: docker/build-push-action@v2
if: ${{ github.event.inputs.is_production == false }}
with:
context: .
tags: ${{ steps.metadata_staging.outputs.tags }}
labels: ${{ steps.metadata_staging.outputs.labels }}
push: true

# for production
# gather metadata from git & github actions to reference in docker
- name: git & github metadata production
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a lot of similarities between this and the staging step. I wonder if we might be able to combine the logic and add conditions in certain places for each deployment case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point, and that's what I mentioned when I officially announced this PR.

This is something that will be improved in the future based on what we are going to see when deploying this on the real infrastructure.

By now, I'm separating the logic between staging and production, but I'm planning to send a PR to the official action project (owned by Docker) that allows me to manipulate the tags without the need to duplicate the whole step.

cc @zackkrida

id: metadata_production
uses: docker/metadata-action@v3
if: ${{ github.event.inputs.is_production == true }}
with:
images: ${{ env.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/openverse/frontend
tags: |
latest=false
type=raw,value=stable
type=semver,pattern={{version}}

# build a docker image
- name: build docker image
uses: docker/build-push-action@v2
if: ${{ github.event.inputs.is_production == true }}
with:
context: .
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
tags: ${{ steps.metadata_production.outputs.tags }}
labels: ${{ steps.metadata_production.outputs.labels }}
push: true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this push trigger a deployment of our AWS infrastructure? Is that encapsulated in this workflow or will that be future work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deployment is made by CodePipeline in our AWS. I just push the image to ECR and the event will automatically be triggered internally.

That's why I opened a discussion a few days ago, because I would need to change this part and build some communication between CodePipeline and ghcr.io events.

28 changes: 28 additions & 0 deletions .github/workflows/push_production.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# this build is triggered when a new pre-release has been created
# it creates a new docker build image based on the tag associated

name: push_production

on:
release:
types:
- 'released'

jobs:
push:
name: push
runs-on: ubuntu-latest
environment:
name: production
url: https://search-prod.openverse.engineering

steps:
# download the source code into the runner
- name: checkout
uses: actions/checkout@v2

# build a new docker image and push it into the repository
- name: docker build
uses: ./.github/workflows/build.yaml@v1
with:
is_production: true
29 changes: 29 additions & 0 deletions .github/workflows/push_staging.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# this build is triggered when a new pull request has been merged
# into the main branch

name: push_staging

on:
push:
branches:
- main
- ci/* # allow any ci/* branch the ability to deploy to staging without the need to merge the PR

jobs:
push:
name: push
runs-on: ubuntu-latest
environment:
name: staging
url: https://search-staging.openverse.engineering
zackkrida marked this conversation as resolved.
Show resolved Hide resolved

steps:
# download the source code into the runner
- name: checkout
uses: actions/checkout@v2

# build a new docker image and push it into the repository
- name: docker build
uses: ./.github/workflows/build.yaml@v1
with:
is_production: false