Skip to content

Commit

Permalink
Ghgc 141/task cicd for goes (#160)
Browse files Browse the repository at this point in the history
1. Added CICD workflow for GOES
2. Updated PR preview workflow to include GOES
  • Loading branch information
sanzog03 authored Nov 26, 2024
2 parents cc0f02b + e50e8d8 commit 5e2a6b5
Show file tree
Hide file tree
Showing 8 changed files with 191 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deploy-emit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ jobs:
with:
distribution-id: ${{ secrets.CF_DISTRIBUTION_ID }}
paths: |
/${{ env.PUBLIC_URL }}*
custom-interfaces/*
deploy-production:
needs:
Expand Down Expand Up @@ -145,4 +145,4 @@ jobs:
with:
distribution-id: ${{ secrets.CF_DISTRIBUTION_ID }}
paths: |
/${{ env.PUBLIC_URL }}*
/custom-interfaces/*
155 changes: 155 additions & 0 deletions .github/workflows/deploy-goes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
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/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: Building 🔧
working-directory: ./goes-plume-viewer
run: |
echo >> .env # add a new line to append the below variables
echo REACT_APP_MAPBOX_TOKEN="${{secrets.REACT_APP_MAPBOX_TOKEN}}" >> .env
echo REACT_APP_MAPBOX_STYLE_URL="${{vars.REACT_APP_MAPBOX_STYLE_URL}}" >> .env
echo REACT_APP_BASE_PATH="${{vars.REACT_APP_BASE_PATH_GOES}}" >> .env
yarn
CI=false yarn build
- name: Upload build folder
uses: actions/upload-artifact@v4
with:
name: build_folder
path: ./goes-plume-viewer/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: ./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: |
export BASE_PATH=${{ vars.REACT_APP_BASE_PATH_GOES }}
echo "BASE_PATH=${BASE_PATH}" >> $GITHUB_ENV
aws s3 sync "./goes-plume-viewer/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_GOES }}

- name: Request Invalidation to AWS Cloudfront
uses: oneyedev/aws-cloudfront-invalidation@v1
with:
distribution-id: ${{ secrets.CF_DISTRIBUTION_ID }}
paths: |
custom-interfaces/*
deploy-production:
needs:
- build
- define-environment
if: github.ref == 'refs/heads/production'
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: |
export BASE_PATH=${{ vars.REACT_APP_BASE_PATH_GOES }}
echo "BASE_PATH=${BASE_PATH}" >> $GITHUB_ENV
aws s3 sync "./goes-plume-viewer/build" s3://ghgc-custom-interfaces-production${BASE_PATH}/ --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: |
custom-interfaces/*
4 changes: 2 additions & 2 deletions .github/workflows/deploy-nist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ jobs:
with:
distribution-id: ${{ secrets.CF_DISTRIBUTION_ID }}
paths: |
${{ env.BASE_PATH }}*
custom-interfaces/*
deploy-production:
needs:
Expand Down Expand Up @@ -152,4 +152,4 @@ jobs:
with:
distribution-id: ${{ secrets.CF_DISTRIBUTION_ID }}
paths: |
${{ env.BASE_PATH }}*
custom-interfaces/*
4 changes: 2 additions & 2 deletions .github/workflows/deploy-noaa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ jobs:
with:
distribution-id: ${{ secrets.CF_DISTRIBUTION_ID }}
paths: |
/${{ env.PUBLIC_URL }}*
custom-interfaces/*
deploy-production:
needs:
Expand Down Expand Up @@ -154,4 +154,4 @@ jobs:
with:
distribution-id: ${{ secrets.CF_DISTRIBUTION_ID }}
paths: |
/${{ env.PUBLIC_URL }}*
custom-interfaces/*
4 changes: 2 additions & 2 deletions .github/workflows/deploy-urban.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ jobs:
with:
distribution-id: ${{ secrets.CF_DISTRIBUTION_ID }}
paths: |
${{ env.BASE_PATH }}*
custom-interfaces/*
deploy-production:
needs:
Expand Down Expand Up @@ -152,4 +152,4 @@ jobs:
with:
distribution-id: ${{ secrets.CF_DISTRIBUTION_ID }}
paths: |
${{ env.BASE_PATH }}*
custom-interfaces/*
25 changes: 25 additions & 0 deletions .github/workflows/pr-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
- 'emit-ch4plume-v1/**'
- 'noaa-cpfp-point/**'
- 'nist-interface/**'
- 'goes-plume-viewer/**'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down Expand Up @@ -58,6 +59,9 @@ jobs:
if grep -q 'nist-interface/' changed_files.txt; then
CHANGED_WEBSITES+=('nist-interface')
fi
if grep -q 'goes-plume-viewer/' changed_files.txt; then
CHANGED_WEBSITES+=('goes-plume-viewer')
fi
# Convert array to comma-separated string and set it as an environment variable
CHANGED_WEBSITES_STRING=$(IFS=, ; echo "${CHANGED_WEBSITES[*]}")
echo "CHANGED_WEBSITES=$CHANGED_WEBSITES_STRING" >> $GITHUB_ENV
Expand Down Expand Up @@ -116,6 +120,26 @@ jobs:
aws s3 sync nist-interface/build s3://${{ env.S3_BUCKET }}${NIST_PATH}
COMMENT+="- 🗼 nist-interface: https://${{ env.S3_BUCKET }}.s3.us-west-2.amazonaws.com${NIST_PATH}index.html"
elif [ "$WEBSITE" == "goes-plume-viewer" ]; then
GOES_PATH=$(echo "${{ vars.PUBLIC_URL_GOES }}/${{ env.PR_STRING }}" | sed -E 's|^https?://[^/]+||; s|/*$|/|')
echo >> ./goes-plume-viewer/.env # add a new line to append the below variables
echo REACT_APP_MAPBOX_TOKEN="${{secrets.REACT_APP_MAPBOX_TOKEN}}" >> ./goes-plume-viewer/.env
echo REACT_APP_MAPBOX_STYLE_URL="${{vars.REACT_APP_MAPBOX_STYLE_URL}}" >> ./goes-plume-viewer/.env
echo REACT_APP_BASE_PATH="${{vars.REACT_APP_BASE_PATH_GOES}}" >> ./goes-plume-viewer/.env
echo REACT_APP_PUBLIC_URL="${GOES_PATH}" >> ./goes-plume-viewer/.env
URL_VALUE=$(grep "REACT_APP_PUBLIC_URL" ./goes-plume-viewer/.env)
echo "The value of REACT_APP_PUBLIC_URL is: ${URL_VALUE}"
cd ./goes-plume-viewer
yarn
CI=false yarn build
cd ..
aws s3 sync goes-plume-viewer/build s3://${{ env.S3_BUCKET }}${GOES_PATH}
COMMENT+="- 🛰️ goes-plume-viewer: https://${{ env.S3_BUCKET }}.s3.us-west-2.amazonaws.com${GOES_PATH}index.html"
fi
echo "COMMENT=${COMMENT}" >> $GITHUB_ENV
done
Expand Down Expand Up @@ -157,6 +181,7 @@ jobs:
aws s3 rm s3://${{ env.S3_BUCKET }}${{ vars.PUBLIC_URL_EMIT }}/${{ env.PR_STRING }}/ --recursive
aws s3 rm s3://${{ env.S3_BUCKET }}${{ vars.PUBLIC_URL_NOAA }}/${{ env.PR_STRING }}/ --recursive
aws s3 rm s3://${{ env.S3_BUCKET }}${{ vars.PUBLIC_URL_NIST }}/${{ env.PR_STRING }}/ --recursive
aws s3 rm s3://${{ env.S3_BUCKET }}${{ vars.PUBLIC_URL_GOES }}/${{ env.PR_STRING }}/ --recursive
- name: Remove PR comment
run: |
Expand Down
3 changes: 3 additions & 0 deletions goes-plume-viewer/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
REACT_APP_STAC_API_URL="https://earth.gov/ghgcenter/api/stac"
REACT_APP_RASTER_API_URL="https://earth.gov/ghgcenter/api/raster"
REACT_APP_CLOUD_BROWSE_URL="https://data.ghg.center/browseui"
1 change: 0 additions & 1 deletion goes-plume-viewer/.env.local-sample
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
REACT_APP_MAPBOX_TOKEN='xxxxxxxxxx'
VITE_MAPBOX_TOKEN='xxxxxxxxxx'
REACT_APP_MAPBOX_STYLE_URL='mapbox://styles/xxxxxxxxx'
REACT_APP_STAC_API_URL='xxxxxxxxxx'
REACT_APP_RASTER_API_URL='xxxxxxxxxx'
Expand Down

0 comments on commit 5e2a6b5

Please sign in to comment.