Skip to content

Commit

Permalink
create upload_zip.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaryaz committed Feb 2, 2024
1 parent 618923e commit 37c9458
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 41 deletions.
48 changes: 7 additions & 41 deletions .github/workflows/deploy-lambdas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,69 +32,35 @@ jobs:
run: |
BUILDER_IMAGE=quiltdata/lambda:build-3.8
docker pull $BUILDER_IMAGE
docker pull "$BUILDER_IMAGE"
touch ./out.zip # 🤦‍♂️
touch ./out.zip
docker run --rm \
--entrypoint /build_zip.sh \
-v "$PWD/lambdas/${{ matrix.path }}":/lambda/function:z \
-v "$PWD/lambdas/shared":/lambda/shared:z \
-v "$PWD/out.zip":/out.zip:z \
-v "$PWD/lambdas/build_zip.sh":/build_zip.sh:z \
$BUILDER_IMAGE
"$BUILDER_IMAGE"
- name: Configure AWS credentials from Prod account
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::730278974607:role/github/GitHub-Quilt
aws-region: us-east-1
- name: Upload zips to Prod S3
run: |
primary_region=us-east-1
regions=$(aws ec2 describe-regions --query "Regions[].{Name:RegionName}" --output text)
lambda_name=$(basename "$(pwd)")
s3_key="$lambda_name/${{ github.sha }}.zip"
echo "Uploading to $primary_region..."
aws s3 cp --acl public-read ./out.zip "s3://quilt-lambda-$primary_region/$s3_key"
for region in $regions
do
if [ "$region" != "$primary_region" ]
then
echo "Copying to $region..."
aws s3 cp --acl public-read "s3://quilt-lambda-$primary_region/$s3_key" "s3://quilt-lambda-$region/$s3_key" --region "$region" --source-region "$primary_region"
fi
done
echo "Deployed $s3_key"
s3_key="$(basename "$PWD")/${{ github.sha }}.zip"
./lambdas/upload_zip.sh ./out.zip "$s3_key"
- name: Configure AWS credentials from GovCloud account
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws-us-gov:iam::313325871032:role/github/GitHub-Quilt
aws-region: us-gov-east-1
- name: Upload zips to GovCloud S3
run: |
primary_region=us-gov-east-1
regions=$(aws ec2 describe-regions --query "Regions[].{Name:RegionName}" --output text)
lambda_name=$(basename "$(pwd)")
s3_key="$lambda_name/${{ github.sha }}.zip"
echo "Uploading to $primary_region..."
aws s3 cp --acl public-read ./out.zip "s3://quilt-lambda-$primary_region/$s3_key"
for region in $regions
do
if [ "$region" != "$primary_region" ]
then
echo "Copying to $region..."
aws s3 cp --acl public-read "s3://quilt-lambda-$primary_region/$s3_key" "s3://quilt-lambda-$region/$s3_key" --region "$region" --source-region "$primary_region"
fi
done
echo "Deployed $s3_key"
s3_key="$(basename "$PWD")/${{ github.sha }}.zip"
./lambdas/upload_zip.sh ./out.zip "$s3_key"
deploy-lambda-ecr:
strategy:
Expand Down
31 changes: 31 additions & 0 deletions lambdas/upload_zip.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

set -e

error() {
echo $@ 2>&1
exit 1
}

[[ $# == 2 ]] || error "Usage: $0 zip_file s3_key"

zip_file=$1
s3_key=$2

primary_region=$(aws configure get region)
regions=$(aws ec2 describe-regions --query "Regions[].{Name:RegionName}" --output text)

echo "Uploading to $primary_region..."
aws s3 cp --acl public-read "$zip_file" --region "$primary_region" "s3://quilt-lambda-$primary_region/$s3_key"

for region in $regions
do
if [[ $region != $primary_region ]]
then
echo "Copying to $region..."
aws s3 cp --acl public-read \
"s3://quilt-lambda-$primary_region/$s3_key" --source-region "$primary_region" \
"s3://quilt-lambda-$region/$s3_key" --region "$region"
fi
done

0 comments on commit 37c9458

Please sign in to comment.