Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/chainguard/gitlab-ci-publish-packages.sts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ issuer: https://gitlab.ddbuild.io
subject_pattern: "project_path:DataDog/apm-reliability/dd-trace-php:ref_type:(branch|tag):ref:.*"

permissions:
packages: write
actions: write
pull_requests: read
82 changes: 82 additions & 0 deletions .github/workflows/publish-system-tests-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: "Publish system-tests image"

# Pushes the per-branch dd-library-php image that DataDog/system-tests pulls
# (LIBRARY_TARGET_BRANCH), tagged with the GitLab CI_COMMIT_REF_SLUG.
on:
workflow_dispatch:
inputs:
ref_slug:
description: "Sanitised branch name (GitLab CI_COMMIT_REF_SLUG); used as the image tag and the S3 prefix."
required: true

concurrency:
group: "publish-system-tests-image-${{ github.event.inputs.ref_slug }}"
cancel-in-progress: true

env:
IMAGE: "ghcr.io/datadog/dd-trace-php/dd-library-php"
PACKAGE_PATH: "orgs/DataDog/packages/container/dd-trace-php%2Fdd-library-php"
S3_BASE: "https://dd-trace-php-builds.s3.us-east-1.amazonaws.com/ci"

jobs:
publish:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- name: Download build artifacts from S3
env:
REF_SLUG: ${{ github.event.inputs.ref_slug }}
run: |
set -euo pipefail
base="${S3_BASE}/${REF_SLUG}"
mkdir -p packages/amd64 packages/arm64
curl -fSL --retry 3 "${base}/dd-library-php-x86_64-linux-gnu.tar.gz" -o "packages/amd64/dd-library-php-${REF_SLUG}-x86_64-linux-gnu.tar.gz"
curl -fSL --retry 3 "${base}/dd-library-php-aarch64-linux-gnu.tar.gz" -o "packages/arm64/dd-library-php-${REF_SLUG}-aarch64-linux-gnu.tar.gz"
curl -fSL --retry 3 "${base}/datadog-setup.php" -o packages/amd64/datadog-setup.php
cp packages/amd64/datadog-setup.php packages/arm64/datadog-setup.php

- name: Log in to GHCR
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ACTOR: ${{ github.actor }}
run: echo "$GH_TOKEN" | docker login ghcr.io -u "$ACTOR" --password-stdin

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4.1.0

- name: Record digests about to be superseded
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REF_SLUG: ${{ github.event.inputs.ref_slug }}
run: |
set -euo pipefail
old_index=$(gh api "${PACKAGE_PATH}/versions" --jq '.[] | select(.metadata.container.tags[]? == "'"${REF_SLUG}"'") | .name')
old_children=$(docker buildx imagetools inspect "${IMAGE}:${REF_SLUG}" --raw 2>/dev/null | jq -r '.manifests[].digest' || true)
printf '%s\n' "$old_index" $old_children | sed '/^$/d' > old_digests.txt

- name: Build and push image
env:
REF_SLUG: ${{ github.event.inputs.ref_slug }}
run: |
set -euo pipefail
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
# Label links the image to this repo, which is what makes GHCR grant this repo's
# GITHUB_TOKEN manage rights on the package (needed for the cleanup step below).
docker buildx build --platform linux/amd64,linux/arm64 \
--label org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }} \
-f Dockerfile.system-tests -t "${IMAGE}:${REF_SLUG}" --push .
Comment on lines +67 to +69

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Connect the existing GHCR package before pushing

On the first dispatch against the existing dd-trace-php/dd-library-php package, this GITHUB_TOKEN push will be rejected if that package is still the current org-scoped package: GitHub documents that GITHUB_TOKEN cannot push to a namespace that was previously published but not connected to the workflow repository, and the public package page for dd-library-php does not redirect under the repo the way the linked dd-lib-php-init package does. The source label cannot grant access until the push succeeds, so connect the existing package/add Actions access first or publish to a new linked package.

Useful? React with 👍 / 👎.

echo "Pushed ${IMAGE}:${REF_SLUG}"

- name: Delete the digests this run superseded
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true
run: |
set -euo pipefail
while read -r digest; do
id=$(gh api "${PACKAGE_PATH}/versions" --jq '.[] | select(.name=="'"$digest"'" and .metadata.container.tags==[]) | .id')
[ -n "$id" ] && gh api "${PACKAGE_PATH}/versions/${id}" -X DELETE
done < old_digests.txt
echo "Superseded-digest cleanup complete"
Loading