Skip to content

Commit 883af8d

Browse files
silverwindclaudeTheFox0x7
authored
Fix multi-arch Docker build SIGILL by splitting frontend stage (#36646)
## Summary - Split Dockerfile and Dockerfile.rootless into a two-stage build: frontend assets are built on the native platform (`$BUILDPLATFORM`) then copied to the per-architecture backend build stage - This avoids running esbuild/webpack under QEMU emulation which causes SIGILL (Invalid machine instruction) on arm64/riscv64 - Frontend assets (JS/CSS/fonts) are platform-independent so they only need to be built once - The `build-env` stage no longer needs `nodejs`/`pnpm` since it only builds the Go backend Signed-off-by: silverwind <me@silverwind.io> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: TheFox0x7 <thefox0x7@gmail.com>
1 parent 1b874d1 commit 883af8d

2 files changed

Lines changed: 24 additions & 15 deletions

File tree

Dockerfile

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# syntax=docker/dockerfile:1
2-
# Build stage
2+
# Build frontend on the native platform to avoid QEMU-related issues with esbuild/webpack
3+
FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.26-alpine3.23 AS frontend-build
4+
RUN apk --no-cache add build-base git nodejs pnpm
5+
WORKDIR /src
6+
COPY --exclude=.git/ . .
7+
RUN --mount=type=cache,target=/root/.local/share/pnpm/store make frontend
8+
9+
# Build backend for each target platform
310
FROM docker.io/library/golang:1.26-alpine3.23 AS build-env
411

512
ARG GOPROXY=direct
@@ -12,22 +19,19 @@ ARG CGO_EXTRA_CFLAGS
1219
# Build deps
1320
RUN apk --no-cache add \
1421
build-base \
15-
git \
16-
nodejs \
17-
pnpm
22+
git
1823

1924
WORKDIR ${GOPATH}/src/code.gitea.io/gitea
20-
# Use COPY but not "mount" because some directories like "node_modules" contain platform-depended contents and these directories need to be ignored.
21-
# ".git" directory will be mounted later separately for getting version data.
22-
# TODO: in the future, maybe we can pre-build the frontend assets on one platform and share them for different platforms, the benefit is that it won't be affected by webpack plugin compatibility problems, then the working directory can be fully mounted and the COPY is not needed.
25+
# Use COPY instead of bind mount as read-only one breaks makefile state tracking and read-write one needs binary to be moved as it's discarded.
26+
# ".git" directory is mounted separately later only for version data extraction.
2327
COPY --exclude=.git/ . .
28+
COPY --from=frontend-build /src/public/assets public/assets
2429

2530
# Build gitea, .git mount is required for version data
2631
RUN --mount=type=cache,target=/go/pkg/mod \
2732
--mount=type=cache,target="/root/.cache/go-build" \
28-
--mount=type=cache,target=/root/.local/share/pnpm/store \
2933
--mount=type=bind,source=".git/",target=".git/" \
30-
make
34+
make backend
3135

3236
COPY docker/root /tmp/local
3337

Dockerfile.rootless

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# syntax=docker/dockerfile:1
2-
# Build stage
2+
# Build frontend on the native platform to avoid QEMU-related issues with esbuild/webpack
3+
FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.26-alpine3.23 AS frontend-build
4+
RUN apk --no-cache add build-base git nodejs pnpm
5+
WORKDIR /src
6+
COPY --exclude=.git/ . .
7+
RUN --mount=type=cache,target=/root/.local/share/pnpm/store make frontend
8+
9+
# Build backend for each target platform
310
FROM docker.io/library/golang:1.26-alpine3.23 AS build-env
411

512
ARG GOPROXY=direct
@@ -12,20 +19,18 @@ ARG CGO_EXTRA_CFLAGS
1219
# Build deps
1320
RUN apk --no-cache add \
1421
build-base \
15-
git \
16-
nodejs \
17-
pnpm
22+
git
1823

1924
WORKDIR ${GOPATH}/src/code.gitea.io/gitea
2025
# See the comments in Dockerfile
2126
COPY --exclude=.git/ . .
27+
COPY --from=frontend-build /src/public/assets public/assets
2228

2329
# Build gitea, .git mount is required for version data
2430
RUN --mount=type=cache,target=/go/pkg/mod \
2531
--mount=type=cache,target="/root/.cache/go-build" \
26-
--mount=type=cache,target=/root/.local/share/pnpm/store \
2732
--mount=type=bind,source=".git/",target=".git/" \
28-
make
33+
make backend
2934

3035
COPY docker/rootless /tmp/local
3136

0 commit comments

Comments
 (0)