Skip to content

Commit 9c2d3ed

Browse files
authored
feat: Use ECR API to tag platform images instead of docker buildx ima… (#1377)
…getools *Issue #, if available:* *Description of changes:* 1. Removes the two single-platform build/push steps 2. Keeps the single multi-arch docker/build-push-action push to both private and public ECR 3. Adds a new step that uses aws ecr batch-get-image + aws ecr put-image to tag the platform digests inside the manifest index with v$VERSION-amd64 / v$VERSION-arm64, and tags attestation manifests (architecture=unknown) with their sha hex By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 68848b5 commit 9c2d3ed

1 file changed

Lines changed: 53 additions & 21 deletions

File tree

.github/workflows/release-build.yml

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -208,27 +208,7 @@ jobs:
208208
shell: bash
209209
run: .github/scripts/test-adot-javaagent-image.sh "${{ env.TEST_TAG }}" "$VERSION"
210210

211-
- name: Build and push amd64 image to private ECR
212-
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 #v6.18.0
213-
with:
214-
push: true
215-
build-args: "ADOT_JAVA_VERSION=${{ env.VERSION }}"
216-
context: .
217-
platforms: linux/amd64
218-
tags: |
219-
${{ env.PRIVATE_REPOSITORY }}:v${{ env.VERSION }}-amd64
220-
221-
- name: Build and push arm64 image to private ECR
222-
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 #v6.18.0
223-
with:
224-
push: true
225-
build-args: "ADOT_JAVA_VERSION=${{ env.VERSION }}"
226-
context: .
227-
platforms: linux/arm64
228-
tags: |
229-
${{ env.PRIVATE_REPOSITORY }}:v${{ env.VERSION }}-arm64
230-
231-
- name: Build and push multi-arch image
211+
- name: Build and push image
232212
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 #v6.18.0
233213
with:
234214
push: true
@@ -239,6 +219,58 @@ jobs:
239219
${{ env.PUBLIC_REPOSITORY }}:v${{ env.VERSION }}
240220
${{ env.PRIVATE_REPOSITORY }}:v${{ env.VERSION }}
241221
222+
- name: Tag platform images in private ECR
223+
env:
224+
REPO_NAME: adot-autoinstrumentation-java
225+
run: |
226+
VERSION="${{ env.VERSION }}"
227+
REGION="${{ env.AWS_PRIVATE_ECR_REGION }}"
228+
# Read the manifest index for the multi-arch tag we just pushed
229+
MANIFEST_INDEX=$(aws ecr batch-get-image \
230+
--repository-name "${REPO_NAME}" \
231+
--image-ids imageTag="v${VERSION}" \
232+
--region "${REGION}" \
233+
--query 'images[0].imageManifest' \
234+
--output text)
235+
236+
# Tag platform images (amd64, arm64) with v$VERSION-$arch
237+
for arch in amd64 arm64; do
238+
DIGEST=$(echo "$MANIFEST_INDEX" | jq -r ".manifests[] | select(.platform.architecture==\"${arch}\") | .digest")
239+
if [ -z "$DIGEST" ] || [ "$DIGEST" = "null" ]; then
240+
echo "No ${arch} image found in manifest index, skipping"
241+
continue
242+
fi
243+
MANIFEST=$(aws ecr batch-get-image \
244+
--repository-name "${REPO_NAME}" \
245+
--image-ids imageDigest="${DIGEST}" \
246+
--region "${REGION}" \
247+
--query 'images[0].imageManifest' \
248+
--output text)
249+
aws ecr put-image \
250+
--repository-name "${REPO_NAME}" \
251+
--image-tag "v${VERSION}-${arch}" \
252+
--image-manifest "$MANIFEST" \
253+
--region "${REGION}" > /dev/null
254+
echo "Tagged ${DIGEST} as v${VERSION}-${arch}"
255+
done
256+
257+
# Tag attestation manifests (architecture=unknown) with their sha hex
258+
for DIGEST in $(echo "$MANIFEST_INDEX" | jq -r '.manifests[] | select(.platform.architecture=="unknown") | .digest'); do
259+
SHA_HEX="${DIGEST#sha256:}"
260+
MANIFEST=$(aws ecr batch-get-image \
261+
--repository-name "${REPO_NAME}" \
262+
--image-ids imageDigest="${DIGEST}" \
263+
--region "${REGION}" \
264+
--query 'images[0].imageManifest' \
265+
--output text)
266+
aws ecr put-image \
267+
--repository-name "${REPO_NAME}" \
268+
--image-tag "${SHA_HEX}" \
269+
--image-manifest "$MANIFEST" \
270+
--region "${REGION}" > /dev/null
271+
echo "Tagged ${DIGEST} as ${SHA_HEX} (attestation)"
272+
done
273+
242274
- name: Build and Publish release with Gradle
243275
uses: gradle/actions/setup-gradle@d9c87d481d55275bb5441eef3fe0e46805f9ef70 #v3.5.0
244276
with:

0 commit comments

Comments
 (0)