Skip to content

Commit

Permalink
Add production deployment scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-md committed Jan 30, 2024
1 parent d6fe7f0 commit 2b5eda6
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 3 deletions.
17 changes: 17 additions & 0 deletions .github/scripts/prepar_production_deployment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

set -ev

# Only:
# - Tagged commits
# - Security env variables are available.
if [ -n "$VERSION_TAG" ] && [ -n "$PROD_DEPLOYMENT_HOOK_TOKEN" ] && [ -n "$PROD_DEPLOYMENT_HOOK_URL" ]
then
curl --silent --output /dev/null --write-out "%{http_code}" -X POST \
-F token="$PROD_DEPLOYMENT_HOOK_TOKEN" \
-F ref=master \
-F "variables[TRIGGER_RELEASE_COMMIT_TAG]=$VERSION_TAG" \
$PROD_DEPLOYMENT_HOOK_URL
else
echo "[ERROR] Production deployment could not be prepared"
fi
52 changes: 52 additions & 0 deletions .github/workflows/deploy-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Release

on:
release:
types: [published]

jobs:
deploy:
runs-on: ubuntu-latest
permissions: write-all

name: Deploy release

steps:
- name: Cancel previous runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

- uses: actions/checkout@v3

- uses: pnpm/action-setup@v2
with:
version: 8

- name: Install dependencies
shell: bash
run: pnpm install --frozen-lockfile

- name: Build app
shell: bash
run: pnpm build

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v3
with:
role-to-assume: ${{ secrets.AWS_ROLE }}
aws-region: ${{ secrets.AWS_REGION }}

# Deploy the main branch to production environment
- name: Deploy to the production S3
if: github.ref == 'refs/heads/main'
env:
BUCKET: s3://${{ secrets.AWS_STAGING_BUCKET_NAME }}/releases/${{ github.event.release.tag_name }}
run: bash ./.github/scripts/s3_upload.sh

# Script to prepare production deployments
- run: bash ./.github/scripts/prepare_production_deployment.sh
env:
PROD_DEPLOYMENT_HOOK_TOKEN: ${{ secrets.PROD_DEPLOYMENT_HOOK_TOKEN }}
PROD_DEPLOYMENT_HOOK_URL: ${{ secrets.PROD_DEPLOYMENT_HOOK_URL }}
VERSION_TAG: ${{ github.event.release.tag_name }}
6 changes: 3 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Deploy to staging
on:
push:
branches:
- nextra
- development

jobs:
deploy:
Expand Down Expand Up @@ -38,9 +38,9 @@ jobs:
role-to-assume: ${{ secrets.AWS_ROLE }}
aws-region: ${{ secrets.AWS_REGION }}

# Deploy the nextra branch to staging
# Deploy the development branch to staging
- name: Deploy to the staging S3
if: github.ref == 'refs/heads/nextra'
if: github.ref == 'refs/heads/development'
env:
BUCKET: s3://${{ secrets.AWS_STAGING_BUCKET_NAME }}/current
run: bash ./.github/scripts/s3_upload.sh

0 comments on commit 2b5eda6

Please sign in to comment.