Deploy the Backend #9
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/backend/src/**' | |
- 'apps/backend/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 }} | |
RELEASE_VERSION: ${{ github.event.inputs.version }} | |
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/backend | |
- 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/backend/build | |
sentry-cli releases finalize "$VERSION" | |
package: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Copy the backend Dockerfile in the root repository | |
run: cp apps/backend/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-backend-prod') || 'snipcode-backend-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 --build-arg APP_VERSION=$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: aws apprunner start-deployment --region $AWS_DEFAULT_REGION --service-arn ${{ secrets.CORE_APP_ARN }} |