Repository navigation
220 lines (199 loc) · 9 KB
/
Copy pathbuild-image.yml
File metadata and controls
220 lines (199 loc) · 9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# Builds the nodejs26.x mainline runtime image for arm64 and amd64, each on its own CodeBuild-hosted
# runner, and runs the smoke and security tests through the Runtime Interface Emulator. On a push it
# also pushes each image to ECR, tagged <commit>-<arch>, as the role that the deploy environment's
# OIDC token may assume.
#
# The CodeBuild label names the runner project; the extra labels override its instance size.
# The jobs are named build-<arch>, the status check names the main branch's ruleset requires.
# Repository variables:
# REGISTRY_MIRROR optional: an ECR pull-through cache of public.ecr.aws for the builder and
# base images (see build.sh). The runner's CodeBuild role pulls from it.
# NPM_REGISTRY optional: the URL of a CodeArtifact npm repository to install the npm
# packages from instead of the public registry. The runner's CodeBuild role
# gets its token.
name: Build runtime image
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
permissions: {}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name != 'push' }}
env:
ECR_REPOSITORY: aws-lambda-nodejs-runtime
jobs:
build:
name: build-${{ matrix.arch }}
strategy:
# A cancelled job shows as a failed check, so one architecture's failure does not cancel
# the other.
fail-fast: false
matrix:
include:
- arch: arm64
project: project-aws-aws-lambda-nodejs-runtime-arm64
lambda_arch: arm64
- arch: amd64
project: project-aws-aws-lambda-nodejs-runtime-x86
lambda_arch: x86_64
runs-on:
- codebuild-${{ matrix.project }}-${{ github.run_id }}-${{ github.run_attempt }}
- instance-size:2xlarge
timeout-minutes: 120
environment: ${{ github.event_name == 'push' && 'deploy' || '' }}
# id-token lets the push steps request the OIDC token the ECR role trusts.
permissions:
contents: read
id-token: write
env:
BUILDKIT_PROGRESS: plain
ARCH: ${{ matrix.arch }}
IMAGE: lambda-runtime/image:nodejs26.x-mainline-${{ matrix.arch }}
FUNCTION_NAME: nodejs-runtime-integ-${{ matrix.arch }}
IMAGE_TAG: integ-${{ matrix.arch }}-${{ github.run_id }}-${{ github.run_attempt }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
# build.sh writes to the containerd image store and later builds read those images back
# as build contexts, which the classic image store cannot do.
- name: Use the containerd image store
run: |
if docker info -f '{{ .DriverStatus }}' | grep -q io.containerd.snapshotter; then exit 0; fi
mkdir -p /etc/docker
echo '{"features":{"containerd-snapshotter":true}}' > /etc/docker/daemon.json
pkill dockerd || true
while pgrep -x dockerd > /dev/null; do sleep 1; done
nohup dockerd > /tmp/dockerd.log 2>&1 &
for attempt in $(seq 60); do docker info > /dev/null 2>&1 && break; sleep 1; done
docker info -f '{{ .DriverStatus }}' | grep io.containerd.snapshotter
docker version
docker buildx version
- name: Log in to the registry mirror
if: vars.REGISTRY_MIRROR != ''
env:
REGISTRY_MIRROR: ${{ vars.REGISTRY_MIRROR }}
run: aws ecr get-login-password | docker login --username AWS --password-stdin "${REGISTRY_MIRROR%%/*}"
# The token is written to an npm config file in the job's temporary directory, which
# build.sh passes to the build as a secret.
- name: Configure the npm registry
if: vars.NPM_REGISTRY != ''
env:
NPM_REGISTRY: ${{ vars.NPM_REGISTRY }}
run: |
host=${NPM_REGISTRY#https://}
host=${host%%/*}
domain_and_owner=${host%%.d.codeartifact.*}
owner=${domain_and_owner##*-}
domain=${domain_and_owner%-*}
token=$(aws codeartifact get-authorization-token --domain "$domain" --domain-owner "$owner" \
--query authorizationToken --output text)
echo "::add-mask::$token"
npmrc="$RUNNER_TEMP/npmrc"
umask 077
printf 'registry=%s\n%s:_authToken=%s\n' "$NPM_REGISTRY" "${NPM_REGISTRY#https:}" "$token" > "$npmrc"
echo "NPMRC=$npmrc" >> "$GITHUB_ENV"
- name: Build the image
env:
REGISTRY_MIRROR: ${{ vars.REGISTRY_MIRROR }}
run: |
if [ -n "${REGISTRY_MIRROR:-}" ]; then
export BUILD_CACHE_REF="${REGISTRY_MIRROR%%/*}/aws-lambda-nodejs-runtime-buildcache"
fi
./build.sh 26 "linux/$ARCH"
- name: Smoke-test the image
run: node test/run.mjs "$IMAGE" "linux/$ARCH"
- name: Security-test the image
run: node test/run.mjs "$IMAGE" "linux/$ARCH" test/security-cases.json
- name: Configure AWS credentials (integration test)
if: github.event_name == 'push'
uses: aws-actions/configure-aws-credentials@e1253824e5c10ff9df46874f81ed3ec929e19cfd # v6.3.0
with:
role-to-assume: ${{ secrets.AWS_INTEGRATION_ROLE_ARN }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Log in to Amazon ECR (integration test)
if: github.event_name == 'push'
id: login-ecr-integ
uses: aws-actions/amazon-ecr-login@7290e214a610b32bc0eef81748948b6d466a8783 # v2.2.0
- name: Build and push the hello-world test image
if: github.event_name == 'push'
id: integ-build
env:
ECR_REGISTRY: ${{ steps.login-ecr-integ.outputs.registry }}
INTEG_ECR_REPOSITORY: ${{ secrets.INTEG_ECR_REPOSITORY }}
run: |
set -euo pipefail
image="${ECR_REGISTRY}/${INTEG_ECR_REPOSITORY}:${IMAGE_TAG}"
# Layer the hello-world handler onto the image just built locally. Single-platform and
# no attestations: Lambda needs a Docker media-type manifest, not an OCI image index.
docker buildx build \
--platform "linux/${ARCH}" \
--provenance=false --sbom=false \
--build-arg "RUNTIME_IMAGE=${IMAGE}" \
--tag "$image" \
--push \
test/integration
echo "image_uri=${image}" >> "$GITHUB_OUTPUT"
- name: Deploy the test Lambda function
if: github.event_name == 'push'
uses: aws-actions/aws-lambda-deploy@d496277188b89f0be02d7a2216fc912c0427702a # v1.1.2
with:
function-name: ${{ env.FUNCTION_NAME }}
package-type: Image
image-uri: ${{ steps.integ-build.outputs.image_uri }}
role: ${{ secrets.AWS_LAMBDA_EXEC_ROLE_ARN }}
architectures: ${{ matrix.lambda_arch }}
memory-size: 256
timeout: 30
- name: Invoke the test function and assert 200
if: github.event_name == 'push'
working-directory: test/integration
run: |
set -euo pipefail
if [ -n "${NPMRC:-}" ]; then
npm install --userconfig "$NPMRC"
else
npm install
fi
node invoke.mjs "$FUNCTION_NAME"
- name: Destroy the test Lambda function
if: always() && github.event_name == 'push'
run: aws lambda delete-function --function-name "$FUNCTION_NAME" || true
- name: Delete the pushed test image
if: always() && github.event_name == 'push'
env:
INTEG_ECR_REPOSITORY: ${{ secrets.INTEG_ECR_REPOSITORY }}
run: |
aws ecr batch-delete-image \
--repository-name "$INTEG_ECR_REPOSITORY" \
--image-ids imageTag="$IMAGE_TAG" || true
- name: Configure AWS credentials (source push)
if: github.event_name == 'push'
uses: aws-actions/configure-aws-credentials@e1253824e5c10ff9df46874f81ed3ec929e19cfd # v6.3.0
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Log in to Amazon ECR
if: github.event_name == 'push'
id: login-ecr
uses: aws-actions/amazon-ecr-login@7290e214a610b32bc0eef81748948b6d466a8783 # v2.2.0
- name: Push the image
if: github.event_name == 'push'
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
# Tags are immutable, so a commit's image is pushed once; a re-run skips the push.
run: |
tag="$GITHUB_SHA-$ARCH"
if existing=$(aws ecr describe-images --repository-name "$ECR_REPOSITORY" --image-ids imageTag="$tag" \
--query 'imageDetails[0].imageDigest' --output text 2> /tmp/describe-images.err); then
echo "$ECR_REPOSITORY:$tag is already published as $existing"
exit 0
fi
grep -q ImageNotFoundException /tmp/describe-images.err || { cat /tmp/describe-images.err >&2; exit 1; }
image="$ECR_REGISTRY/$ECR_REPOSITORY:$tag"
docker tag "$IMAGE" "$image"
docker push "$image"