Skip to content

Commit

Permalink
Remove --arch in favor of DOCKER_DEFAULT_PLATFORM env var
Browse files Browse the repository at this point in the history
  • Loading branch information
GaretJax committed May 24, 2023
1 parent 82a9f80 commit 7b728f0
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Changelog
=========


2023-05-24
----------

* Removed `--arch` param from `./build.py` in favor of Docker's
`DOCKER_DEFAULT_PLATFORM` environment variable.


2023-05-11
----------

Expand Down
5 changes: 3 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ To locally build an image, run the following command::

./build.py --repo divio/base --tag 0.00-py3.6-alpine3.7 build

To build for a specific architecture (eg. ARM64), add `--arch` flag::
To build for a different architecture then your machine's one, set the
`DOCKER_DEFAULT_PLATFORM` environment variable::

./build.py --repo divio/base --arch arm64 --tag 1.1-py3.11-slim-bullseye build
DOCKER_DEFAULT_PLATFORM=linux/arm64 ./build.py --repo divio/base --tag 1.1-py3.11-slim-bullseye build

Check `./build.py --help` for additional information.

Expand Down
13 changes: 2 additions & 11 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,14 @@ def get_context_path_from_tag(tag):
return directory


def get_build_command(repo, tag, target, arch):
def get_build_command(repo, tag, target):
return [
"docker",
"build",
"-t",
get_image_name(repo, tag, target),
"--build-arg",
"TARGET={}".format(target),
"--build-arg",
"TARGETARCH={}".format(arch),
"--no-cache",
get_context_path_from_tag(tag=tag),
]
Expand Down Expand Up @@ -124,11 +122,6 @@ def main():
default=os.environ.get("TARGET", "prod"),
help="The build target (dev or prod).",
)
parser.add_argument(
"--arch",
default=os.environ.get("ARCH", "amd64"),
help="The build architecture (amd64, arm64, x86_64 etc).",
)

args = parser.parse_args()

Expand All @@ -144,7 +137,6 @@ def main():
repo = str(args.repo)
tag = str(args.tag)
target = str(args.target)
arch = str(args.arch)
if not (repo and tag and target):
print("Missing parameters!")
exit(code=1)
Expand All @@ -157,15 +149,14 @@ def main():

if operation == "build":
command = get_build_command(
repo=repo, tag=tag, target=target, arch=arch
repo=repo, tag=tag, target=target
)
elif operation == "test":
command = get_test_command(repo=repo, tag=tag, target=target)

print("repo: {}".format(repo))
print("tag: {}".format(tag))
print("target: {}".format(target))
print("arch: {}".format(arch))
print("command:")
print(" ".join(command))
os.execvp(command[0], command)
Expand Down
2 changes: 1 addition & 1 deletion py3.10-slim-bullseye/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
FROM python:3.10.11-slim-bullseye AS build

ARG TARGET=prod
ARG TARGETARCH=amd64
ARG TARGETARCH

ENV PYTHONUNBUFFERED=1 \
PATH=/root/.local/bin:$PATH \
Expand Down
2 changes: 1 addition & 1 deletion py3.11-slim-bullseye/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
FROM python:3.11.3-slim-bullseye AS build

ARG TARGET=prod
ARG TARGETARCH=amd64
ARG TARGETARCH

ENV PYTHONUNBUFFERED=1 \
PATH=/root/.local/bin:$PATH \
Expand Down
2 changes: 1 addition & 1 deletion py3.8-slim-buster/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
FROM python:3.8.16-slim-buster AS build

ARG TARGET=prod
ARG TARGETARCH=amd64
ARG TARGETARCH

ENV PYTHONUNBUFFERED=1 \
PATH=/root/.local/bin:$PATH \
Expand Down
2 changes: 1 addition & 1 deletion py3.9-slim-buster/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
FROM python:3.9.16-slim-buster AS build

ARG TARGET=prod
ARG TARGETARCH=amd64
ARG TARGETARCH

ENV PYTHONUNBUFFERED=1 \
PATH=/root/.local/bin:$PATH \
Expand Down

0 comments on commit 7b728f0

Please sign in to comment.