Skip to content

Commit

Permalink
test ecr
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaryaz committed Feb 2, 2024
1 parent c9eeac2 commit c4d82a4
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 16 deletions.
62 changes: 46 additions & 16 deletions .github/workflows/deploy-lambdas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
push:
branches:
- ci_deploy_lambdas
paths:
# - '.github/workflows/deploy-lambdas.yml'
- 'lambdas/**'

jobs:
deploy-lambda-s3:
Expand All @@ -30,47 +33,74 @@ jobs:
- uses: actions/checkout@v4
- name: Build zip
run: |
BUILDER_IMAGE=quiltdata/lambda:build-3.8
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"
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"
- 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: |
s3_key="$(basename ${{ matrix.path }})/${{ github.sha }}.zip"
./lambdas/upload_zip.sh ./out.zip "$AWS_REGION" "$s3_key"
s3_key="$(basename ${{ matrix.path }})/${{ github.sha }}.zip"
./lambdas/upload_zip.sh ./out.zip "$AWS_REGION" "$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: |
s3_key="$(basename ${{ matrix.path }})/${{ github.sha }}.zip"
./lambdas/upload_zip.sh ./out.zip "$AWS_REGION" "$s3_key"
s3_key="$(basename ${{ matrix.path }})/${{ github.sha }}.zip"
./lambdas/upload_zip.sh ./out.zip "$AWS_REGION" "$s3_key"
deploy-lambda-ecr:
strategy:
matrix:
path:
- molecule
- thumbnail
# - thumbnail
runs-on: ubuntu-latest
# These permissions are needed to interact with GitHub's OIDC Token endpoint.
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v4
- name: Build Docker image
working-directory: ./lambdas/${{ matrix.path }}
run: |
echo TODO
image_name=quiltdata/lambdas/${{ matrix.path }}:${{ github.sha }}
docker buildx build --pull --platform=linux/amd64 -t "$image_name" -f Dockerfile ..
- 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: Login to Prod ECR
id: login-prod-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Push Docker image to Prod ECR
run: ./lambdas/upload_ecr.sh 730278974607 quiltdata/lambdas/${{ matrix.path }}:${{ github.sha }}
- 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: Login to GovCloud ECR
id: login-govcloud-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Push Docker image to GovCloud ECR
run: ./lambdas/upload_ecr.sh 313325871032 quiltdata/lambdas/${{ matrix.path }}:${{ github.sha }}

28 changes: 28 additions & 0 deletions lambdas/upload_ecr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

set -e

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

[[ $# == 2 ]] || error "Usage: $0 account_id image_name"

account_id=$1
image_name=$2

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

for region in $regions
do
docker_url=$account_id.dkr.ecr.$region.amazonaws.com
echo "Logging in to $docker_url..."
aws ecr get-login-password --region $region | docker login -u AWS --password-stdin "$docker_url"

echo "Pushing to $region..."
remote_image_name="$docker_url/$image_name"
docker tag "$image_name" "$remote_image_name"
docker push "$remote_image_name"
done

0 comments on commit c4d82a4

Please sign in to comment.