chore(app): implement release process (#65) #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy the Backend | |
on: | |
push: | |
branches: | |
- dev | |
paths: | |
- 'apps/core/src/**' | |
- 'apps/core/Dockerfile' | |
workflow_dispatch: | |
inputs: | |
version: | |
description: 'New version of the backend to release' | |
type: string | |
required: true | |
default: 'latest' | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_DEFAULT_REGION: ${{ secrets.AWS_REGION }} | |
jobs: | |
sourcemaps: | |
runs-on: ubuntu-latest | |
continue-on-error: true | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install dependencies | |
uses: ./.github/actions/install-dependencies | |
- name: Generate sourcemaps from build | |
run: yarn build:prod --filter=...@snipcode/core | |
- name: Create a Sentry release | |
env: | |
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} | |
SENTRY_ORG: snipcode | |
SENTRY_PROJECT: backend | |
VERSION: ${{ github.sha }} | |
run: | | |
curl -sL https://sentry.io/get-cli/ | SENTRY_CLI_VERSION="2.2.0" bash | |
sentry-cli releases new "$VERSION" | |
sentry-cli releases files "$VERSION" upload-sourcemaps ./apps/core/build | |
sentry-cli releases finalize "$VERSION" | |
package: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Copy the core Dockerfile in the root repository | |
run: cp apps/core/Dockerfile . | |
- name: Build, tag, and push docker image to Amazon ECR | |
env: | |
REGISTRY: public.ecr.aws/x9y5g9l2 | |
REGION: us-east-1 # Public ECR aren't region specific | |
REPOSITORY: ${{ (github.ref == 'refs/heads/main' && 'snipcode') || 'snipcode-dev' }} | |
IMAGE_TAG: ${{ inputs.version }} | |
run: | | |
aws ecr-public get-login-password --region $REGION | docker login --username AWS --password-stdin $REGISTRY | |
docker build -t $REPOSITORY:$IMAGE_TAG . | |
docker tag $REPOSITORY:$IMAGE_TAG $REGISTRY/$REPOSITORY:$IMAGE_TAG | |
docker tag $REPOSITORY:$IMAGE_TAG $REGISTRY/$REPOSITORY:latest | |
docker push --all-tags $REGISTRY/$REPOSITORY | |
deploy: | |
runs-on: ubuntu-latest | |
environment: ${{ (github.ref == 'refs/heads/main' && 'Production') || 'Development' }} | |
needs: | |
- package | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Deploy the application | |
run: | | |
touch file.json && echo '${{ secrets.CORE_APP_ARN }}' > file.json | |
aws apprunner start-deployment --region $AWS_DEFAULT_REGION --cli-input-json file://file.json |