deploy #28
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 | |
permissions: | |
id-token: write # required for requesting the JWT | |
contents: read # required for actions/checkout | |
on: | |
workflow_dispatch: | |
inputs: | |
deployment_environment: | |
description: 'environment (either dev or test)' | |
required: true | |
api_version: | |
description: 'federated collection discovery API version - must be in this [list of tags](https://github.com/developmentseed/federated-collection-discovery/tags)' | |
required: true | |
default: '0.1.1' | |
jobs: | |
build_and_deploy: | |
runs-on: ubuntu-latest | |
environment: "${{ github.event.inputs.deployment_environment }}" | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Checkout client repository | |
uses: actions/checkout@v4 | |
with: | |
repository: developmentseed/federated-collection-discovery | |
path: client_app | |
sparse-checkout: src/client | |
ref: "${{ github.event.inputs.api_version }}" | |
- name: Set up node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 22 | |
- name: Cache Node.js dependencies | |
uses: actions/cache@v4 | |
with: | |
path: node_modules | |
key: node-modules-${{ runner.os }}-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
node-modules-${{ runner.os }}- | |
- name: Cache Yarn dependencies | |
uses: actions/cache@v4 | |
with: | |
path: | | |
client_app/src/client/node_modules | |
client_app/src/client/.yarn | |
key: yarn-cache-${{ runner.os }}-${{ hashFiles('client_app/src/client/yarn.lock') }} | |
restore-keys: | | |
yarn-cache-${{ runner.os }}- | |
- name: Install Yarn | |
run: npm install -g yarn | |
- name: Install Poetry | |
uses: Gr1N/setup-poetry@v9 | |
with: | |
poetry-version: "1.8.0" | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.12" | |
cache: poetry | |
cache-dependency-path: poetry.lock | |
- name: Assume Github OIDC role | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-region: us-west-2 | |
role-to-assume: ${{ vars.DEPLOY_ROLE }} | |
role-session-name: federated-collection-discovery-${{ github.event.inputs.deployment_environment }}-deploy | |
- name: Install deployment dependencies | |
run: | | |
npm install | |
poetry install | |
cd client_app/src/client | |
yarn install | |
- name: Run CDK deploy | |
env: | |
STAGE: "${{ github.event.inputs.deployment_environment }}" | |
API_VERSION: "${{ github.event.inputs.api_version }}" | |
API_CERTIFICATE_ARN: "${{ vars.API_CERTIFICATE_ARN }}" | |
API_DOMAIN_NAME: "${{ vars.API_DOMAIN_NAME }}" | |
CLIENT_CERTIFICATE_ARN: "${{ vars.CLIENT_CERTIFICATE_ARN }}" | |
CLIENT_DOMAIN_NAME: "${{ vars.CLIENT_DOMAIN_NAME }}" | |
STAC_API_URLS: ${{ vars.STAC_API_URLS }} | |
run: | | |
start_time=$(date +%s) | |
poetry run npx cdk deploy --all --require-approval never --outputs-file cdk-output.json | |
status=$? | |
end_time=$(date +%s) | |
duration=$((end_time - start_time)) | |
echo "success=${status}" >> $GITHUB_ENV | |
echo "duration=${duration}" >> $GITHUB_ENV | |
if [ $status -eq 0 ]; then | |
echo "CDK deploy successful." | |
else | |
echo "CDK deploy failed." >&2 | |
exit 1 | |
fi | |
export STACK_NAME=$(jq -r 'keys_unsorted[0]' cdk-output.json) | |
export REACT_APP_API_URL=$(jq -r --arg stack_name "$STACK_NAME" '.[$stack_name].ApiEndpoint' cdk-output.json) | |
echo "REACT_APP_API_URL=$REACT_APP_API_URL" >> $GITHUB_ENV | |
export BUCKET_NAME=$(jq -r --arg stack_name "$STACK_NAME" '.[$stack_name].ClientBucketName' cdk-output.json) | |
echo "BUCKET_NAME=$BUCKET_NAME" >> $GITHUB_ENV | |
export DISTRIBUTION_ID=$(jq -r --arg stack_name "$STACK_NAME" '.[$stack_name].CloudFrontId' cdk-output.json) | |
echo "DISTRIBUTION_ID=$DISTRIBUTION_ID" >> $GITHUB_ENV | |
- name: Build and deploy client app | |
working-directory: client_app/src/client | |
run: | | |
yarn build | |
aws s3 sync ./build s3://${BUCKET_NAME} | |
# invalidate existing index.html to refresh the site | |
aws cloudfront create-invalidation --distribution-id ${DISTRIBUTION_ID} --paths "/*" | |
- name: Upload cdk-output.json | |
uses: actions/upload-artifact@v4 | |
with: | |
name: cdk-output.json | |
path: cdk-output.json |