This repository has been archived on 2025-08-23. You can view files and clone it, but cannot push or open issues or pull requests.
Files
GreenCoast/Dockerfile
2025-08-21 20:56:38 -04:00

45 lines
1.4 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
# 1) Copy ONLY go.mod first and materialize go.sum inside the image
COPY go.mod ./
# Produce go.sum (and module cache) before copying the rest
RUN --mount=type=cache,target=/root/.cache/go-build \
go mod download && go mod verify
# 2) Now copy the rest of the source
COPY . .
# (Optional but nice) ensure module graph is tidy (updates go.sum if needed)
RUN --mount=type=cache,target=/root/.cache/go-build \
go mod tidy
# 3) Build (with ARM variant handling)
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
VOLUME ["/var/lib/greencoast"]
EXPOSE 8080 8081
USER nonroot:nonroot
ENTRYPOINT ["/app/greencoast-shard","--config","/app/shard.yaml"]