Files
mtusi2026lab5/Dockerfile
T
Vladislav Kunetskiy 01b885e846 lab5: очереди и асинхронная обработка изображений
Durable staging handoff, transactional outbox, at-least-once worker with lease fencing, idempotent versioned pipeline, three variants, operator tooling, contract tests and evidence. Includes the review fixes: reprocess source selection and failure settlement, replay guards, stale-job retirement, PNG structural/raster validation, migration rollback safety and audit events.
2026-10-31 14:34:24 +03:00

78 lines
3.3 KiB
Docker

# syntax=docker/dockerfile:1.7
ARG GO_VERSION=1.27.1
ARG ALPINE_VERSION=3.22
FROM golang:${GO_VERSION}-alpine AS build
# Platform of the produced binaries. Left empty on purpose: the classic builder
# does not supply these args, and the previous hardcoded `amd64` default silently
# produced x86-64 binaries inside an arm64 image. Those ran under emulation and
# the Go runtime crashed under load (fatals like "found pointer to free object").
# Empty means "build for the builder's own platform"; cross-compile explicitly:
# docker build --build-arg TARGETARCH=amd64 ...
ARG TARGETOS
ARG TARGETARCH
ARG VERSION=dev
ENV GOTOOLCHAIN=local
WORKDIR /opt
COPY go.mod go.sum ./
RUN go mod download
# The Go compiler spikes well above 1 GiB per package on large dependencies
# (AWS SDK + pgx + Redis), so an unbounded or even -p=2 build OOMs Docker
# Desktop's default VM. Build one package at a time; override with
# --build-arg GOFLAGS=-p=$(nproc) on a bigger host.
ARG GOFLAGS="-p=1"
ENV GOFLAGS=$GOFLAGS
# Keep the compiler well below Docker Desktop's default VM limit.
ENV GOGC=50
ENV GOMEMLIMIT=1GiB
COPY . .
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
go build -trimpath -buildvcs=false -tags timetzdata,nodynamic \
-ldflags="-s -w -X main.version=${VERSION}" \
-o /out/messenger ./cmd/messenger \
&& CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
go build -trimpath -buildvcs=false -tags timetzdata,nodynamic \
-ldflags="-s -w -X main.version=${VERSION}" \
-o /out/migrate ./cmd/migrate \
&& CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
go build -trimpath -buildvcs=false -tags timetzdata,nodynamic \
-ldflags="-s -w -X main.version=${VERSION}" \
-o /out/s3init ./cmd/s3init \
&& CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
go build -trimpath -buildvcs=false -tags timetzdata,nodynamic \
-ldflags="-s -w -X main.version=${VERSION}" \
-o /out/worker ./cmd/worker \
&& CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
go build -trimpath -buildvcs=false -tags timetzdata,nodynamic \
-ldflags="-s -w -X main.version=${VERSION}" \
-o /out/relay ./cmd/relay \
&& CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
go build -trimpath -buildvcs=false -tags timetzdata,nodynamic \
-ldflags="-s -w -X main.version=${VERSION}" \
-o /out/jobctl ./cmd/jobctl
FROM alpine:${ALPINE_VERSION} AS runtime
RUN apk add --no-cache ca-certificates wget \
&& addgroup -S -g 10001 app \
&& adduser -S -D -H -u 10001 -G app app
COPY --from=build --chown=10001:10001 /out/messenger /usr/local/bin/messenger
COPY --from=build --chown=10001:10001 /out/migrate /usr/local/bin/migrate
COPY --from=build --chown=10001:10001 /out/s3init /usr/local/bin/s3init
COPY --from=build --chown=10001:10001 /out/worker /usr/local/bin/worker
COPY --from=build --chown=10001:10001 /out/relay /usr/local/bin/relay
COPY --from=build --chown=10001:10001 /out/jobctl /usr/local/bin/jobctl
COPY --chown=10001:10001 config/dev/config.yaml /etc/messenger/dev/config.yaml
USER 10001:10001
EXPOSE 8080
STOPSIGNAL SIGTERM
HEALTHCHECK --interval=10s --timeout=3s --start-period=5s --retries=3 \
CMD wget -q -O /dev/null "http://127.0.0.1:${SERVER_PORT:-8080}/health/live" || exit 1
ENTRYPOINT ["/usr/local/bin/messenger"]