Skip to content

AWS Deployment

AWS Deployment #365

---
name: AWS Deployment
on:
workflow_dispatch:
inputs:
environment:
description: "Environment to deploy to"
default: "staging"
options:
- staging
- production
required: true
type: choice
env:
AWS_ACCOUNT_ID: ${{ vars.AWS_PUBLIC_DATA_RELEASES_ACCOUNT_ID }}
AWS_REGION: ${{ vars.AWS_DEFAULT_REGION }}
STAGING_CLOUDFRONT_DISTRIBUTION_ID: ${{ secrets.STAGING_CLOUDFRONT_DISTRIBUTION_ID }}
STAGING_S3_BUCKET: s3://staging.bff.allencell.org
STAGING_BFF_CLOUDFRONT_DISTRIBUTION_ID: ${{ secrets.STAGING_BFF_CLOUDFRONT_DISTRIBUTION_ID }}
PRODUCTION_CLOUDFRONT_DISTRIBUTION_ID: ${{ secrets.PRODUCTION_CLOUDFRONT_DISTRIBUTION_ID }}
PRODUCTION_S3_BUCKET: s3://bff.allencell.org
PRODUCTION_BFF_CLOUDFRONT_DISTRIBUTION_ID: ${{ secrets.PRODUCTION_BFF_CLOUDFRONT_DISTRIBUTION_ID }}
permissions:
id-token: write # Required for requesting the JWT and OIDC
contents: write # Required for actions/checkout and OIDC tokens
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e
with:
node-version: 24
- name: Install Dependencies
run: npm ci
- name: Build
run: npm run --prefix packages/web build
- name: Upload build files
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
with:
name: aws-deploy-files
path: ./packages/web/dist
deploy:
needs: build
runs-on: ubuntu-latest
# Dynamically set the environment variable based on the input above:
environment: ${{ github.event.inputs.environment }}
steps:
# Compute a short sha for use in the OIDC session name, which has a 64 character limit
- name: Add SHORT_SHA env property with commit short sha
run: echo "SHORT_SHA=`echo ${{ github.sha }} | cut -c1-8`" >> $GITHUB_ENV
- name: Configure AWS credentials with OIDC
uses: aws-actions/configure-aws-credentials@e7f100cf4c008499ea8adda475de1042d6975c7b
with:
role-to-assume: arn:aws:iam::${{ env.AWS_ACCOUNT_ID }}:role/github_biofile_finder
role-session-name: github_biofile_finder-${{ env.SHORT_SHA }}
aws-region: ${{ env.AWS_REGION }}
# Setup variables based on the staging or production environment
- name: Set ECS variables based on environment
run: |
if [ "${{ github.event.inputs.environment }}" == "production" ]; then
echo "S3_BUCKET=${{ env.PRODUCTION_S3_BUCKET }}" >> $GITHUB_ENV
echo "CLOUDFRONT_DISTRIBUTION_ID=${{ env.PRODUCTION_CLOUDFRONT_DISTRIBUTION_ID }}" >> $GITHUB_ENV
echo "BFF_CLOUDFRONT_DISTRIBUTION_ID=${{ env.PRODUCTION_BFF_CLOUDFRONT_DISTRIBUTION_ID }}" >> $GITHUB_ENV
elif [ "${{ github.event.inputs.environment }}" == "staging" ]; then
echo "S3_BUCKET=${{ env.STAGING_S3_BUCKET }}" >> $GITHUB_ENV
echo "CLOUDFRONT_DISTRIBUTION_ID=${{ env.STAGING_CLOUDFRONT_DISTRIBUTION_ID }}" >> $GITHUB_ENV
echo "BFF_CLOUDFRONT_DISTRIBUTION_ID=${{ env.STAGING_BFF_CLOUDFRONT_DISTRIBUTION_ID }}" >> $GITHUB_ENV
else
echo "Invalid environment specified"
exit 1
fi
- name: Download build artifacts
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c
with:
name: aws-deploy-files
path: ./packages/web/dist
# Note that the command below will copy the files to the root of the S3 bucket e.g., s3://bff.allencell.org/
# If you want to copy files to a S3 prefix / subdirectory, you would want something like ${{ env.BFF_S3_BUCKET }}/your_prefix below
- name: Copy build files to BFF S3
run: aws s3 sync ./packages/web/dist ${{ env.S3_BUCKET }}
# This isn't strictly necessary since this distribution only handles redirects and doesn't serve any content directly
- name: Invalidate CloudFront biofile-finder cache
run: aws cloudfront create-invalidation --distribution-id ${{ env.CLOUDFRONT_DISTRIBUTION_ID }} --paths "/*"
- name: Invalidate CloudFront BFF cache
run: aws cloudfront create-invalidation --distribution-id ${{ env.BFF_CLOUDFRONT_DISTRIBUTION_ID }} --paths "/*"