From 5ddff6f4fc54cc1423ebb649415d324fc5526a5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0t=C4=9Bp=C3=A1n=20Brychta?= Date: Wed, 3 Jul 2024 15:52:28 +0100 Subject: [PATCH] Create a GitHub action to deploy the ingest inspector (#1130) --- .github/workflows/deploy-ingest-inspector.yml | 30 ++++++++++++++++ builds/deploy_lambda_zip.sh | 36 +++++++++++++++++++ monitoring/ingest_inspector/README.md | 2 +- .../ingest_inspector/frontend/deploy.sh | 5 ++- 4 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/deploy-ingest-inspector.yml create mode 100755 builds/deploy_lambda_zip.sh diff --git a/.github/workflows/deploy-ingest-inspector.yml b/.github/workflows/deploy-ingest-inspector.yml new file mode 100644 index 000000000..6334a9d5c --- /dev/null +++ b/.github/workflows/deploy-ingest-inspector.yml @@ -0,0 +1,30 @@ +name: Deploy Ingest Inspector +on: + push +# push: +# branches: +# - main + +permissions: + id-token: write + +jobs: + deploy_ingest_inspector: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: aws-actions/configure-aws-credentials@v4 + with: + aws-region: eu-west-1 + role-to-assume: ${{ secrets.DEPLOY_INGEST_INSPECTOR_GHA_ROLE_ARN }} + - name: Deploy Ingest Inspector backend + run: | + pip3 install boto3 docopt + python3 ./builds/publish_lambda_zip.py monitoring/ingest_inspector/backend_lambda \ + --bucket=wellcomecollection-storage-infra \ + --key=lambdas/monitoring/ingest_inspector_backend.zip + ./builds/deploy_lambda_zip.sh monitoring/ingest_inspector_backend ingest_inspector_backend + - name: Deploy Ingest Inspector frontend + run: | + cd monitoring/ingest_inspector/frontend + sh deploy.sh diff --git a/builds/deploy_lambda_zip.sh b/builds/deploy_lambda_zip.sh new file mode 100755 index 000000000..76fa22ae7 --- /dev/null +++ b/builds/deploy_lambda_zip.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +# Usage: ./deploy_lambda_zip.sh +# Example: ./deploy_lambda_zip.sh monitoring/ingest_inspector_backend ingest_inspector_backend + +set -o errexit +set -o nounset +set -o pipefail + +PROJECT_NAME=$1 +LAMBDA_NAME=$2 + +S3_BUCKET="wellcomecollection-storage-infra" +S3_KEY="lambdas/$PROJECT_NAME.zip" + +echo "Identifying function: $LAMBDA_NAME" +FUNCTION_ARN=$(aws lambda get-function-configuration \ + --function-name $LAMBDA_NAME \ + --query "FunctionArn" \ + --output text) + +echo "Updating function: $FUNCTION_ARN from s3://$S3_BUCKET/$S3_KEY" +REVISION_ID=$(aws lambda update-function-code \ + --function-name $LAMBDA_NAME \ + --s3-bucket $S3_BUCKET \ + --s3-key $S3_KEY \ + --query "RevisionId" \ + --output text) + +echo "Revision id: $REVISION_ID" + +echo "Awaiting function update" +aws lambda wait function-updated \ + --function-name $LAMBDA_NAME + +echo "Done" diff --git a/monitoring/ingest_inspector/README.md b/monitoring/ingest_inspector/README.md index b8b17613a..32a18f431 100644 --- a/monitoring/ingest_inspector/README.md +++ b/monitoring/ingest_inspector/README.md @@ -164,6 +164,6 @@ The frontend is hosted as a static website on S3 and served via CloudFront. To b the `ingest_inspector/frontend` directory and run: ```shell -sh deploy.sh +AWS_PROFILE=storage-developer sh deploy.sh ``` diff --git a/monitoring/ingest_inspector/frontend/deploy.sh b/monitoring/ingest_inspector/frontend/deploy.sh index 0b52e6aef..349f46e9c 100644 --- a/monitoring/ingest_inspector/frontend/deploy.sh +++ b/monitoring/ingest_inspector/frontend/deploy.sh @@ -1,5 +1,8 @@ #!/bin/sh +echo "Installing packages..." +npm install + echo "Building app..." npm run build @@ -9,7 +12,7 @@ if [ $? -ne 0 ]; then fi echo "Uploading to S3..." -AWS_PROFILE=storage-developer aws s3 cp out s3://wellcomecollection-ingest-inspector-frontend --recursive --only-show-errors +aws s3 cp out s3://wellcomecollection-ingest-inspector-frontend --recursive --only-show-errors if [ $? -eq 0 ]; then echo "Success!"