Skip to content

Commit

Permalink
Staging to Production (#161)
Browse files Browse the repository at this point in the history
Changes:

- [x] Upgrade EMIT Plumes Portal
- [x] Add GOES Methane Portal
- [x] Fix trailing slash issue with all react apps
- [x] Refactor CICD a lil bit
  • Loading branch information
slesaad authored Dec 5, 2024
2 parents 374e39a + bddf902 commit 41c7fd5
Show file tree
Hide file tree
Showing 120 changed files with 24,343 additions and 1,144 deletions.
71 changes: 24 additions & 47 deletions .github/workflows/deploy-emit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,32 @@ jobs:
working-directory: ./emit-ch4plume-v1
run: |
GEOAPIFY_APIKEY="${{ secrets.GEOAPIFY_APIKEY }}" node update_data.js
- name: Validate required variables and secrets
run: |
missing_vars=()
# Check for required variables
[ -z "${{ vars.PUBLIC_URL_EMIT }}" ] && missing_vars+=("vars.PUBLIC_URL_EMIT")
[ -z "${{ vars.MAP_STYLE }}" ] && missing_vars+=("vars.MAP_STYLE")
[ -z "${{ secrets.MAP_ACCESS_TOKEN }}" ] && missing_vars+=("secrets.MAP_ACCESS_TOKEN")
[ -z "${{ secrets.DEPLOYMENT_ROLE_ARN }}" ] && missing_vars+=("secrets.DEPLOYMENT_ROLE_ARN")
[ -z "${{ secrets.CF_DISTRIBUTION_ID }}" ] && missing_vars+=("secrets.CF_DISTRIBUTION_ID")
# If any variables are missing, print them and exit with an error
if [ ${#missing_vars[@]} -ne 0 ]; then
echo "Error: The following required variables are missing:"
printf '%s\n' "${missing_vars[@]}"
exit 1
fi
shell: bash

- name: Build for production 🔧
working-directory: ./emit-ch4plume-v1
run: |
echo PUBLIC_URL="${{ vars.PUBLIC_URL_EMIT }}" >> .env
echo MAP_STYLE="${{ vars.MAP_STYLE }}" >> .env
echo MAP_ACCESS_TOKEN="${{ secrets.MAP_ACCESS_TOKEN }}" >> .env
echo PUBLIC_URL="${{ vars.PUBLIC_URL_EMIT }}" >> .env
echo STAGE="production" >> .env
npm install
npm run deploy
Expand All @@ -67,51 +85,12 @@ jobs:
name: dist_folder
path: ./emit-ch4plume-v1/dist

deploy-staging:
needs:
- build
- define-environment
if: needs.define-environment.outputs.target_branch == 'main'
environment: ${{ needs.define-environment.outputs.env_name }}

permissions:
id-token: write
contents: read

runs-on: ubuntu-latest
steps:

- name: Download dist folder
uses: actions/download-artifact@v4
with:
name: dist_folder
path: ./emit-ch4plume-v1/dist

- name: ConfigureAWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.DEPLOYMENT_ROLE_ARN }}
role-session-name: ${{ github.repository_owner}}
aws-region: us-west-2

- name: Upload to S3
run: |
export PUBLIC_URL=$(echo ${{ vars.PUBLIC_URL_EMIT }} | sed -E 's|^https?://[^/]+/||')
echo "PUBLIC_URL=${PUBLIC_URL}" >> $GITHUB_ENV
aws s3 sync "./emit-ch4plume-v1/dist" s3://ghgc-custom-interfaces-staging/${PUBLIC_URL}/ --cache-control max-age=30,must-revalidate,s-maxage=604800 --delete
- name: Request Invalidation to AWS Cloudfront
uses: oneyedev/aws-cloudfront-invalidation@v1
with:
distribution-id: ${{ secrets.CF_DISTRIBUTION_ID }}
paths: |
/${{ env.PUBLIC_URL }}*

deploy-production:
deploy:
name: Deploy EMIT to ${{ needs.define-environment.outputs.env_name }} 🚀
needs:
- build
- define-environment
if: needs.define-environment.outputs.target_branch == 'production'
environment: ${{ needs.define-environment.outputs.env_name }}

permissions:
Expand All @@ -136,13 +115,11 @@ jobs:

- name: Upload to S3
run: |
export PUBLIC_URL=$(echo ${{ vars.PUBLIC_URL_EMIT }} | sed -E 's|^https?://[^/]+/||')
echo "PUBLIC_URL=${PUBLIC_URL}" >> $GITHUB_ENV
aws s3 sync "./emit-ch4plume-v1/dist" s3://ghgc-custom-interfaces-production/${PUBLIC_URL}/ --cache-control max-age=30,must-revalidate,s-maxage=604800 --delete
aws s3 sync "./emit-ch4plume-v1/dist" s3://${{ vars.DEPLOYMENT_BUCKET }}${{ vars.PUBLIC_URL_EMIT }}/ --cache-control max-age=30,must-revalidate,s-maxage=604800 --delete
- name: Request Invalidation to AWS Cloudfront
uses: oneyedev/aws-cloudfront-invalidation@v1
with:
distribution-id: ${{ secrets.CF_DISTRIBUTION_ID }}
paths: |
/${{ env.PUBLIC_URL }}*
/ghgcenter/custom-interfaces/*
133 changes: 133 additions & 0 deletions .github/workflows/deploy-goes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
name: Deploy GOES

on:
workflow_dispatch:
push:
branches: [ main, production ]
paths:
- goes-plume-viewer/**

jobs:
define-environment:
name: Set environment
runs-on: ubuntu-latest
outputs:
env_name: ${{ steps.define_environment.outputs.env_name }}
steps:
- name: Set the environment based on the branch
id: define_environment
run: |
if [ "${{ github.ref }}" = "refs/heads/main" ]; then
echo "env_name=staging" >> $GITHUB_OUTPUT
elif [ "${{ github.ref }}" = "refs/heads/deploy-goes-to-prod" ]; then
echo "env_name=production" >> $GITHUB_OUTPUT
elif [ "${{ github.ref }}" = "refs/heads/production" ]; then
echo "env_name=production" >> $GITHUB_OUTPUT
fi
- name: Print the environment
run: echo "The environment is ${{ steps.define_environment.outputs.env_name }}"

build:
runs-on: ubuntu-latest
needs: define-environment
environment: ${{ needs.define-environment.outputs.env_name }}

steps:
- name: Checkout 🛎️
uses: actions/checkout@v4
with:
sparse-checkout: 'goes-plume-viewer/'
sparse-checkout-cone-mode: true

- name: Read Node.js version from .nvmrc
id: nvm
run: echo "::set-output name=NODE_VERSION::$(cat goes-plume-viewer/.nvmrc)"

- uses: actions/setup-node@v3
with:
node-version: ${{ steps.nvm.outputs.NODE_VERSION }}

- name: Install Yarn
run: npm install -g yarn

- name: Validate required variables and secrets
run: |
missing_vars=()
# Check for required variables
[ -z "${{ secrets.REACT_APP_MAPBOX_ACCESS_TOKEN }}" ] && missing_vars+=("secrets.REACT_APP_MAPBOX_ACCESS_TOKEN")
[ -z "${{ secrets.REACT_APP_MAPBOX_STYLE_URL }}" ] && missing_vars+=("secrets.REACT_APP_MAPBOX_STYLE_URL")
[ -z "${{ vars.REACT_APP_BASE_PATH_GOES }}" ] && missing_vars+=("vars.REACT_APP_BASE_PATH_GOES")
[ -z "${{ secrets.DEPLOYMENT_ROLE_ARN }}" ] && missing_vars+=("secrets.DEPLOYMENT_ROLE_ARN")
[ -z "${{ secrets.CF_DISTRIBUTION_ID }}" ] && missing_vars+=("secrets.CF_DISTRIBUTION_ID")
# If any variables are missing, print them and exit with an error
if [ ${#missing_vars[@]} -ne 0 ]; then
echo "Error: The following required variables are missing:"
printf '%s\n' "${missing_vars[@]}"
exit 1
fi
shell: bash

- name: Building 🔧
working-directory: ./goes-plume-viewer
env:
REACT_APP_MAPBOX_TOKEN: ${{ secrets.REACT_APP_MAPBOX_ACCESS_TOKEN }}
REACT_APP_MAPBOX_STYLE_URL: ${{ secrets.REACT_APP_MAPBOX_STYLE_URL }}
PUBLIC_URL: ${{ vars.REACT_APP_BASE_PATH_GOES }}
REACT_APP_BASE_PATH: ${{ vars.REACT_APP_BASE_PATH_GOES }}
REACT_APP_STAC_API_URL: ${{ vars.REACT_APP_STAC_API_URL }}
REACT_APP_RASTER_API_URL: ${{ vars.REACT_APP_RASTER_API_URL }}
REACT_APP_CLOUD_BROWSE_URL: ${{ vars.REACT_APP_CLOUD_BROWSE_URL }}
run: |
yarn
CI=false yarn build
- name: Upload build folder
uses: actions/upload-artifact@v4
with:
name: build_folder
path: ./goes-plume-viewer/build

deploy:
name: Deploy GOES to ${{ needs.define-environment.outputs.env_name }} 🚀
needs:
- build
- define-environment
environment: ${{ needs.define-environment.outputs.env_name }}

permissions:
id-token: write
contents: read

runs-on: ubuntu-latest
steps:

- name: Checkout 🛎️
uses: actions/checkout@v4

- name: Download build folder
uses: actions/download-artifact@v4
with:
name: build_folder
path: ./goes-plume-viewer/build

- name: ConfigureAWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.DEPLOYMENT_ROLE_ARN }}
role-session-name: ${{ github.repository_owner}}
aws-region: us-west-2

- name: Upload to S3
run: |
aws s3 sync "./goes-plume-viewer/build" s3://${{ vars.DEPLOYMENT_BUCKET }}${{ vars.REACT_APP_BASE_PATH_GOES }} --cache-control max-age=30,must-revalidate,s-maxage=604800 --delete
env:
BASE_PATH: ${{ vars.REACT_APP_BASE_PATH_GOES }}

- name: Request Invalidation to AWS Cloudfront
uses: oneyedev/aws-cloudfront-invalidation@v1
with:
distribution-id: ${{ secrets.CF_DISTRIBUTION_ID }}
paths: |
/ghgcenter/custom-interfaces/*
82 changes: 28 additions & 54 deletions .github/workflows/deploy-nist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,33 @@ jobs:
- name: Install Yarn
run: npm install -g yarn

- name: Validate required variables and secrets
run: |
missing_vars=()
# Check for required variables
[ -z "${{ secrets.REACT_APP_MAPBOX_ACCESS_TOKEN }}" ] && missing_vars+=("secrets.REACT_APP_MAPBOX_ACCESS_TOKEN")
[ -z "${{ secrets.REACT_APP_MAPBOX_STYLE_URL }}" ] && missing_vars+=("secrets.REACT_APP_MAPBOX_STYLE_URL")
[ -z "${{ vars.REACT_APP_BASE_PATH_NIST }}" ] && missing_vars+=("vars.REACT_APP_BASE_PATH_NIST")
[ -z "${{ secrets.DEPLOYMENT_ROLE_ARN }}" ] && missing_vars+=("secrets.DEPLOYMENT_ROLE_ARN")
[ -z "${{ secrets.CF_DISTRIBUTION_ID }}" ] && missing_vars+=("secrets.CF_DISTRIBUTION_ID")
# If any variables are missing, print them and exit with an error
if [ ${#missing_vars[@]} -ne 0 ]; then
echo "Error: The following required variables are missing:"
printf '%s\n' "${missing_vars[@]}"
exit 1
fi
shell: bash

- name: Building 🔧
working-directory: ./nist-interface
env:
PUBLIC_URL: ${{ vars.REACT_APP_BASE_PATH_NIST }}
REACT_APP_MAPBOX_TOKEN: ${{ secrets.REACT_APP_MAPBOX_ACCESS_TOKEN }}
REACT_APP_MAPBOX_STYLE_URL: ${{ secrets.REACT_APP_MAPBOX_STYLE_URL }}
REACT_APP_FEATURES_API_URL: ${{ vars.FEATURES_API_URL }}
run: |
echo >> .env # add a new line to append the below variables
echo REACT_APP_MAPBOX_TOKEN="${{ secrets.REACT_APP_MAPBOX_ACCESS_TOKEN }}" >> .env
echo REACT_APP_MAPBOX_STYLE_URL="${{ secrets.REACT_APP_MAPBOX_STYLE_URL }}" >> .env
echo REACT_APP_BASE_PATH="${{ vars.REACT_APP_BASE_PATH_NIST }}" >> .env
yarn
yarn build
Expand All @@ -64,56 +84,12 @@ jobs:
name: build_folder
path: ./nist-interface/build

deploy-staging:
needs:
- build
- define-environment
if: github.ref == 'refs/heads/main'
environment: ${{ needs.define-environment.outputs.env_name }}

permissions:
id-token: write
contents: read

runs-on: ubuntu-latest
steps:

- name: Checkout 🛎️
uses: actions/checkout@v4

- name: Download build folder
uses: actions/download-artifact@v4
with:
name: build_folder
path: ./nist-interface/build

- name: ConfigureAWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.DEPLOYMENT_ROLE_ARN }}
role-session-name: ${{ github.repository_owner}}
aws-region: us-west-2

- name: Upload to S3
run: |
export BASE_PATH=${{ vars.REACT_APP_BASE_PATH_NIST }}
echo "BASE_PATH=${BASE_PATH}" >> $GITHUB_ENV
aws s3 sync "./nist-interface/build" s3://ghgc-custom-interfaces-staging${BASE_PATH}/ --cache-control max-age=30,must-revalidate,s-maxage=604800 --delete
env:
BASE_PATH: ${{ vars.REACT_APP_BASE_PATH_NIST }}

- name: Request Invalidation to AWS Cloudfront
uses: oneyedev/aws-cloudfront-invalidation@v1
with:
distribution-id: ${{ secrets.CF_DISTRIBUTION_ID }}
paths: |
${{ env.BASE_PATH }}*

deploy-production:
deploy:
name: Deploy NIST to ${{ needs.define-environment.outputs.env_name }} 🚀
needs:
- build
- define-environment
if: github.ref == 'refs/heads/production'
environment: ${{ needs.define-environment.outputs.env_name }}

permissions:
Expand Down Expand Up @@ -141,9 +117,7 @@ jobs:

- name: Upload to S3
run: |
export BASE_PATH=${{ vars.REACT_APP_BASE_PATH_NIST }}
echo "BASE_PATH=${BASE_PATH}" >> $GITHUB_ENV
aws s3 sync "./nist-interface/build" s3://ghgc-custom-interfaces-production${BASE_PATH}/ --cache-control max-age=30,must-revalidate,s-maxage=604800 --delete
aws s3 sync "./nist-interface/build" s3://${{ vars.DEPLOYMENT_BUCKET }}${{ vars.REACT_APP_BASE_PATH_NIST }} --cache-control max-age=30,must-revalidate,s-maxage=604800 --delete
env:
BASE_PATH: ${{ vars.REACT_APP_BASE_PATH_NIST }}

Expand All @@ -152,4 +126,4 @@ jobs:
with:
distribution-id: ${{ secrets.CF_DISTRIBUTION_ID }}
paths: |
${{ env.BASE_PATH }}*
/ghgcenter/custom-interfaces/*
Loading

0 comments on commit 41c7fd5

Please sign in to comment.