Skip to content

Commit 1cc5cf5

Browse files
committed
fix(ci): publish system-tests image via GH Actions dispatch
Standalone workflow that pulls per-branch build artifacts from S3 and pushes a multi-arch dd-library-php image so system-tests can pull it by branch slug. Lands first, before GitLab CI is wired to dispatch it, since workflow_dispatch resolves the workflow by filename against the default branch's registered workflows regardless of target ref.
1 parent b2d669e commit 1cc5cf5

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: "Publish system-tests image"
2+
3+
# Pushes the per-branch dd-library-php image that DataDog/system-tests pulls
4+
# (LIBRARY_TARGET_BRANCH), tagged with the GitLab CI_COMMIT_REF_SLUG.
5+
on:
6+
workflow_dispatch:
7+
inputs:
8+
ref_slug:
9+
description: "Sanitised branch name (GitLab CI_COMMIT_REF_SLUG); used as the image tag and the S3 prefix."
10+
required: true
11+
12+
concurrency:
13+
group: "publish-system-tests-image-${{ github.event.inputs.ref_slug }}"
14+
cancel-in-progress: true
15+
16+
env:
17+
IMAGE: "ghcr.io/datadog/dd-trace-php/dd-library-php"
18+
PACKAGE_PATH: "orgs/DataDog/packages/container/dd-trace-php%2Fdd-library-php"
19+
S3_BASE: "https://dd-trace-php-builds.s3.us-east-1.amazonaws.com/ci"
20+
21+
jobs:
22+
publish:
23+
runs-on: ubuntu-latest
24+
permissions:
25+
packages: write
26+
contents: read
27+
steps:
28+
- name: Download build artifacts from S3
29+
env:
30+
REF_SLUG: ${{ github.event.inputs.ref_slug }}
31+
run: |
32+
set -euo pipefail
33+
base="${S3_BASE}/${REF_SLUG}"
34+
mkdir -p packages/amd64 packages/arm64
35+
curl -fSL --retry 3 "${base}/dd-library-php-x86_64-linux-gnu.tar.gz" -o packages/amd64/dd-library-php-x86_64-linux-gnu.tar.gz
36+
curl -fSL --retry 3 "${base}/dd-library-php-aarch64-linux-gnu.tar.gz" -o packages/arm64/dd-library-php-aarch64-linux-gnu.tar.gz
37+
curl -fSL --retry 3 "${base}/datadog-setup.php" -o packages/amd64/datadog-setup.php
38+
cp packages/amd64/datadog-setup.php packages/arm64/datadog-setup.php
39+
40+
- name: Log in to GHCR
41+
env:
42+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43+
ACTOR: ${{ github.actor }}
44+
run: echo "$GH_TOKEN" | docker login ghcr.io -u "$ACTOR" --password-stdin
45+
46+
- name: Set up Docker Buildx
47+
uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4.1.0
48+
49+
- name: Build and push image
50+
env:
51+
REF_SLUG: ${{ github.event.inputs.ref_slug }}
52+
run: |
53+
set -euo pipefail
54+
printf 'FROM scratch\nARG TARGETARCH\nCOPY packages/${TARGETARCH}/dd-library-php-*-linux-gnu.tar.gz /\nCOPY packages/${TARGETARCH}/datadog-setup.php /\n' > Dockerfile.system-tests
55+
# Label links the image to this repo, which is what makes GHCR grant this repo's
56+
# GITHUB_TOKEN manage rights on the package (needed for the cleanup step below).
57+
docker buildx build --platform linux/amd64,linux/arm64 \
58+
--label org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }} \
59+
-f Dockerfile.system-tests -t "${IMAGE}:${REF_SLUG}" --push .
60+
echo "Pushed ${IMAGE}:${REF_SLUG}"
61+
62+
- name: Clean up superseded untagged versions
63+
env:
64+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65+
REF_SLUG: ${{ github.event.inputs.ref_slug }}
66+
continue-on-error: true
67+
run: | # re-pushing a tag above just retargets it, leaving the old version untagged;
68+
# the just-pushed multi-arch index's own child manifests are untagged too, so
69+
# keep whatever digest the current tag still references.
70+
set -euo pipefail
71+
keep_digests=$(docker buildx imagetools inspect "${IMAGE}:${REF_SLUG}" --raw | jq -r '.manifests[].digest')
72+
gh api "${PACKAGE_PATH}/versions" \
73+
--jq '.[] | select(.metadata.container.tags == []) | "\(.id) \(.name)"' \
74+
| while read -r id digest; do
75+
if grep -qxF "$digest" <<< "$keep_digests"; then
76+
continue
77+
fi
78+
gh api "${PACKAGE_PATH}/versions/${id}" -X DELETE
79+
done
80+
echo "Untagged-version cleanup complete"

0 commit comments

Comments
 (0)