|
12 | 12 | # See the License for the specific language governing permissions and
|
13 | 13 | # limitations under the License.
|
14 | 14 |
|
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}) |
18 | 28 |
|
19 | 29 | .PHONY: default
|
20 | 30 | default: test
|
21 | 31 |
|
22 |
| -# Perform a shortened build for testing |
23 | 32 | .PHONY: build
|
24 | 33 | 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}' |
37 | 38 |
|
| 39 | +# Run the local tag as a container. |
38 | 40 | .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 |
40 | 50 | @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 \ |
42 | 53 | --workdir=/home/github/python-agent \
|
43 | 54 | --add-host=host.docker.internal:host-gateway \
|
44 | 55 | -e NEW_RELIC_HOST="${NEW_RELIC_HOST}" \
|
45 | 56 | -e NEW_RELIC_LICENSE_KEY="${NEW_RELIC_LICENSE_KEY}" \
|
46 | 57 | -e NEW_RELIC_DEVELOPER_MODE="${NEW_RELIC_DEVELOPER_MODE}" \
|
47 | 58 | -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."' |
0 commit comments