Skip to content

Commit 8280b7e

Browse files
authored
Merge pull request #28 from aws-samples/dev
update pipeline to publish OCI images to ECR public repo
2 parents defdf03 + 8982937 commit 8280b7e

File tree

2 files changed

+76
-26
lines changed

2 files changed

+76
-26
lines changed

.github/workflows/pipeline.yaml

Lines changed: 62 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ env:
2323
BETA_ARTIFACTS_BUCKET: aws-sam-cli-managed-beta-pipeline-artifactsbucket-889nlo0z1nt0
2424
BETA_IMAGE_REPOSITORY: 477159140107.dkr.ecr.ap-northeast-1.amazonaws.com/aws-sam-cli-managed-beta-pipeline-resources-imagerepository-0hbn3hxi9pcm
2525
BETA_REGION: ap-northeast-1
26+
PROD_ECR_PIPELINE_EXECUTION_ROLE: arn:aws:iam::373534280245:role/aws-sam-cli-managed-prod-ecr-PipelineExecutionRole-12FE9QIHNFYOI
27+
PROD_ECR_CLOUDFORMATION_EXECUTION_ROLE: arn:aws:iam::373534280245:role/aws-sam-cli-managed-prod-CloudFormationExecutionR-RDUT9EAJJ1ZN
28+
PROD_ARTIFACTS_BUCKET: aws-sam-cli-managed-prod-ecr-pipe-artifactsbucket-1mjporc66dkgn
29+
PROD_IMAGE_REPOSITORY: 373534280245.dkr.ecr.us-east-1.amazonaws.com/aws-sam-cli-managed-prod-ecr-pipeline-resources-imagerepository-fhpoty0tapro
30+
PROD_ECR_REGION: us-east-1
2631

2732
jobs:
2833
test:
@@ -34,30 +39,14 @@ jobs:
3439
toolchain: stable
3540
components: clippy
3641
- name: linting
37-
run: cargo fmt -- --check && cargo clippy -- -Dwarnings
42+
run: |
43+
cargo fmt -- --check
44+
cargo clippy -- -Dwarnings
3845
- run: cargo test
3946

40-
load-gamma-matrix:
41-
needs: [ test ]
42-
runs-on: ubuntu-latest
43-
outputs:
44-
matrix: ${{ steps.set-matrix.outputs.matrix }}
45-
steps:
46-
- uses: actions/checkout@v2
47-
- id: set-matrix
48-
run: echo "::set-output name=matrix::{\"include\":$(jq -r tostring .github/workflows/gamma.json)}"
49-
50-
load-prod-matrix:
51-
needs: [ test ]
52-
runs-on: ubuntu-latest
53-
outputs:
54-
matrix: ${{ steps.set-matrix.outputs.matrix }}
55-
steps:
56-
- uses: actions/checkout@v2
57-
- id: set-matrix
58-
run: echo "::set-output name=matrix::{\"include\":$(jq -r tostring .github/workflows/prod.json)}"
5947

6048
build:
49+
if: ${{ github.ref == 'refs/heads/main' || github.event_name == 'release' }}
6150
needs: [test]
6251
runs-on: ubuntu-latest
6352
steps:
@@ -81,8 +70,30 @@ jobs:
8170
name: aws-sam-build-arm64
8271
path: build-arm64
8372

73+
load-gamma-matrix:
74+
if: ${{ github.ref == 'refs/heads/main' || github.event_name == 'release' }}
75+
needs: [ test ]
76+
runs-on: ubuntu-latest
77+
outputs:
78+
matrix: ${{ steps.set-matrix.outputs.matrix }}
79+
steps:
80+
- uses: actions/checkout@v2
81+
- id: set-matrix
82+
run: echo "::set-output name=matrix::{\"include\":$(jq -r tostring .github/workflows/gamma.json)}"
83+
84+
load-prod-matrix:
85+
if: ${{ github.ref == 'refs/heads/main' || github.event_name == 'release' }}
86+
needs: [ test ]
87+
runs-on: ubuntu-latest
88+
outputs:
89+
matrix: ${{ steps.set-matrix.outputs.matrix }}
90+
steps:
91+
- uses: actions/checkout@v2
92+
- id: set-matrix
93+
run: echo "::set-output name=matrix::{\"include\":$(jq -r tostring .github/workflows/prod.json)}"
8494

8595
package-beta:
96+
if: ${{ github.ref == 'refs/heads/main' || github.event_name == 'release' }}
8697
needs: [ build ]
8798
runs-on: ubuntu-latest
8899
steps:
@@ -141,6 +152,7 @@ jobs:
141152

142153

143154
package-gamma:
155+
if: ${{ github.ref == 'refs/heads/main' || github.event_name == 'release' }}
144156
needs: [ build, load-gamma-matrix ]
145157
runs-on: ubuntu-latest
146158
strategy:
@@ -200,6 +212,7 @@ jobs:
200212
path: packaged-gamma-arm64-${{ matrix.region }}.yaml
201213

202214
package-prod:
215+
if: ${{ github.ref == 'refs/heads/main' || github.event_name == 'release' }}
203216
needs: [ build, load-prod-matrix ]
204217
runs-on: ubuntu-latest
205218
strategy:
@@ -259,6 +272,7 @@ jobs:
259272
path: packaged-prod-arm64-${{ matrix.region }}.yaml
260273

261274
deploy-beta:
275+
if: ${{ github.ref == 'refs/heads/main' || github.event_name == 'release' }}
262276
needs: [package-beta, package-gamma, package-prod]
263277
runs-on: ubuntu-latest
264278
steps:
@@ -308,6 +322,7 @@ jobs:
308322
--role-arn ${BETA_CLOUDFORMATION_EXECUTION_ROLE}
309323
310324
integration-test:
325+
if: ${{ github.ref == 'refs/heads/main' || github.event_name == 'release' }}
311326
needs: [deploy-beta]
312327
runs-on: ubuntu-latest
313328
steps:
@@ -443,3 +458,30 @@ jobs:
443458
--image-repository ${{ matrix.image_repository }} \
444459
--no-fail-on-empty-changeset \
445460
--role-arn ${{ matrix.cloudformation_execution_role }}
461+
462+
publish-to-public-ecr:
463+
if: ${{ github.event_name == 'release' }}
464+
needs: [deploy-prod]
465+
runs-on: ubuntu-latest
466+
steps:
467+
- uses: actions/checkout@v2
468+
469+
- name: Assume the prod pipeline user role
470+
uses: aws-actions/configure-aws-credentials@v1
471+
with:
472+
aws-access-key-id: ${{ env.PIPELINE_USER_ACCESS_KEY_ID }}
473+
aws-secret-access-key: ${{ env.PIPELINE_USER_SECRET_ACCESS_KEY }}
474+
aws-region: ${{ env.PROD_ECR_REGION }}
475+
role-to-assume: ${{ env.PROD_ECR_PIPELINE_EXECUTION_ROLE }}
476+
role-session-name: prod-deployment
477+
role-duration-seconds: 3600
478+
role-skip-session-tagging: true
479+
480+
- name: build OCI images for x86_64 and aarch64
481+
run: |
482+
make build-x86
483+
make build-arm
484+
485+
- name: publish OCI images to ECR public repository
486+
run: |
487+
make publish

Makefile

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
1+
CARGO_PKG_VERSION := $(shell cargo metadata --no-deps --format-version=1 | jq -r '.packages[0].version')
2+
13
clean:
24
rm -rf target
35

46
build-x86:
5-
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws
6-
DOCKER_BUILDKIT=1 docker build --build-arg ARCH=x86_64 -t aws-lambda-adapter:latest-x86_64 .
7+
DOCKER_BUILDKIT=1 docker build --build-arg ARCH=x86_64 -t public.ecr.aws/awsguru/aws-lambda-adapter:$(CARGO_PKG_VERSION)-x86_64 .
78

89
build-arm:
9-
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws
10-
DOCKER_BUILDKIT=1 docker build --build-arg ARCH=aarch64 -t aws-lambda-adapter:latest-aarch64 .
10+
DOCKER_BUILDKIT=1 docker build --build-arg ARCH=aarch64 -t public.ecr.aws/awsguru/aws-lambda-adapter:$(CARGO_PKG_VERSION)-aarch64 .
1111

1212
build: build-x86 build-arm
13-
docker tag aws-lambda-adapter:latest-x86_64 aws-lambda-adapter:latest
13+
docker push public.ecr.aws/awsguru/aws-lambda-adapter:$(CARGO_PKG_VERSION)-x86_64
14+
docker push public.ecr.aws/awsguru/aws-lambda-adapter:$(CARGO_PKG_VERSION)-aarch64
15+
docker manifest create public.ecr.aws/awsguru/aws-lambda-adapter:$(CARGO_PKG_VERSION) \
16+
public.ecr.aws/awsguru/aws-lambda-adapter:$(CARGO_PKG_VERSION)-x86_64 \
17+
public.ecr.aws/awsguru/aws-lambda-adapter:$(CARGO_PKG_VERSION)-aarch64
18+
docker manifest annotate --arch arm64 public.ecr.aws/awsguru/aws-lambda-adapter:$(CARGO_PKG_VERSION) \
19+
public.ecr.aws/awsguru/aws-lambda-adapter:$(CARGO_PKG_VERSION)-aarch64
20+
21+
publish: build
22+
docker manifest push public.ecr.aws/awsguru/aws-lambda-adapter:$(CARGO_PKG_VERSION)
1423

1524
build-mac:
1625
CC=x86_64-unknown-linux-musl-gcc cargo build --release --target=x86_64-unknown-linux-musl
17-
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws
1826
DOCKER_BUILDKIT=1 docker build -f Dockerfile.mac --build-arg ARCH=x86_64 -t aws-lambda-adapter:latest .
1927

2028
build-LambdaAdapterLayerX86:

0 commit comments

Comments
 (0)