Skip to content

Commit b1fc099

Browse files
authored
Merge pull request #146 from DataDog/sarahchen6/delete-workflow
Add test image deletion workflow
2 parents 1c058af + c0ff030 commit b1fc099

File tree

3 files changed

+172
-2
lines changed

3 files changed

+172
-2
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: Delete test image mirror PR
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
pr_number:
7+
description: "PR number in dd-trace-java-docker-build (e.g. 123)"
8+
required: true
9+
10+
jobs:
11+
delete-test-mirror-pr:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
id-token: write # Required for OIDC token federation
15+
contents: read
16+
steps:
17+
- uses: DataDog/dd-octo-sts-action@acaa02eee7e3bb0839e4272dacb37b8f3b58ba80 # v1.0.3
18+
id: octo-sts
19+
with:
20+
scope: DataDog/images
21+
policy: dd-trace-java-docker-build.update-mirror
22+
23+
- name: Checkout DataDog/dd-trace-java-docker-build
24+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
25+
with:
26+
path: dd-trace-java-docker-build
27+
28+
- name: Checkout DataDog/images
29+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
30+
with:
31+
repository: DataDog/images
32+
token: ${{ steps.octo-sts.outputs.token }}
33+
path: images
34+
35+
- name: Capture images HEAD SHA
36+
id: images-head
37+
run: echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
38+
working-directory: images
39+
40+
- name: Remove test mirror entries
41+
env:
42+
PR_NUMBER: ${{ github.event.inputs.pr_number }}
43+
run: bash "${GITHUB_WORKSPACE}/dd-trace-java-docker-build/scripts/delete-test-mirror-entries.sh"
44+
working-directory: images
45+
46+
- name: Define branch name
47+
id: define-branch
48+
run: echo "branch=ci/delete-dd-trace-java-docker-build-test-images-pr${{ github.event.inputs.pr_number }}" >> "$GITHUB_OUTPUT"
49+
50+
- name: Commit changes
51+
id: create-commit
52+
env:
53+
PR_NUMBER: ${{ github.event.inputs.pr_number }}
54+
run: |
55+
git config user.name "github-actions[bot]"
56+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
57+
git add mirror.yaml mirror.lock.yaml
58+
if git diff --cached --quiet; then
59+
echo "::error::Expected mirror file deletions but found no changes."
60+
exit 1
61+
fi
62+
git commit -m "chore: Remove dd-trace-java-docker-build test images for PR #${PR_NUMBER}"
63+
echo "commit=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
64+
working-directory: images
65+
66+
- name: Push changes
67+
uses: DataDog/commit-headless@05d7b7ee023e2c7d01c47832d420c2503cd416f3 # action/v2.0.3
68+
with:
69+
target: DataDog/images
70+
token: "${{ steps.octo-sts.outputs.token }}"
71+
branch: "${{ steps.define-branch.outputs.branch }}"
72+
head-sha: "${{ steps.images-head.outputs.sha }}"
73+
create-branch: true
74+
command: push
75+
commits: "${{ steps.create-commit.outputs.commit }}"
76+
working-directory: images
77+
78+
- name: Create pull request
79+
env:
80+
GH_TOKEN: ${{ steps.octo-sts.outputs.token }}
81+
PR_NUMBER: ${{ github.event.inputs.pr_number }}
82+
run: |
83+
gh pr create \
84+
--repo DataDog/images \
85+
--draft \
86+
--title "Remove dd-trace-java-docker-build test images for PR #${PR_NUMBER}" \
87+
--base master \
88+
--head "${{ steps.define-branch.outputs.branch }}" \
89+
--body "Removes mirror.yaml and mirror.lock.yaml entries for \`${PR_NUMBER}_merge-*\` test images from DataDog/dd-trace-java-docker-build#${PR_NUMBER}."

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,7 @@ To test these images in `dd-trace-java` CI:
3737
2. After the PR images are built in the [GitHub Container Registry](https://github.com/DataDog/dd-trace-java-docker-build/pkgs/container/dd-trace-java-docker-build), run the [Create test image mirror PR](https://github.com/DataDog/dd-trace-java-docker-build/actions/workflows/create-test-mirror-pr.yml) workflow with the corresponding PR number: `N`. This automatically opens a PR in [DataDog/images](https://github.com/DataDog/images) that adds mirror entries for the `N_merge-*` test images. Merge the PR that should be automatically approved by the `dd-prapprover` bot.
3838
3. Open a PR in [DataDog/dd-trace-java](https://github.com/DataDog/dd-trace-java) that sets `BUILDER_IMAGE_VERSION_PREFIX: "N_merge-"` in `.gitlab-ci.yml`. Here, you can check your test images with `DataDog/dd-trace-java` CI.
3939
4. Every time you want to test changes made in PR #N, ensure the test image SHAs in `DataDog/images` are updated by running the [Create test image mirror PR](https://github.com/DataDog/dd-trace-java-docker-build/actions/workflows/create-test-mirror-pr.yml) workflow with `N`. Confirm that these PRs are approved and merged by the `dd-prapprover` bot.
40-
5. When the test images look good and `DataDog/dd-trace-java` CI is green, merge your `DataDog/dd-trace-java-docker-build` PR #N, close the test `DataDog/dd-trace-java` PR, and **remove the `N_merge-*` images from the `DataDog/images` repo**.
41-
6. Finally, run the [Tag new images version](https://github.com/DataDog/dd-trace-java-docker-build/actions/workflows/docker-tag.yml) workflow. The [Update mirror digests for ci-* images](https://github.com/DataDog/dd-trace-java-docker-build/actions/workflows/update-mirror-digests.yml) workflow will automatically open a PR in `DataDog/images`, updating the pinned `ci-*` digests. `dd-trace-java` CI should automatically pick up these updated images a few minutes after the PR is merged.
40+
5. When the test images look good and `DataDog/dd-trace-java` CI is green, merge your `DataDog/dd-trace-java-docker-build` PR #N.
41+
6. Close the test `DataDog/dd-trace-java` PR.
42+
7. Run the [Delete test image mirror PR](https://github.com/DataDog/dd-trace-java-docker-build/actions/workflows/delete-test-mirror-pr.yml) workflow with `N` to remove the `N_merge-*` images from `DataDog/images`. Confirm that this PR is approved and merged by the `dd-prapprover` bot.
43+
8. Finally, run the [Tag new images version](https://github.com/DataDog/dd-trace-java-docker-build/actions/workflows/docker-tag.yml) workflow. The [Update mirror digests for ci-* images](https://github.com/DataDog/dd-trace-java-docker-build/actions/workflows/update-mirror-digests.yml) workflow will automatically open a PR in `DataDog/images`, updating the pinned `ci-*` digests. `dd-trace-java` CI should automatically pick up these updated images a few minutes after the PR is merged.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/env bash
2+
# delete-test-mirror-entries.sh — remove {PR_NUMBER}_merge-* test image entries
3+
# from mirror.yaml and mirror.lock.yaml in the DataDog/images repo.
4+
#
5+
# This script is called in the delete-test-mirror-pr GitHub workflow.
6+
# It must be run from the root of DataDog/images.
7+
#
8+
# Required env var:
9+
# PR_NUMBER — pull request number in dd-trace-java-docker-build (numeric)
10+
11+
set -euo pipefail
12+
13+
readonly SOURCE_REPO="ghcr.io/datadog/dd-trace-java-docker-build"
14+
readonly CI_VARIANTS=(base 7 8 11 17 21 25 tip zulu8 zulu11 oracle8 ibm8 semeru8 semeru11 semeru17 graalvm17 graalvm21 graalvm25)
15+
16+
if ! [[ "${PR_NUMBER}" =~ ^[0-9]+$ ]]; then
17+
echo "::error::PR_NUMBER must be numeric (got: '${PR_NUMBER}')" >&2
18+
exit 1
19+
fi
20+
21+
readonly PREFIX="${PR_NUMBER}_merge-"
22+
23+
require_entry_exists() {
24+
local tag="$1"
25+
if ! grep -qF "${SOURCE_REPO}:${tag}\"" mirror.yaml; then
26+
echo "::error::Missing mirror.yaml entry for ${SOURCE_REPO}:${tag}" >&2
27+
exit 1
28+
fi
29+
if ! grep -qF "${SOURCE_REPO}:${tag}" mirror.lock.yaml; then
30+
echo "::error::Missing mirror.lock.yaml entry for ${SOURCE_REPO}:${tag}" >&2
31+
exit 1
32+
fi
33+
}
34+
35+
remove_from_mirror_yaml() {
36+
local tag="$1"
37+
local src=" - source: \"${SOURCE_REPO}:${tag}\""
38+
local file="mirror.yaml"
39+
awk -v src="${src}" '
40+
$0 == src { skip=1; removed=1; next }
41+
skip && /^ - source: / { skip=0 }
42+
!skip { print }
43+
END {
44+
if (!removed) {
45+
exit 44
46+
}
47+
}
48+
' "${file}" > "${file}.tmp" && mv "${file}.tmp" "${file}"
49+
}
50+
51+
remove_from_mirror_lock() {
52+
local tag="$1"
53+
local src=" - source: ${SOURCE_REPO}:${tag}"
54+
local file="mirror.lock.yaml"
55+
awk -v src="${src}" '
56+
$0 == src { skip_digest=1; removed=1; next }
57+
skip_digest && /^ digest: / { skip_digest=0; next }
58+
{ print }
59+
END {
60+
if (!removed) {
61+
exit 45
62+
}
63+
}
64+
' "${file}" > "${file}.tmp" && mv "${file}.tmp" "${file}"
65+
}
66+
67+
echo "Validating test mirror entries for prefix '${PREFIX}'..."
68+
for variant in "${CI_VARIANTS[@]}"; do
69+
require_entry_exists "${PREFIX}${variant}"
70+
done
71+
72+
echo "Removing test mirror entries for prefix '${PREFIX}'..."
73+
for variant in "${CI_VARIANTS[@]}"; do
74+
tag="${PREFIX}${variant}"
75+
remove_from_mirror_yaml "${tag}"
76+
remove_from_mirror_lock "${tag}"
77+
done
78+
79+
echo "Removed ${#CI_VARIANTS[@]} entries from mirror.yaml and mirror.lock.yaml"

0 commit comments

Comments
 (0)