diff --git a/.ci/docker/README.md b/.ci/docker/README.md index 1241a7f05..9ca435c1c 100644 --- a/.ci/docker/README.md +++ b/.ci/docker/README.md @@ -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 diff --git a/.ci/docker/util.sh b/.ci/docker/util.sh index 9326a5773..865e4d884 100755 --- a/.ci/docker/util.sh +++ b/.ci/docker/util.sh @@ -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/-/:}" \ diff --git a/.github/workflows/build-images.yml b/.github/workflows/build-images.yml new file mode 100644 index 000000000..44dcb39be --- /dev/null +++ b/.github/workflows/build-images.yml @@ -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 diff --git a/.github/workflows/run-matrix.yml b/.github/workflows/run-matrix.yml index 0b31f4318..3dc3befb7 100644 --- a/.github/workflows/run-matrix.yml +++ b/.github/workflows/run-matrix.yml @@ -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 diff --git a/tests/Dockerfile b/tests/Dockerfile index cf1a8e30b..c5cd8050a 100644 --- a/tests/Dockerfile +++ b/tests/Dockerfile @@ -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"] diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml index c6598a969..b65a97e9e 100644 --- a/tests/docker-compose.yml +++ b/tests/docker-compose.yml @@ -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' diff --git a/tests/scripts/docker/run_tests.sh b/tests/scripts/docker/run_tests.sh index de518dc32..9de251f02 100755 --- a/tests/scripts/docker/run_tests.sh +++ b/tests/scripts/docker/run_tests.sh @@ -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 .. @@ -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 @@ -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 \ @@ -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 \