perf: cross-compile for arm64 instead of QEMU emulation, add GHA layer cache

This commit is contained in:
2026-06-29 23:55:08 +02:00
parent f86afd76f3
commit 9effeba4a2
3 changed files with 25 additions and 10 deletions

View File

@@ -69,6 +69,8 @@ jobs:
tags: ${{ env.REGISTRY }}/${{ env.IMAGE }}:tmp-std-amd64
platforms: linux/amd64
provenance: false
cache-from: type=gha,scope=std-amd64
cache-to: type=gha,scope=std-amd64,mode=max
- name: Build standard arm64
uses: docker/build-push-action@v6
@@ -80,6 +82,8 @@ jobs:
tags: ${{ env.REGISTRY }}/${{ env.IMAGE }}:tmp-std-arm64
platforms: linux/arm64
provenance: false
cache-from: type=gha,scope=std-arm64
cache-to: type=gha,scope=std-arm64,mode=max
- name: Build bundled amd64
uses: docker/build-push-action@v6
@@ -91,6 +95,8 @@ jobs:
tags: ${{ env.REGISTRY }}/${{ env.IMAGE }}:tmp-bnd-amd64
platforms: linux/amd64
provenance: false
cache-from: type=gha,scope=bnd-amd64
cache-to: type=gha,scope=bnd-amd64,mode=max
- name: Build bundled arm64
uses: docker/build-push-action@v6
@@ -102,6 +108,8 @@ jobs:
tags: ${{ env.REGISTRY }}/${{ env.IMAGE }}:tmp-bnd-arm64
platforms: linux/arm64
provenance: false
cache-from: type=gha,scope=bnd-arm64
cache-to: type=gha,scope=bnd-arm64,mode=max
- name: Push standard image
if: github.event_name != 'pull_request'

View File

@@ -1,19 +1,23 @@
# ── Build stage ──────────────────────────────────────────────────────────────
FROM node:22-alpine AS ui
# syntax=docker/dockerfile:1
# ── Build stages run on the build host (amd64); Go cross-compiles for TARGETARCH.
# This avoids QEMU emulation and cuts arm64 build time from ~15min to ~2min.
FROM --platform=$BUILDPLATFORM node:22-alpine AS ui
WORKDIR /src/dashboard
COPY backend/dashboard/package*.json ./
RUN npm ci
COPY backend/dashboard/ ./
RUN npm run build
FROM golang:1.24-alpine AS go-build
ENV GOTOOLCHAIN=auto
FROM --platform=$BUILDPLATFORM golang:1.24-alpine AS go-build
ARG TARGETARCH
ENV GOTOOLCHAIN=auto CGO_ENABLED=0 GOARCH=$TARGETARCH
WORKDIR /src
COPY backend/go.mod backend/go.sum ./
RUN go mod download
COPY backend/ .
COPY --from=ui /src/dashboard/../internal/web/dist ./internal/web/dist
RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /lmr ./cmd/server
RUN go build -trimpath -ldflags="-s -w" -o /lmr ./cmd/server
# ── Runtime stage ─────────────────────────────────────────────────────────────
FROM gcr.io/distroless/static-debian12:nonroot

View File

@@ -1,19 +1,22 @@
# ── Build stage ──────────────────────────────────────────────────────────────
FROM node:22-alpine AS ui
# syntax=docker/dockerfile:1
# ── Build stages run on the build host (amd64); Go cross-compiles for TARGETARCH.
FROM --platform=$BUILDPLATFORM node:22-alpine AS ui
WORKDIR /src/dashboard
COPY backend/dashboard/package*.json ./
RUN npm ci
COPY backend/dashboard/ ./
RUN npm run build
FROM golang:1.24-alpine AS go-build
ENV GOTOOLCHAIN=auto
FROM --platform=$BUILDPLATFORM golang:1.24-alpine AS go-build
ARG TARGETARCH
ENV GOTOOLCHAIN=auto CGO_ENABLED=0 GOARCH=$TARGETARCH
WORKDIR /src
COPY backend/go.mod backend/go.sum ./
RUN go mod download
COPY backend/ .
COPY --from=ui /src/dashboard/../internal/web/dist ./internal/web/dist
RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /lmr ./cmd/server
RUN go build -trimpath -ldflags="-s -w" -o /lmr ./cmd/server
# ── Runtime stage (Postgres bundled) ─────────────────────────────────────────
FROM alpine:3.21