Skip to content

Commit

Permalink
Specify Docker architecture explicitly in Makefile tasks (#1297)
Browse files Browse the repository at this point in the history
Currently when any of the Docker related `Makefile` targets are invoked
from a machine that is not using the AMD64 (x86-64) architecture (such
as a machine using the Apple M1), it emits the following warning:

```
WARNING: The requested image's platform (linux/amd64) does not match the
detected host platform (linux/arm64/v8) and no specific platform was requested
```

In addition, were the `heroku/heroku:*` images ever to support ARM64
(see heroku/base-images#194), relying on an
implicit platform value would mean the runtime generation tasks would
silently start to generate binaries for a different architecture.

To prevent this warning, and prevent such surprises with binary
generation, the platform is now specified explicitly using `--platform`.

GUS-W-10884947.
  • Loading branch information
edmorley authored Mar 23, 2022
1 parent 6d97414 commit e4397d6
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

STACK ?= heroku-20
STACKS ?= heroku-18 heroku-20
PLATFORM := linux/amd64
FIXTURE ?= spec/fixtures/python_version_unspecified
ENV_FILE ?= builds/dockerenv.default
BUILDER_IMAGE_PREFIX := heroku-python-build
Expand All @@ -23,14 +24,14 @@ lint-ruby:
compile:
@echo "Running compile using: STACK=$(STACK) FIXTURE=$(FIXTURE)"
@echo
@docker run --rm -it -v $(PWD):/src:ro -e "STACK=$(STACK)" -w /buildpack "$(STACK_IMAGE_TAG)" \
@docker run --rm -it -v $(PWD):/src:ro -e "STACK=$(STACK)" -w /buildpack --platform="$(PLATFORM)" "$(STACK_IMAGE_TAG)" \
bash -c 'cp -r /src/{bin,vendor} /buildpack && cp -r /src/$(FIXTURE) /build && mkdir /cache /env && bin/compile /build /cache /env'
@echo

builder-image:
@echo "Generating binary builder image for $(STACK)..."
@echo
@docker build --pull -f builds/$(STACK).Dockerfile -t "$(BUILDER_IMAGE_PREFIX)-$(STACK)" .
@docker build --pull -f builds/$(STACK).Dockerfile --platform="$(PLATFORM)" -t "$(BUILDER_IMAGE_PREFIX)-$(STACK)" .
@echo

buildenv: builder-image
Expand All @@ -40,7 +41,7 @@ buildenv: builder-image
@echo
@echo " $$ bob build runtimes/python-X.Y.Z"
@echo
@docker run --rm -it --env-file="$(ENV_FILE)" -v $(PWD)/builds:/app/builds "$(BUILDER_IMAGE_PREFIX)-$(STACK)" bash
@docker run --rm -it --env-file="$(ENV_FILE)" -v $(PWD)/builds:/app/builds --platform="$(PLATFORM)" "$(BUILDER_IMAGE_PREFIX)-$(STACK)" bash

deploy-runtimes:
ifndef RUNTIMES
Expand All @@ -53,7 +54,7 @@ endif
for runtime in $(RUNTIMES); do \
echo "Generating/deploying $${runtime} for $${stack}..."; \
echo; \
docker run --rm -it --env-file="$(ENV_FILE)" "$(BUILDER_IMAGE_PREFIX)-$${stack}" bob deploy "runtimes/$${runtime}"; \
docker run --rm -it --env-file="$(ENV_FILE)" --platform="$(PLATFORM)" "$(BUILDER_IMAGE_PREFIX)-$${stack}" bob deploy "runtimes/$${runtime}"; \
echo; \
done; \
done
Expand Down

0 comments on commit e4397d6

Please sign in to comment.