forked from mtusi2026/mtusi2026lab7
База lab7: контракт 1.7.0 и реализация lab1–lab6
Перенесены cmd/internal/config, compose.yaml, Dockerfile, скрипты, student-tests и evidence из mtusi-messenger (master, lab6). Skeleton lab7 (openapi/infrastructure 1.7.0, trust-matrix.md, security/THREAT_MODEL.md, infra/openbao, tests/security.py) сохранён; make test-security добавлен в Makefile.
This commit is contained in:
+77
@@ -0,0 +1,77 @@
|
||||
# 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"]
|
||||
Reference in New Issue
Block a user