Skip to content
Merged
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 .ci/docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

> :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,
> :information_source: This script is mainly used in [publish-docker-images](https://github.com/elastic/apm-agent-python/actions/workflows/build-images.yml) workflow,
which can be triggered safely at any time.

## Options
Expand Down
1 change: 1 addition & 0 deletions .ci/docker/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ for version in $versions; do
case $ACTION in
build)
DOCKER_BUILDKIT=1 docker build \
--progress=plain \
--cache-from="${full_image_name}" \
-f "${project_root}/tests/Dockerfile" \
--build-arg PYTHON_IMAGE="${version/-/:}" \
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/build-images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
name: build-images

on:
workflow_dispatch: ~

permissions:
contents: read

jobs:

build-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}/apm-agent-python-testing
steps:

- uses: actions/checkout@v4

- name: Login to ghcr.io
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- run: ./util.sh --action build --registry ${{ env.REGISTRY }} --name ${{ env.IMAGE_NAME }}
working-directory: .ci/docker

- run: ./util.sh --action push --registry ${{ env.REGISTRY }} --name ${{ env.IMAGE_NAME }}
working-directory: .ci/docker
4 changes: 4 additions & 0 deletions .github/workflows/run-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ jobs:
max-parallel: 10
matrix:
include: ${{ fromJSON(inputs.include) }}
env:
# These env variables are used in the docker-compose.yml and the run_tests.sh script.
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}/apm-agent-python-testing
steps:
- uses: actions/checkout@v4
- name: Run tests
Expand Down
3 changes: 3 additions & 0 deletions tests/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,7 @@ RUN chmod +x /usr/local/bin/entrypoint.sh

WORKDIR /app

# configure the label to help with the GitHub container registry
LABEL org.opencontainers.image.source https://github.com/elastic/apm-agent-python

ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
2 changes: 1 addition & 1 deletion tests/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ services:
- zookeeper

run_tests:
image: elasticobservability/apm-agent-python-testing:${PYTHON_VERSION}
image: ${REGISTRY:-elasticobservability}/${IMAGE_NAME:-apm-agent-python-testing}:${PYTHON_VERSION}
environment:
ES_8_URL: 'http://elasticsearch8:9200'
ES_7_URL: 'http://elasticsearch7:9200'
Expand Down
17 changes: 11 additions & 6 deletions tests/scripts/docker/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -ex

function cleanup {
PYTHON_VERSION=${1} docker compose down -v
PYTHON_VERSION=${1} REGISTRY=${REGISTRY} IMAGE_NAME=${IMAGE_NAME} docker compose down -v

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

cd tests

Expand All @@ -38,26 +40,27 @@ else
fi
fi

echo "Running tests for ${1}/${2}"
echo "Running tests for ${TEST}"

if [[ -n $DOCKER_DEPS ]]
then
PYTHON_VERSION=${1} docker compose up -d ${DOCKER_DEPS}
PYTHON_VERSION=${1} REGISTRY=${REGISTRY} IMAGE_NAME=${IMAGE_NAME} docker compose up --quiet-pull -d ${DOCKER_DEPS}
fi

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

if ! ${CI}; then
full_image_name="${REGISTRY}/${IMAGE_NAME}:${1}"
DOCKER_BUILDKIT=1 docker build \
--progress=plain \
--cache-from="elasticobservability/apm-agent-python-testing:${1}" \
--cache-from="${full_image_name}" \
--build-arg PYTHON_IMAGE="${1/-/:}" \
--tag "elasticobservability/apm-agent-python-testing:${1}" \
--tag "${full_image_name}" \
.
fi

PYTHON_VERSION=${1} docker compose run \
PYTHON_VERSION=${1} docker compose run --quiet-pull \
-e PYTHON_FULL_VERSION=${1} \
-e LOCAL_USER_ID=$LOCAL_USER_ID \
-e LOCAL_GROUP_ID=$LOCAL_GROUP_ID \
Expand All @@ -67,6 +70,8 @@ PYTHON_VERSION=${1} docker compose run \
-e WITH_COVERAGE=true \
-e CASS_DRIVER_NO_EXTENSIONS=1 \
-e PYTEST_JUNIT="--junitxml=/app/tests/docker-${1}-${2}-python-agent-junit.xml" \
-e REGISTRY=${REGISTRY} \
-e IMAGE_NAME=${IMAGE_NAME} \
-v ${pip_cache}:$(dirname ${docker_pip_cache}) \
-v "$(dirname $(pwd))":/app \
--rm run_tests \
Expand Down
Loading