Skip to content

Commit abe4bb3

Browse files
authored
github-actions: use GitHub container registry (#2266)
1 parent a172025 commit abe4bb3

File tree

7 files changed

+56
-8
lines changed

7 files changed

+56
-8
lines changed

.ci/docker/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Utility script for building and pushing the images based on `.ci/.matrix_python_full.yml`.
44

5-
> :information_source: This script is mainly used in [publish-docker-images](https://github.com/elastic/apm-pipeline-library/actions/workflows/publish-docker-images.yml) workflow,
5+
> :information_source: This script is mainly used in [publish-docker-images](https://github.com/elastic/apm-agent-python/actions/workflows/build-images.yml) workflow,
66
which can be triggered safely at any time.
77

88
## Options

.ci/docker/util.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ for version in $versions; do
4444
case $ACTION in
4545
build)
4646
DOCKER_BUILDKIT=1 docker build \
47+
--progress=plain \
4748
--cache-from="${full_image_name}" \
4849
-f "${project_root}/tests/Dockerfile" \
4950
--build-arg PYTHON_IMAGE="${version/-/:}" \

.github/workflows/build-images.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
name: build-images
3+
4+
on:
5+
workflow_dispatch: ~
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
12+
build-push:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
16+
packages: write
17+
env:
18+
REGISTRY: ghcr.io
19+
IMAGE_NAME: ${{ github.repository }}/apm-agent-python-testing
20+
steps:
21+
22+
- uses: actions/checkout@v4
23+
24+
- name: Login to ghcr.io
25+
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
26+
with:
27+
registry: ${{ env.REGISTRY }}
28+
username: ${{ github.actor }}
29+
password: ${{ secrets.GITHUB_TOKEN }}
30+
31+
- run: ./util.sh --action build --registry ${{ env.REGISTRY }} --name ${{ env.IMAGE_NAME }}
32+
working-directory: .ci/docker
33+
34+
- run: ./util.sh --action push --registry ${{ env.REGISTRY }} --name ${{ env.IMAGE_NAME }}
35+
working-directory: .ci/docker

.github/workflows/run-matrix.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ jobs:
2020
max-parallel: 10
2121
matrix:
2222
include: ${{ fromJSON(inputs.include) }}
23+
env:
24+
# These env variables are used in the docker-compose.yml and the run_tests.sh script.
25+
REGISTRY: ghcr.io
26+
IMAGE_NAME: ${{ github.repository }}/apm-agent-python-testing
2327
steps:
2428
- uses: actions/checkout@v4
2529
- name: Run tests

tests/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,7 @@ RUN chmod +x /usr/local/bin/entrypoint.sh
4444

4545
WORKDIR /app
4646

47+
# configure the label to help with the GitHub container registry
48+
LABEL org.opencontainers.image.source https://github.com/elastic/apm-agent-python
49+
4750
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

tests/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ services:
185185
- zookeeper
186186

187187
run_tests:
188-
image: elasticobservability/apm-agent-python-testing:${PYTHON_VERSION}
188+
image: ${REGISTRY:-elasticobservability}/${IMAGE_NAME:-apm-agent-python-testing}:${PYTHON_VERSION}
189189
environment:
190190
ES_8_URL: 'http://elasticsearch8:9200'
191191
ES_7_URL: 'http://elasticsearch7:9200'

tests/scripts/docker/run_tests.sh

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
set -ex
33

44
function cleanup {
5-
PYTHON_VERSION=${1} docker compose down -v
5+
PYTHON_VERSION=${1} REGISTRY=${REGISTRY} IMAGE_NAME=${IMAGE_NAME} docker compose down -v
66

77
if [[ $CODECOV_TOKEN ]]; then
88
cd ..
@@ -21,6 +21,8 @@ docker_pip_cache="/tmp/cache/pip"
2121
TEST="${1}/${2}"
2222
LOCAL_USER_ID=${LOCAL_USER_ID:=$(id -u)}
2323
LOCAL_GROUP_ID=${LOCAL_GROUP_ID:=$(id -g)}
24+
IMAGE_NAME=${IMAGE_NAME:-"apm-agent-python-testing"}
25+
REGISTRY=${REGISTRY:-"elasticobservability"}
2426

2527
cd tests
2628

@@ -38,26 +40,27 @@ else
3840
fi
3941
fi
4042

41-
echo "Running tests for ${1}/${2}"
43+
echo "Running tests for ${TEST}"
4244

4345
if [[ -n $DOCKER_DEPS ]]
4446
then
45-
PYTHON_VERSION=${1} docker compose up -d ${DOCKER_DEPS}
47+
PYTHON_VERSION=${1} REGISTRY=${REGISTRY} IMAGE_NAME=${IMAGE_NAME} docker compose up --quiet-pull -d ${DOCKER_DEPS}
4648
fi
4749

4850
# CASS_DRIVER_NO_EXTENSIONS is set so we don't build the Cassandra C-extensions,
4951
# as this can take several minutes
5052

5153
if ! ${CI}; then
54+
full_image_name="${REGISTRY}/${IMAGE_NAME}:${1}"
5255
DOCKER_BUILDKIT=1 docker build \
5356
--progress=plain \
54-
--cache-from="elasticobservability/apm-agent-python-testing:${1}" \
57+
--cache-from="${full_image_name}" \
5558
--build-arg PYTHON_IMAGE="${1/-/:}" \
56-
--tag "elasticobservability/apm-agent-python-testing:${1}" \
59+
--tag "${full_image_name}" \
5760
.
5861
fi
5962

60-
PYTHON_VERSION=${1} docker compose run \
63+
PYTHON_VERSION=${1} docker compose run --quiet-pull \
6164
-e PYTHON_FULL_VERSION=${1} \
6265
-e LOCAL_USER_ID=$LOCAL_USER_ID \
6366
-e LOCAL_GROUP_ID=$LOCAL_GROUP_ID \
@@ -67,6 +70,8 @@ PYTHON_VERSION=${1} docker compose run \
6770
-e WITH_COVERAGE=true \
6871
-e CASS_DRIVER_NO_EXTENSIONS=1 \
6972
-e PYTEST_JUNIT="--junitxml=/app/tests/docker-${1}-${2}-python-agent-junit.xml" \
73+
-e REGISTRY=${REGISTRY} \
74+
-e IMAGE_NAME=${IMAGE_NAME} \
7075
-v ${pip_cache}:$(dirname ${docker_pip_cache}) \
7176
-v "$(dirname $(pwd))":/app \
7277
--rm run_tests \

0 commit comments

Comments
 (0)