-
Notifications
You must be signed in to change notification settings - Fork 182
fix(ci): publish system-tests image via S3 + GH Actions dispatch #4065
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
+83
−1
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
1cc5cf5
fix(ci): publish system-tests image via GH Actions dispatch
MilanGarnier dc1b2ac
fix(ci): scope system-tests image cleanup to digests this run superseded
MilanGarnier e14d7f9
fix(ci): scope gitlab-ci-publish-packages octo-sts policy to actions:…
MilanGarnier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 . | ||
| 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" | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the first dispatch against the existing
dd-trace-php/dd-library-phppackage, thisGITHUB_TOKENpush will be rejected if that package is still the current org-scoped package: GitHub documents thatGITHUB_TOKENcannot push to a namespace that was previously published but not connected to the workflow repository, and the public package page fordd-library-phpdoes not redirect under the repo the way the linkeddd-lib-php-initpackage 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 👍 / 👎.