Files
Datarush/Containerfile
T
2025-12-14 14:32:35 +03:00

63 lines
1.2 KiB
Docker

ARG GOARCH=amd64
ARG GOOS=linux
ARG CGO_ENABLED=0
ARG BUILD_TIME=unknown
ARG SERVICE
# Stage 1: Build
FROM docker.io/golang:1.24-alpine AS build
ARG GOOS
ARG GOARCH
ARG CGO_ENABLED
ARG VERSION
ARG BUILD_TIME
ARG SERVICE
WORKDIR /src
COPY go.mod go.sum ./
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
go mod download
COPY . .
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
CGO_ENABLED=${CGO_ENABLED} \
GOOS=${GOOS} \
GOARCH=${GOARCH} \
go build -trimpath \
-ldflags="-s -w -X 'main.BuildTime=${BUILD_TIME}'" \
-o /bin/${SERVICE} ./cmd/${SERVICE}
# Stage 2: Runtime
FROM docker.io/alpine:3.22 AS runtime
ARG VERSION
ARG BUILD_TIME
ARG SERVICE
RUN addgroup -S app && adduser -S -G app app
WORKDIR /app
COPY --from=build /bin/${SERVICE} /app/bin
RUN chown app:app /app/bin && chmod +x /app/bin
USER app
EXPOSE 8080 50051
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
CMD wget -qO- --timeout=2 http://127.0.0.1:8080/health || exit 1
LABEL org.opencontainers.image.version=${VERSION}
LABEL org.opencontainers.image.created=${BUILD_TIME}
ENTRYPOINT ["/app/bin"]
CMD [""]