Skip to content

Commit 13e9891

Browse files
Update CI Image (#930)
* Update available python versions in CI * Update makefile with overrides * Fix default branch detection for arm builds --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent d577a69 commit 13e9891

File tree

3 files changed

+44
-21
lines changed

3 files changed

+44
-21
lines changed

.github/containers/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ RUN echo 'eval "$(pyenv init -)"' >>$HOME/.bashrc && \
9696
pyenv update
9797

9898
# Install Python
99-
ARG PYTHON_VERSIONS="3.10 3.9 3.8 3.7 3.11 2.7 pypy2.7-7.3.12 pypy3.8-7.3.11"
99+
ARG PYTHON_VERSIONS="3.11 3.10 3.9 3.8 3.7 3.12 2.7 pypy2.7-7.3.12 pypy3.8-7.3.11"
100100
COPY --chown=1000:1000 --chmod=+x ./install-python.sh /tmp/install-python.sh
101101
RUN /tmp/install-python.sh && \
102102
rm /tmp/install-python.sh

.github/containers/Makefile

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,37 +12,60 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
# Repository root for mounting into container.
16-
MAKEFILE_DIR:=$(dir $(realpath $(firstword $(MAKEFILE_LIST))))
17-
REPO_ROOT:=$(realpath $(MAKEFILE_DIR)../../)
15+
# Override constants
16+
PLATFORM_OVERRIDE:=
17+
PYTHON_VERSIONS_OVERRIDE:=
18+
19+
# Computed variables
20+
IMAGE_NAME:=ghcr.io/newrelic/newrelic-python-agent-ci
21+
MAKEFILE_DIR:=$(dir $(realpath $(firstword ${MAKEFILE_LIST})))
22+
REPO_ROOT:=$(realpath ${MAKEFILE_DIR}../../)
23+
UNAME_P:=$(shell uname -p)
24+
PLATFORM_AUTOMATIC:=$(if $(findstring arm,${UNAME_P}),linux/arm64,linux/amd64)
25+
PLATFORM:=$(if ${PLATFORM_OVERRIDE},${PLATFORM_OVERRIDE},${PLATFORM_AUTOMATIC})
26+
PYTHON_VERSIONS_AUTOMATIC:=3.10 2.7
27+
PYTHON_VERSIONS:=$(if ${PYTHON_VERSIONS_OVERRIDE},${PYTHON_VERSIONS_OVERRIDE},${PYTHON_VERSIONS_AUTOMATIC})
1828

1929
.PHONY: default
2030
default: test
2131

22-
# Perform a shortened build for testing
2332
.PHONY: build
2433
build:
25-
@docker build $(MAKEFILE_DIR) \
26-
-t ghcr.io/newrelic/newrelic-python-agent-ci:local \
27-
--build-arg='PYTHON_VERSIONS=3.10 2.7'
28-
29-
# Ensure python versions are usable
30-
.PHONY: test
31-
test: build
32-
@docker run --rm ghcr.io/newrelic/python-agent-ci:local /bin/bash -c '\
33-
python3.10 --version && \
34-
python2.7 --version && \
35-
touch tox.ini && tox --version && \
36-
echo "Success! Python versions installed."'
34+
@docker build ${MAKEFILE_DIR} \
35+
--platform=${PLATFORM} \
36+
-t ${IMAGE_NAME}:local \
37+
--build-arg='PYTHON_VERSIONS=${PYTHON_VERSIONS}'
3738

39+
# Run the local tag as a container.
3840
.PHONY: run
39-
run: build
41+
run: run.local
42+
43+
# Run a specific tag as a container.
44+
# Usage: make run.<tag>
45+
# Defaults to run.local, but can instead be run.latest or any other tag.
46+
.PHONY: run.%
47+
run.%:
48+
# Build image if local was specified, else pull latest
49+
@if [[ "$*" = "local" ]]; then cd ${MAKEFILE_DIR} && $(MAKE) build; else docker pull ${IMAGE_NAME}:$*; fi
4050
@docker run --rm -it \
41-
--mount type=bind,source="$(REPO_ROOT)",target=/home/github/python-agent \
51+
--platform=${PLATFORM} \
52+
--mount type=bind,source="${REPO_ROOT}",target=/home/github/python-agent \
4253
--workdir=/home/github/python-agent \
4354
--add-host=host.docker.internal:host-gateway \
4455
-e NEW_RELIC_HOST="${NEW_RELIC_HOST}" \
4556
-e NEW_RELIC_LICENSE_KEY="${NEW_RELIC_LICENSE_KEY}" \
4657
-e NEW_RELIC_DEVELOPER_MODE="${NEW_RELIC_DEVELOPER_MODE}" \
4758
-e GITHUB_ACTIONS="true" \
48-
ghcr.io/newrelic/newrelic-python-agent-ci:local /bin/bash
59+
${IMAGE_NAME}:$* /bin/bash
60+
61+
# Ensure python versions are usable. Cannot be automatically used with PYTHON_VERSIONS_OVERRIDE.
62+
.PHONY: test
63+
test: build
64+
@docker run --rm \
65+
--platform=${PLATFORM} \
66+
ghcr.io/newrelic/python-agent-ci:local \
67+
/bin/bash -c '\
68+
python3.10 --version && \
69+
python2.7 --version && \
70+
touch tox.ini && tox --version && \
71+
echo "Success! Python versions installed."'

.github/workflows/build-ci-image.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@ jobs:
6363
with:
6464
push: ${{ github.event_name != 'pull_request' }}
6565
context: .github/containers
66-
platforms: ${{ (github.ref == 'refs/head/main') && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
66+
platforms: ${{ (format('refs/heads/{0}', github.event.repository.default_branch) == github.ref) && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
6767
tags: ${{ steps.meta.outputs.tags }}
6868
labels: ${{ steps.meta.outputs.labels }}

0 commit comments

Comments
 (0)