This repository has been archived on 2024-04-25. You can view files and clone it, but cannot push or open issues or pull requests.
golang-rest-example/Dockerfile

33 lines
675 B
Text
Raw Normal View History

2024-02-01 22:09:09 +00:00
# Base
ARG GO_VERSION=1.21
FROM golang:${GO_VERSION} as build
2024-02-01 22:09:09 +00:00
WORKDIR /app
COPY go.mod go.sum ./
2024-02-01 22:09:09 +00:00
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -o /server cmd/server.go
2024-02-01 22:09:09 +00:00
# Get curl
FROM tarampampam/curl AS curl
2024-02-01 22:09:09 +00:00
# Production
FROM gcr.io/distroless/static-debian12 as release
ENV PORT=1234
EXPOSE 1234
COPY --from=curl /bin/curl /bin/curl
HEALTHCHECK --interval=5s --timeout=2s --retries=2 --start-period=2s CMD [ \
"curl", "--fail", "http://127.0.0.1:1234/healthz" \
]
COPY --from=build /server /server
ENV DATABASE_MIGRATIONS=file:///app/migrations
2024-02-02 14:39:13 +00:00
COPY --from=build /app/migrations /app/migrations
USER nonroot:nonroot
2024-02-01 22:09:09 +00:00
ENTRYPOINT ["/server"]