39 lines
1.2 KiB
Docker
39 lines
1.2 KiB
Docker
# syntax=docker/dockerfile:1.7
|
|
|
|
########################
|
|
# builder
|
|
########################
|
|
FROM --platform=$BUILDPLATFORM golang:1.22-bookworm AS build
|
|
ARG TARGETOS
|
|
ARG TARGETARCH
|
|
ARG TARGETVARIANT
|
|
|
|
WORKDIR /src
|
|
COPY go.mod ./
|
|
RUN --mount=type=cache,target=/root/.cache/go-build \
|
|
go mod download && go mod verify
|
|
|
|
# Copy the rest and tidy (creates go.sum if missing)
|
|
COPY . .
|
|
RUN --mount=type=cache,target=/root/.cache/go-build go mod tidy
|
|
|
|
ENV CGO_ENABLED=0
|
|
RUN --mount=type=cache,target=/root/.cache/go-build \
|
|
if [ "${TARGETARCH}${TARGETVARIANT}" = "armv6" ]; then export GOARM=6; fi && \
|
|
if [ "${TARGETARCH}${TARGETVARIANT}" = "armv7" ]; then export GOARM=7; fi && \
|
|
GOOS=$TARGETOS GOARCH=$TARGETARCH go build -trimpath -ldflags="-s -w" \
|
|
-o /out/greencoast-shard ./cmd/shard
|
|
|
|
########################
|
|
# runtime
|
|
########################
|
|
FROM gcr.io/distroless/base-debian12:nonroot
|
|
WORKDIR /app
|
|
COPY --from=build /out/greencoast-shard /app/greencoast-shard
|
|
COPY configs/shard.sample.yaml /app/shard.yaml
|
|
COPY client /app/client
|
|
VOLUME ["/var/lib/greencoast"]
|
|
EXPOSE 8080 8081 8443 9443
|
|
USER nonroot:nonroot
|
|
ENTRYPOINT ["/app/greencoast-shard","--config","/app/shard.yaml"]
|