-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
67 lines (45 loc) · 1.46 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#syntax=docker/dockerfile:1.7-labs
ARG BUILD_BASE="golang"
ARG BUILD_BASE_VERSION="1.22.4-bookworm"
ARG PROD_BASE="gcr.io/distroless/base-debian12"
ARG PROD_BASE_VERSION="nonroot"
ARG DEV_BASE="${PROD_BASE}"
ARG DEV_BASE_VERSION="debug-nonroot"
# Prepare Sources
FROM ${BUILD_BASE}:${BUILD_BASE_VERSION} as src
WORKDIR /src
# go.mod / go.sum
COPY ["go.*", "./"]
RUN go mod download
# hadolint ignore=DL3021
COPY --parents ["**/*.go", "Makefile", "./"]
# Build (Development)
FROM src as build_dev
# To build faster, installing delve partially
RUN go install github.com/go-delve/delve/cmd/dlv@latest
# to use delve, disable optimizations/inlining
ENV GCFLAGS="all=-N -l"
RUN make build
# Build (Production)
FROM src as build_prod
RUN make build
# Runner (Development)
FROM ${DEV_BASE}:${DEV_BASE_VERSION} as dev
WORKDIR /src
EXPOSE 2345
COPY --from=build_dev ["/go/bin/dlv", "/usr/bin/"]
COPY --from=build_dev ["/src/go-template", "./"]
ENTRYPOINT ["dlv", "--listen=:2345", "--headless=true", "--api-version=2", "--accept-multiclient", "exec", "./go-template"]
# Runner (Go Test)
FROM build_dev as test
WORKDIR /src
EXPOSE 2346
# Run all tests
# To test as you need, overwrite CMD
ENTRYPOINT ["dlv", "--listen=:2346", "--headless=true", "--api-version=2", "--accept-multiclient", "test", "--"]
CMD ["-test.v", "./..."]
# Runner (Production)
FROM ${PROD_BASE}:${PROD_BASE_VERSION} as prod
WORKDIR /src
COPY --from=build_prod ["/src/go-template", "./"]
ENTRYPOINT ["./go-template"]