Skip to content

Commit f5bd393

Browse files
committed
refactor(vermeer): cross-compile Docker binaries
- pin the Go builder to the native build platform - cross-compile binaries for each requested target platform - cache Go modules and compiler artifacts across builds - isolate UI dependency downloads from source changes
1 parent b636712 commit f5bd393

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

vermeer/Dockerfile

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,27 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616
#
17-
FROM golang:1.23-alpine AS builder
17+
FROM --platform=$BUILDPLATFORM golang:1.23-alpine AS builder
18+
ARG TARGETOS
19+
ARG TARGETARCH
1820
RUN apk add --no-cache npm bash curl
19-
COPY ./ /src/
2021
WORKDIR /src/
2122
ENV CGO_ENABLED="0"
23+
24+
COPY go.mod go.sum ./
25+
RUN --mount=type=cache,target=/go/pkg/mod go mod download
26+
27+
COPY scripts/download_ui_assets.sh ./scripts/
28+
COPY ui/package.json ./ui/
2229
RUN ./scripts/download_ui_assets.sh
23-
RUN cd asset && go generate
24-
RUN go build -o /go/bin/app
30+
31+
COPY ./ ./
32+
RUN --mount=type=cache,target=/go/pkg/mod \
33+
--mount=type=cache,target=/root/.cache/go-build \
34+
cd asset && go generate
35+
RUN --mount=type=cache,target=/go/pkg/mod \
36+
--mount=type=cache,target=/root/.cache/go-build \
37+
GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o /go/bin/app
2538

2639
FROM alpine
2740
EXPOSE 8080

0 commit comments

Comments
 (0)