Skip to content

Commit 2385771

Browse files
fix(lib-injection): wait and publish release tag of image [backport #4931, #5039 to 1.8] (#5056)
## [fix(lib-injection): wait and publish release tag of image](a4fdbad) Currently, only dev images for commits are pushed to the container registry. This means that images like `v1.7.0` that get published are really just aliases of the corresponding SHA image. These images use ``` pip install git+....@sha ``` to install the image. For example: ``` ~/d/h/c/datadog ❯❯❯ docker run -it gcr.io/datadoghq/dd-lib-python-init:v1.7.0 cat /datadog-init/sitecustomize.py | head -n 12 """ This module when included on the PYTHONPATH will install the ddtrace package from pypi for the Python runtime being used. """ $ docker run -it gcr.io/datadoghq/dd-lib-python-init:v1.7.0 cat /datadog-init/sitecustomize.py | head -n 12 ... version = "git+https://github.com/Datadog/dd-trace-py@ced65df45a9b592dd36af12c37c047c1486af38a" ``` While this isn't _wrong_ it is slow for auto instrumented applications to start since the install is from source. It also means all installation dependencies are required and the install could fail. The solution is to run the publishing Github workflow on release after the pypi_upload job. This should ensure that we build an image that uses the release tag and subsequently pip installs with that version rather than from source. The Gitlab job responsible for publishing the image to the other container registries is updated to use the release tag image rather than the SHA. There is and was a race between when the Github registry image is published and when the Gitlab job runs. To mitigate this the Gitlab job is delayed by 1 day to give time for the image to be pushed to the Github registry. ## [fix(ci/lib-injection): add missing runs_on value](d10ec21) The `runs_on` field was missing which caused the 1.7.4 release workflow to fail. To avoid this problem, or problems like this from happening again, the shared logic is pulled into a reusable workflow[0]. Now the build and push logic is shared between the test and publish jobs which will give us a better idea if the publish one works. ## Checklist - [ ] Change(s) are motivated and described in the PR description. - [ ] Testing strategy is described if automated tests are not included in the PR. - [ ] Risk is outlined (performance impact, potential for breakage, maintainability, etc). - [ ] Change is maintainable (easy to change, telemetry, documentation). - [ ] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/contributing.html#Release-Note-Guidelines) are followed. - [ ] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)). ## Reviewer Checklist - [ ] Title is accurate. - [ ] No unnecessary changes are introduced. - [ ] Description motivates each change. - [ ] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [ ] Testing strategy adequately addresses listed risk(s). - [ ] Change is maintainable (easy to change, telemetry, documentation). - [ ] Release note makes sense to a user of the library. --------- Co-authored-by: Yun Kim <[email protected]>
1 parent 4950e58 commit 2385771

File tree

6 files changed

+86
-60
lines changed

6 files changed

+86
-60
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Build and publish image
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
tags:
7+
required: true
8+
type: string
9+
platforms:
10+
required: true
11+
type: string
12+
build-args:
13+
required: true
14+
type: string
15+
context:
16+
required: true
17+
type: string
18+
secrets:
19+
token:
20+
required: true
21+
22+
jobs:
23+
build_push:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v3
27+
- name: Set up QEMU
28+
uses: docker/setup-qemu-action@v2
29+
- name: Set up Docker Buildx
30+
id: buildx
31+
uses: docker/setup-buildx-action@v2
32+
- name: Login to Docker
33+
run: docker login -u publisher -p ${{ secrets.token }} ghcr.io
34+
- name: Docker Build
35+
uses: docker/build-push-action@v3
36+
with:
37+
push: true
38+
tags: ${{ inputs.tags }}
39+
platforms: ${{ inputs.platforms }}
40+
build-args: ${{ inputs.build-args }}
41+
context: ${{ inputs.context }}

.github/workflows/build_deploy.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,16 @@ jobs:
211211
# due to a duplicate wheel being present which will ensure that the rest
212212
# of the wheels will be uploaded if some are uploaded manually.
213213
skip_existing: true
214+
215+
build-and-publish-init-image:
216+
needs: [upload_pypi]
217+
# We have to wait for the PyPI job since the image that we publish depends on installing
218+
# the package from PyPI.
219+
uses: ./.github/workflows/build-and-publish-image.yml
220+
with:
221+
tags: ghcr.io/datadog/dd-trace-py/dd-lib-python-init:${{ github.ref_name }}
222+
platforms: 'linux/amd64,linux/arm64/v8'
223+
build-args: "DDTRACE_PYTHON_VERSION=${{ github.ref_name }}"
224+
context: ./lib-injection
225+
secrets:
226+
token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/lib-injection.yml

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,22 @@
11
name: "Library Injection"
22
on:
3+
# Build each branch for testing
34
push:
45

56
jobs:
6-
build-and-publish-init-image:
7-
runs-on: ubuntu-latest
8-
steps:
9-
- uses: actions/checkout@v3
10-
11-
- name: Set up QEMU
12-
uses: docker/setup-qemu-action@v2
13-
14-
- uses: actions/setup-python@v4
15-
with:
16-
python-version: '3.10'
17-
# required for getting the version
18-
- run: pip install setuptools-scm
19-
- name: Get library version
20-
id: get_version
21-
run: |
22-
DDTRACE_PYTHON_VERSION=$(scripts/get_install_version.py)
23-
echo "library_version=$DDTRACE_PYTHON_VERSION" >> $GITHUB_OUTPUT
24-
25-
- name: Set up Docker Buildx
26-
id: buildx
27-
uses: docker/setup-buildx-action@v2
28-
29-
- name: lib-injection-tags
30-
id: lib-injection-tags
31-
uses: DataDog/system-tests/lib-injection/docker-tags@main
32-
with:
33-
init-image-name: 'dd-lib-python-init'
34-
main-branch-name: '1.x'
35-
36-
- name: Login to Docker
37-
run: docker login -u publisher -p ${{ secrets.GITHUB_TOKEN }} ghcr.io
38-
39-
- name: Docker Build
40-
uses: docker/build-push-action@v3
41-
with:
42-
push: true
43-
tags: ${{ steps.lib-injection-tags.outputs.tag-names }}
44-
platforms: 'linux/amd64,linux/arm64/v8'
45-
build-args: "DDTRACE_PYTHON_VERSION=${{ steps.get_version.outputs.library_version }}"
46-
context: ./lib-injection
7+
build-and-publish-test-image:
8+
uses: ./.github/workflows/build-and-publish-image.yml
9+
with:
10+
tags: 'ghcr.io/datadog/dd-trace-py/dd-lib-python-init:${{ github.sha }}'
11+
platforms: 'linux/amd64,linux/arm64/v8'
12+
build-args: 'DDTRACE_PYTHON_VERSION=git+https://github.com/Datadog/dd-trace-py@${{ github.sha }}'
13+
context: ./lib-injection
14+
secrets:
15+
token: ${{ secrets.GITHUB_TOKEN }}
4716

4817
test:
4918
needs:
50-
- build-and-publish-init-image
19+
- build-and-publish-test-image
5120
runs-on: ubuntu-latest
5221
permissions:
5322
contents: read

.gitlab-ci.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,24 @@ deploy_to_docker_registries:
4646
rules:
4747
- if: '$POPULATE_CACHE'
4848
when: never
49+
# Wait 1 day to trigger the downstream job.
50+
# This is a work-around since there isn't a way to trigger
51+
# Gitlab from the Github workflow (build_deploy.yml:upload_pypi).
52+
#
53+
# The caveat here is that if there is a failure to build to PyPI
54+
# and it isn't fixed in a day then this job will fail and images
55+
# will not be published.
4956
- if: '$CI_COMMIT_TAG =~ /^v.*/'
50-
when: on_success
57+
when: delayed
58+
start_in: 1 day
5159
- when: manual
5260
allow_failure: true
5361
trigger:
5462
project: DataDog/public-images
5563
branch: main
5664
strategy: depend
5765
variables:
58-
IMG_SOURCES: ghcr.io/datadog/dd-trace-py/dd-lib-python-init:$CI_COMMIT_SHA
66+
IMG_SOURCES: ghcr.io/datadog/dd-trace-py/dd-lib-python-init:$CI_COMMIT_TAG
5967
IMG_DESTINATIONS: dd-lib-python-init:$CI_COMMIT_TAG
6068
IMG_SIGNING: "false"
6169

@@ -64,15 +72,17 @@ deploy_latest_tag_to_docker_registries:
6472
rules:
6573
- if: '$POPULATE_CACHE'
6674
when: never
75+
# See above note in the `deploy_to_docker_registries` job.
6776
- if: '$CI_COMMIT_TAG =~ /^v.*/'
68-
when: on_success
77+
when: delayed
78+
start_in: 1 day
6979
- when: manual
7080
allow_failure: true
7181
trigger:
7282
project: DataDog/public-images
7383
branch: main
7484
strategy: depend
7585
variables:
76-
IMG_SOURCES: ghcr.io/datadog/dd-trace-py/dd-lib-python-init:$CI_COMMIT_SHA
86+
IMG_SOURCES: ghcr.io/datadog/dd-trace-py/dd-lib-python-init:$CI_COMMIT_TAG
7787
IMG_DESTINATIONS: dd-lib-python-init:latest
7888
IMG_SIGNING: "false"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
fixes:
3+
- |
4+
lib-injection: Use package versions published to PyPI to install the
5+
library. Formerly the published image was installing the package from
6+
source using the tagged commit SHA which resulted in slow and potentially
7+
failing installs.

scripts/get_install_version.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)