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 all 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
88 changes: 88 additions & 0 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# 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: openverse/build
description: build a docker image that can be used in different environments

inputs:
is_production:
required: true
description: Determine whether the current workflow is executed against production or not
aws_region:
required: true
description: AWS region where the resource will be deployed
aws_account_id:
required: true
description: AWS account number where the resources are already deployed
aws_access_key_id:
required: true
description: AWS access key id that performs the modifications described in this action
aws_secret_access_key:
required: true
description: AWS secret access key associated to the access key id specified above

runs:
using: "composite"
steps:
# setup docker buildx
- name: setup docker buildx
uses: docker/setup-buildx-action@v1
with:
install: true

# login in docker repository
- name: docker login
uses: aws-actions/amazon-ecr-login@v1
env:
AWS_REGION: ${{ inputs.aws_region }}
AWS_ACCOUNT_ID: ${{ inputs.aws_account_id }}
AWS_ACCESS_KEY_ID: ${{ inputs.aws_access_key_id }}
AWS_SECRET_ACCESS_KEY: ${{ inputs.aws_secret_access_key }}

# 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: ${{ inputs.aws_account_id }}.dkr.ecr.${{ inputs.aws_region }}.amazonaws.com/openverse/frontend
tags: |
type=raw,value=latest
type=ref,event=branch

# 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
id: metadata_production
uses: docker/metadata-action@v3
if: ${{ github.event.inputs.is_production == true }}
with:
images: ${{ inputs.aws_account_id }}.dkr.ecr.${{ inputs.aws_region }}.amazonaws.com/openverse/frontend
flavor: |
latest=false
tags: |
type=raw,value=stable
type=ref,event=tag
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_production.outputs.tags }}
labels: ${{ steps.metadata_production.outputs.labels }}
push: true
50 changes: 0 additions & 50 deletions .github/workflows/build.yml

This file was deleted.

12 changes: 6 additions & 6 deletions .github/workflows/pre-build.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# this workflow will try to lint and build a node.js application
#
# this is useful for stages that you require to make sure everything is working
# this is useful for stages that you require making sure everything is working
# properly before creating a container image to be pushed on the cloud
#
name: pre_build
name: openverse/validate

on:
pull_request:
push:
branches:
- 'main'
- 'ci/*' # branches that follows the pattern ci/* can access this workflow too
# push:
# branches:
# - 'main'
# - 'ci/*' # branches that follows the pattern ci/* can access this workflow too
zackkrida marked this conversation as resolved.
Show resolved Hide resolved

jobs:
pre_build:
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/push_production.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# 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: openverse/deploy/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/actions/build
with:
is_production: true
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
33 changes: 33 additions & 0 deletions .github/workflows/push_staging.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# this build is triggered when a new pull request has been merged
# into the main branch

name: openverse/deploy/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/actions/build
with:
is_production: false
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}