Files
mtusi2026lab2/Dockerfile
T

23 lines
743 B
Docker

FROM golang:1.24.4-alpine3.22 AS build
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY cmd/ ./cmd/
COPY internal/ ./internal/
RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /out/messenger ./cmd/server
FROM build AS tests
RUN apk add --no-cache gcc musl-dev
ENV CGO_ENABLED=1
CMD ["go", "test", "-race", "-count=1", "-v", "./..."]
FROM alpine:3.22.1
RUN addgroup -g 10001 app && adduser -D -u 10001 -G app app
COPY --from=build /out/messenger /usr/local/bin/messenger
USER 10001:10001
ENV APP_HOST=0.0.0.0 APP_PORT=8080 APP_ENV=lab
EXPOSE 8080
HEALTHCHECK --interval=5s --timeout=4s --start-period=3s --retries=3 CMD ["/usr/local/bin/messenger", "healthcheck"]
STOPSIGNAL SIGTERM
ENTRYPOINT ["/usr/local/bin/messenger"]