Skip to content

Commit 89b2ebe

Browse files
authored
chore: federate into AWS to authenticate to ECR Public (#3679)
In order to reduce throttlin events, federate into AWS using the GitHub OpenID Connect provider, and authenticate to ECR Public. When no `AWS_ROLE_TO_ASSUME` secret is configured, federation is skipped and the jitter is applied instead. Also reduces parallelism of the `buildx` OCI provider so that we can more reliably re-use layer caches across all platforms without choking the runner's IO.
1 parent 30eded9 commit 89b2ebe

File tree

1 file changed

+47
-21
lines changed

1 file changed

+47
-21
lines changed

.github/workflows/docker-images.yml

+47-21
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,48 @@ jobs:
4545
echo '⏯ Dockerfile changed'
4646
echo "::set-output name=result::true"
4747
else
48-
echo '⏭ Dockerfile not changed'
49-
echo "::set-output name=result::false"
48+
if grep '.github/workflows/docker-images.yml' <<< "${changed}" ; then
49+
echo '⏯ docker-images workflow changed'
50+
echo "::set-output name=result::true"
51+
else
52+
echo '⏭ Dockerfile not changed'
53+
echo "::set-output name=result::false"
54+
fi
5055
fi
5156
fi
5257
58+
# Check if federation into AWS is configured. This is necessary because
59+
# GitHub does not interpret ${{ secret.FOO }} within `if:` conditions...
60+
# See: https://github.com/actions/runner/issues/520
61+
- name: Check AWS federation configuration
62+
id: federate_to_aws
63+
if: steps.should-run.outputs.result == 'true'
64+
run: |-
65+
if [[ "${{ secrets.AWS_ROLE_TO_ASSUME }}" != "" ]]; then
66+
echo "🔑 Federation into AWS is possible (AWS_ROLE_TO_ASSUME is available)"
67+
echo "::set-output name=enabled::true"
68+
else
69+
echo "❌ Federation into AWS is disabled (no AWS_ROLE_TO_ASSUME secret found)"
70+
echo "::set-output name=enabled::false"
71+
fi
72+
73+
# Federate into the PR Validation AWS Account
74+
- name: Federate into AWS
75+
if: steps.should-run.outputs.result == 'true' && steps.federate_to_aws.outputs.enabled == 'true'
76+
uses: aws-actions/configure-aws-credentials@v1
77+
with:
78+
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
79+
aws-region: us-east-1
80+
81+
# Login to ECR Public registry, so we don't get throttled at 1 TPS
82+
- name: Login to ECR Public
83+
if: steps.should-run.outputs.result == 'true' && steps.federate_to_aws.outputs.enabled == 'true'
84+
run: |-
85+
aws ecr-public get-login-password --region=us-east-1 \
86+
| docker login --username AWS --password-stdin public.ecr.aws
87+
5388
# We only authenticate to Docker on the 'aws/jsii' repo, as forks will not have the secret
54-
- name: Login to Docker
89+
- name: Login to Docker Hub
5590
if: steps.should-run.outputs.result == 'true' && github.repository == 'aws/jsii'
5691
# The DOCKER_CREDENTIALS secret is expected to contain a username:token pair
5792
run: |-
@@ -70,6 +105,12 @@ jobs:
70105
id: buildx
71106
if: steps.should-run.outputs.result == 'true'
72107
uses: docker/setup-buildx-action@v2
108+
with:
109+
# Disable parallelism because IO contention makes it too slow on GitHub
110+
# workers...
111+
config-inline: |-
112+
[worker.oci]
113+
max-parallelism = 1
73114
74115
# We only restore GH cache if we are not going to publish the result (i.e: PR validation)
75116
- name: Set up layer cache
@@ -85,7 +126,7 @@ jobs:
85126
# 1 pull per second from ECR Public
86127
- name: Jitter the start time to avoid ECR Public throttling
87128
id: sleep-start
88-
if: steps.should-run.outputs.result == 'true'
129+
if: steps.should-run.outputs.result == 'true' && steps.federate_to_aws.outputs.enabled != true
89130
run: |-
90131
sleep $((RANDOM % 60))
91132
@@ -111,27 +152,12 @@ jobs:
111152
-f superchain/Dockerfile \
112153
.
113154
114-
# Testing sequentially, because in parallel it's too slow due to IO contention
115-
- name: Test Image (AMD64)
116-
if: steps.should-run.outputs.result == 'true'
117-
run: |-
118-
docker buildx build \
119-
--builder ${{ steps.buildx.outputs.name }} \
120-
--platform linux/amd64 \
121-
--target superchain \
122-
--cache-from type=local,src=/tmp/.buildx-cache \
123-
--cache-to type=local,dest=/tmp/.buildx-cache \
124-
--build-arg BUILD_TIMESTAMP="${{ steps.build-time.outputs.value }}" \
125-
--build-arg COMMIT_ID='${{ github.sha }}' \
126-
--build-arg NODE_MAJOR_VERSION=${{ matrix.node }} \
127-
-f superchain/Dockerfile \
128-
.
129-
- name: Test Image (ARM64)
155+
- name: Test Image
130156
if: steps.should-run.outputs.result == 'true'
131157
run: |-
132158
docker buildx build \
133159
--builder ${{ steps.buildx.outputs.name }} \
134-
--platform linux/arm64 \
160+
--platform linux/amd64,linux/arm64 \
135161
--target superchain \
136162
--cache-from type=local,src=/tmp/.buildx-cache \
137163
--cache-to type=local,dest=/tmp/.buildx-cache \

0 commit comments

Comments
 (0)