|
1536 | 1536 | paths: |
1537 | 1537 | - packages/datadog-setup.php |
1538 | 1538 |
|
1539 | | -# Runs on every non-default branch so system tests can be run against any (non-default) in-progress branch. |
1540 | | -"publish docker image for system tests (token)": |
1541 | | - stage: release |
1542 | | - image: registry.ddbuild.io/images/dd-octo-sts-ci-base:2025.06-1 |
1543 | | - tags: [ "arch:amd64" ] |
1544 | | - id_tokens: |
1545 | | - DDOCTOSTS_ID_TOKEN: |
1546 | | - aud: dd-octo-sts |
1547 | | - rules: |
1548 | | - - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH |
1549 | | - when: never |
1550 | | - - when: on_success |
1551 | | - variables: |
1552 | | - GIT_STRATEGY: none |
1553 | | - script: |
1554 | | - - dd-octo-sts token --scope DataDog/dd-trace-php --policy gitlab-ci-publish-packages > github_token_system_tests.txt |
1555 | | - artifacts: |
1556 | | - paths: |
1557 | | - - github_token_system_tests.txt |
1558 | | - expire_in: 1 hour |
1559 | | - when: on_success |
| 1539 | +# System-tests image publishing. Runs on every non-default branch so system tests can be |
| 1540 | +# run against any in-progress branch (DataDog/system-tests LIBRARY_TARGET_BRANCH). |
1560 | 1541 |
|
1561 | | -"publish docker image for system tests": |
| 1542 | +"publish docker image for system tests (upload)": |
1562 | 1543 | stage: release |
1563 | | - image: 486234852809.dkr.ecr.us-east-1.amazonaws.com/docker:29.4.0-noble |
1564 | | - tags: [ "docker-in-docker:amd64" ] |
1565 | | - resource_group: "publish-system-tests-image-${CI_COMMIT_REF_SLUG}" |
1566 | | - interruptible: true |
| 1544 | + image: registry.ddbuild.io/images/mirror/amazon/aws-cli:2.17.32 |
| 1545 | + tags: [ "arch:amd64" ] |
1567 | 1546 | rules: |
1568 | 1547 | - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH |
1569 | 1548 | when: never |
1570 | | - - when: on_success |
| 1549 | + - when: always |
| 1550 | + allow_failure: true |
1571 | 1551 | needs: |
1572 | | - - job: "publish docker image for system tests (token)" |
1573 | | - artifacts: true |
1574 | 1552 | - job: "datadog-setup.php" |
1575 | 1553 | artifacts: true |
1576 | 1554 | - job: "package extension: [amd64, x86_64-unknown-linux-gnu]" |
|
1579 | 1557 | artifacts: true |
1580 | 1558 | variables: |
1581 | 1559 | GIT_STRATEGY: none |
1582 | | - allow_failure: |
1583 | | - exit_codes: 3 |
1584 | 1560 | script: | |
1585 | 1561 | set -e |
1586 | | - IMAGE="ghcr.io/datadog/dd-trace-php/dd-library-php:${CI_COMMIT_REF_SLUG}" |
1587 | | - VERSIONS_URL="https://api.github.com/orgs/DataDog/packages/container/dd-trace-php%2Fdd-library-php/versions" |
1588 | | - GITHUB_TOKEN=$(<github_token_system_tests.txt) |
1589 | | - |
1590 | | - apt-get update -qq && apt-get install -y -qq curl jq > /dev/null |
| 1562 | + # Normalise the arch tarball names so the GitHub Actions side needs only the branch slug. |
| 1563 | + DEST="s3://dd-trace-php-builds/ci/${CI_COMMIT_REF_SLUG}" |
| 1564 | + aws s3 cp packages/dd-library-php-*-x86_64-linux-gnu.tar.gz "${DEST}/dd-library-php-x86_64-linux-gnu.tar.gz" |
| 1565 | + aws s3 cp packages/dd-library-php-*-aarch64-linux-gnu.tar.gz "${DEST}/dd-library-php-aarch64-linux-gnu.tar.gz" |
| 1566 | + aws s3 cp packages/datadog-setup.php "${DEST}/datadog-setup.php" |
| 1567 | + echo "Uploaded system-tests artifacts to ${DEST}/" |
| 1568 | + |
| 1569 | +"publish docker image for system tests (dispatch)": |
| 1570 | + stage: release |
| 1571 | + image: registry.ddbuild.io/images/dd-octo-sts-ci-base:2025.06-1 |
| 1572 | + tags: [ "arch:amd64" ] |
| 1573 | + id_tokens: |
| 1574 | + DDOCTOSTS_ID_TOKEN: |
| 1575 | + aud: dd-octo-sts |
| 1576 | + rules: |
| 1577 | + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH |
| 1578 | + when: never |
| 1579 | + - when: always |
| 1580 | + allow_failure: true |
| 1581 | + needs: |
| 1582 | + - job: "publish docker image for system tests (upload)" |
| 1583 | + variables: |
| 1584 | + GIT_STRATEGY: none |
| 1585 | + script: | |
| 1586 | + set -e |
| 1587 | + # octo-sts token: actions:write to dispatch the workflow, pull_requests:read to gate on an open PR. |
| 1588 | + GITHUB_TOKEN=$(dd-octo-sts token --scope DataDog/dd-trace-php --policy gitlab-ci-publish-packages) |
1591 | 1589 |
|
1592 | | - STATUS=$(curl -s -o /tmp/pulls.json -w "%{http_code}" -H "Authorization: Bearer ${GITHUB_TOKEN}" -H "Accept: application/vnd.github+json" \ |
1593 | | - "https://api.github.com/repos/DataDog/dd-trace-php/pulls?head=DataDog:${CI_COMMIT_BRANCH}&state=open") |
1594 | | - if [ "${STATUS}" != "200" ]; then |
1595 | | - echo "ERROR: failed to check for an open PR on branch ${CI_COMMIT_BRANCH} (HTTP ${STATUS}):"; cat /tmp/pulls.json |
1596 | | - exit 1 |
1597 | | - fi |
1598 | | - PR_COUNT=$(jq 'length' /tmp/pulls.json) |
1599 | | - if [ "${PR_COUNT}" -eq 0 ]; then |
| 1590 | + # Only publish for branches with an open PR (system tests pull the image per-PR). |
| 1591 | + PR_COUNT=$(curl -s -H "Authorization: Bearer ${GITHUB_TOKEN}" -H "Accept: application/vnd.github+json" \ |
| 1592 | + "https://api.github.com/repos/DataDog/dd-trace-php/pulls?head=DataDog:${CI_COMMIT_BRANCH}&state=open" | jq 'length') |
| 1593 | + if [ "${PR_COUNT:-0}" -eq 0 ]; then |
1600 | 1594 | echo "No open PR for branch ${CI_COMMIT_BRANCH}; skipping system-tests image publish." |
1601 | | - exit 3 |
| 1595 | + exit 0 |
1602 | 1596 | fi |
1603 | | - echo "Found open PR(s) on branch ${CI_COMMIT_BRANCH}, continuing" |
1604 | | - |
1605 | | - docker login ghcr.io -u DataDog --password-stdin < github_token_system_tests.txt |
1606 | | - echo "Docker login to ghcr.io succeeded" |
1607 | | - |
1608 | | - gh_api() { curl -s -o /tmp/resp.json -w "%{http_code}" -X "$1" \ |
1609 | | - -H "Authorization: Bearer ${GITHUB_TOKEN}" -H "Accept: application/vnd.github+json" "$2"; } |
1610 | | - |
1611 | | - # delete any pre-existing image with the same tag so pushing with the same tag doesn't pile up untagged versions. |
1612 | | - echo "== Checking token and existing image tagged ${CI_COMMIT_REF_SLUG} ==" |
1613 | | - STATUS=$(gh_api GET "$VERSIONS_URL") |
1614 | | - if [ "$STATUS" != "200" ]; then |
1615 | | - echo "WARNING: token check failed (HTTP ${STATUS}), skipping pre-delete:"; cat /tmp/resp.json |
1616 | | - else |
1617 | | - echo "Token OK (HTTP 200): listed package versions for dd-trace-php/dd-library-php" |
1618 | | - VERSION_ID=$(jq -r --arg TAG "${CI_COMMIT_REF_SLUG}" \ |
1619 | | - '.[] | select(.metadata.container.tags[]? == $TAG) | .id' /tmp/resp.json | head -n1) |
1620 | | - if [ -z "$VERSION_ID" ]; then |
1621 | | - echo "No pre-existing image tagged ${CI_COMMIT_REF_SLUG} found, nothing to delete" |
1622 | | - else |
1623 | | - STATUS=$(gh_api DELETE "${VERSIONS_URL}/${VERSION_ID}") |
1624 | | - if [ "$STATUS" = "204" ]; then |
1625 | | - echo "Deleted existing image version ${VERSION_ID} (HTTP 204)" |
1626 | | - else |
1627 | | - echo "WARNING: failed to delete existing image version ${VERSION_ID} (HTTP ${STATUS}), continuing anyway:" |
1628 | | - cat /tmp/resp.json |
1629 | | - fi |
1630 | | - fi |
| 1597 | + echo "Found open PR(s) on branch ${CI_COMMIT_BRANCH}, dispatching publish workflow" |
| 1598 | + |
| 1599 | + # GHCR write must come from GitHub Actions' GITHUB_TOKEN, so trigger the workflow that |
| 1600 | + # pulls the artifacts back down from S3 and pushes the image. |
| 1601 | + PAYLOAD=$(jq -n --arg ref "${CI_DEFAULT_BRANCH}" --arg slug "${CI_COMMIT_REF_SLUG}" \ |
| 1602 | + '{ref: $ref, inputs: {ref_slug: $slug}}') |
| 1603 | + HTTP=$(curl -s -o /tmp/dispatch.json -w "%{http_code}" -X POST \ |
| 1604 | + -H "Authorization: Bearer ${GITHUB_TOKEN}" -H "Accept: application/vnd.github+json" \ |
| 1605 | + "https://api.github.com/repos/DataDog/dd-trace-php/actions/workflows/publish-system-tests-image.yml/dispatches" \ |
| 1606 | + -d "${PAYLOAD}") |
| 1607 | + if [ "${HTTP}" != "204" ]; then |
| 1608 | + echo "ERROR: workflow_dispatch failed (HTTP ${HTTP}):"; cat /tmp/dispatch.json; exit 1 |
1631 | 1609 | fi |
1632 | | - |
1633 | | - echo "== Building and pushing ${IMAGE} (linux/amd64, linux/arm64) ==" |
1634 | | - # stage each arch's tarball under its own dir so the Dockerfile can pick the right one via buildx's TARGETARCH arg. |
1635 | | - mkdir -p packages/amd64 packages/arm64 |
1636 | | - cp packages/dd-library-php-*-x86_64-linux-gnu.tar.gz packages/amd64/ |
1637 | | - cp packages/dd-library-php-*-aarch64-linux-gnu.tar.gz packages/arm64/ |
1638 | | - cp packages/datadog-setup.php packages/amd64/ |
1639 | | - cp packages/datadog-setup.php packages/arm64/ |
1640 | | - |
1641 | | - printf 'FROM scratch\nARG TARGETARCH\nCOPY packages/${TARGETARCH}/dd-library-php-*-linux-gnu.tar.gz /\nCOPY packages/${TARGETARCH}/datadog-setup.php /\n' \ |
1642 | | - > Dockerfile.system-tests |
1643 | | - BUILDER="system-tests-builder-${CI_JOB_ID}" |
1644 | | - docker buildx create --name "$BUILDER" --driver docker-container |
1645 | | - docker buildx build --builder "$BUILDER" --platform linux/amd64,linux/arm64 \ |
1646 | | - -f Dockerfile.system-tests -t "$IMAGE" --push . |
1647 | | - echo "Pushed $IMAGE" |
1648 | | - after_script: |
1649 | | - - rm -f github_token_system_tests.txt |
1650 | | - - docker buildx rm "system-tests-builder-${CI_JOB_ID}" || true |
| 1610 | + echo "Dispatched publish-system-tests-image.yml (tag ${CI_COMMIT_REF_SLUG}) on ${CI_DEFAULT_BRANCH}" |
1651 | 1611 |
|
1652 | 1612 | "bundle for reliability env": |
1653 | 1613 | stage: shared-pipeline |
|
0 commit comments