-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
38 lines (28 loc) · 1.38 KB
/
Copy pathDockerfile
File metadata and controls
38 lines (28 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# syntax=docker/dockerfile:1.7
# --platform=$BUILDPLATFORM: run the builder image natively on the CI runner.
FROM --platform=$BUILDPLATFORM golang:1.25-alpine AS build
# Buildx sets these per target platform, for example linux/amd64 or linux/arm64.
ARG TARGETOS
ARG TARGETARCH
WORKDIR /src
COPY go.mod go.sum ./
# type=cache: keep downloaded Go modules in BuildKit cache between image builds.
# target=/go/pkg/mod: Go module download cache location.
RUN --mount=type=cache,target=/go/pkg/mod go mod download
COPY . .
# type=cache,target=/go/pkg/mod: reuse downloaded modules during compile.
# type=cache,target=/root/.cache/go-build: reuse Go compiler build cache.
# CGO_ENABLED=0: build a static binary that works in a small runtime image.
# GOOS/GOARCH: compile for the current Buildx target platform.
# -trimpath: remove local filesystem paths from the binary.
# -ldflags="-s -w": strip symbol/debug tables to reduce binary size.
# -o: write the server binary to the path copied into the runtime stage.
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH \
go build -trimpath -ldflags="-s -w" -o /out/rivet-server ./cmd/rivet-server
FROM alpine:3.22
RUN apk add --no-cache ca-certificates
COPY --from=build /out/rivet-server /usr/local/bin/rivet-server
EXPOSE 3000
ENTRYPOINT ["/usr/local/bin/rivet-server"]