Skip to content

Commit

Permalink
RFC: Remove BUILDPLATFORM (#1350)
Browse files Browse the repository at this point in the history
  • Loading branch information
72636c committed Mar 18, 2024
1 parent 34768de commit f137372
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 15 deletions.
24 changes: 24 additions & 0 deletions .changeset/fifty-toys-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
'skuba': patch
---

template: Remove `BUILDPLATFORM` from Dockerfiles

Previously, the built-in templates made use of [`BUILDPLATFORM`](https://docs.docker.com/build/guide/multi-platform/#platform-build-arguments) and a fallback value:

```dockerfile
FROM --platform=${BUILDPLATFORM:-arm64} gcr.io/distroless/nodejs20-debian11
```

1. Choose the platform of the host machine running the Docker build. A vCurrent SEEK build agent or Apple Silicon laptop will build under `arm64`, while an Intel laptop will build under `amd64`.
2. Fall back to `arm64` if the build platform is not available. This maintains compatibility with toolchains like Gantry that lack support for the `BUILDPLATFORM` argument.

This approach allowed you to quickly build images and run containers in a local environment without emulation. For example, you could `docker build` an `arm64` image on an Apple Silicon laptop for local troubleshooting, while your CI/CD solution employed `amd64` hardware across its build and runtime environments. The catch is that your local `arm64` image may exhibit different behaviour, and is unsuitable for use in your `amd64` runtime environment without cross-compilation.

The built-in templates now hardcode `--platform` as we have largely converged on `arm64` across local, build and runtime environments:

```dockerfile
FROM --platform=arm64 gcr.io/distroless/nodejs20-debian11
```

This approach is more explicit and predictable, reducing surprises when working across different environments and toolchains. Building an image on a different platform will be slower and rely on emulation.
6 changes: 3 additions & 3 deletions docs/deep-dives/arm64.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ then ensure that you run your builds on AMD64 hardware:

```diff
- FROM --platform=arm64 gcr.io/distroless/nodejs20-debian12 AS runtime
+ FROM --platform=${BUILDPLATFORM:-amd64} gcr.io/distroless/nodejs20-debian12 AS runtime
+ FROM --platform=amd64 gcr.io/distroless/nodejs20-debian12 AS runtime

- FROM --platform=${BUILDPLATFORM:-arm64} gcr.io/distroless/nodejs20-debian12 AS runtime
+ FROM --platform=${BUILDPLATFORM:-amd64} gcr.io/distroless/nodejs20-debian12 AS runtime
- FROM --platform=arm64 gcr.io/distroless/nodejs20-debian12 AS runtime
+ FROM --platform=amd64 gcr.io/distroless/nodejs20-debian12 AS runtime
```

For a [Gantry] service, modify the `cpuArchitecture` property in your `gantry.build.yml` and `gantry.apply.yml` resource files:
Expand Down
4 changes: 2 additions & 2 deletions docs/deep-dives/pnpm.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ This migration guide assumes that your project was scaffolded with a **skuba** t

<!-- prettier-ignore -->
```diff
FROM --platform=${BUILDPLATFORM:-<%- platformName %>} node:20-alpine AS dev-deps
FROM --platform=arm64 node:20-alpine AS dev-deps

+ RUN corepack enable pnpm
+ RUN pnpm config set store-dir /root/.pnpm-store
Expand Down Expand Up @@ -264,7 +264,7 @@ This migration guide assumes that your project was scaffolded with a **skuba** t

###

FROM --platform=${BUILDPLATFORM:-<%- platformName %>} gcr.io/distroless/nodejs20-debian12 AS runtime
FROM --platform=arm64 gcr.io/distroless/nodejs20-debian12 AS runtime
WORKDIR /workdir

COPY --from=build /workdir/lib lib
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const dockerfileDebian11 = `
ARG BASE_IMAGE
ARG BASE_TAG
FROM --platform=\${BUILDPLATFORM:-<%- platformName %>} gcr.io/distroless/nodejs20-debian11 AS runtime
FROM --platform=<%- platformName %> gcr.io/distroless/nodejs20-debian11 AS runtime
WORKDIR /workdir
`;
Expand All @@ -31,7 +31,7 @@ const dockerfileNonDistroless = `
ARG BASE_IMAGE
ARG BASE_TAG
FROM --platform=\${BUILDPLATFORM:-<%- platformName %>} node:20-alpine AS runtime
FROM --platform=\${BUILDPLATFORM:-arm64} node:20-alpine AS runtime
WORKDIR /workdir
`;
Expand Down Expand Up @@ -72,7 +72,7 @@ describe('tryPatchDockerfile', () => {
ARG BASE_IMAGE
ARG BASE_TAG
FROM --platform=\${BUILDPLATFORM:-<%- platformName %>} gcr.io/distroless/nodejs20-debian12 AS runtime
FROM --platform=<%- platformName %> gcr.io/distroless/nodejs20-debian12 AS runtime
WORKDIR /workdir
",
Expand Down
2 changes: 1 addition & 1 deletion template/express-rest-api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RUN pnpm install --offline --prod

###

FROM --platform=${BUILDPLATFORM:-<%- platformName %>} gcr.io/distroless/nodejs20-debian12 AS runtime
FROM --platform=<%- platformName %> gcr.io/distroless/nodejs20-debian12 AS runtime

WORKDIR /workdir

Expand Down
2 changes: 1 addition & 1 deletion template/express-rest-api/Dockerfile.dev-deps
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# syntax=docker/dockerfile:1.7

FROM --platform=${BUILDPLATFORM:-<%- platformName %>} node:20-alpine AS dev-deps
FROM --platform=<%- platformName %> node:20-alpine AS dev-deps

RUN corepack enable pnpm
RUN pnpm config set store-dir /root/.pnpm-store
Expand Down
2 changes: 1 addition & 1 deletion template/greeter/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# syntax=docker/dockerfile:1.7

FROM --platform=${BUILDPLATFORM:-<%- platformName %>} node:20-alpine AS dev-deps
FROM --platform=<%- platformName %> node:20-alpine AS dev-deps

RUN corepack enable pnpm
RUN pnpm config set store-dir /root/.pnpm-store
Expand Down
2 changes: 1 addition & 1 deletion template/koa-rest-api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RUN pnpm install --offline --prod

###

FROM --platform=${BUILDPLATFORM:-<%- platformName %>} gcr.io/distroless/nodejs20-debian12 AS runtime
FROM --platform=<%- platformName %> gcr.io/distroless/nodejs20-debian12 AS runtime

WORKDIR /workdir

Expand Down
2 changes: 1 addition & 1 deletion template/koa-rest-api/Dockerfile.dev-deps
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# syntax=docker/dockerfile:1.7

FROM --platform=${BUILDPLATFORM:-<%- platformName %>} node:20-alpine AS dev-deps
FROM --platform=<%- platformName %> node:20-alpine AS dev-deps

RUN corepack enable pnpm
RUN pnpm config set store-dir /root/.pnpm-store
Expand Down
2 changes: 1 addition & 1 deletion template/lambda-sqs-worker-cdk/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# syntax=docker/dockerfile:1.7

FROM --platform=${BUILDPLATFORM:-<%- platformName %>} node:20-alpine AS dev-deps
FROM --platform=<%- platformName %> node:20-alpine AS dev-deps

# Needed for cdk
RUN apk add --no-cache bash
Expand Down
2 changes: 1 addition & 1 deletion template/lambda-sqs-worker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# syntax=docker/dockerfile:1.7

FROM --platform=${BUILDPLATFORM:-<%- platformName %>} node:20-alpine AS dev-deps
FROM --platform=<%- platformName %> node:20-alpine AS dev-deps

RUN corepack enable pnpm
RUN pnpm config set store-dir /root/.pnpm-store
Expand Down

0 comments on commit f137372

Please sign in to comment.