-
Notifications
You must be signed in to change notification settings - Fork 594
/
Dockerfile.debug
56 lines (46 loc) · 1.89 KB
/
Dockerfile.debug
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
# Build a manager binary with debug symbols and download Delve
FROM --platform=$BUILDPLATFORM golang:1.23.3 AS builder
ARG GOPATH
ARG GOCACHE
ARG TARGETPLATFORM
ARG TARGETOS
ARG TARGETARCH
RUN printf "Building for TARGETPLATFORM=${TARGETPLATFORM}" \
&& printf ", TARGETARCH=${TARGETARCH}" \
&& printf ", TARGETOS=${TARGETOS}" \
&& printf ", TARGETVARIANT=${TARGETVARIANT} \n" \
&& printf "With 'uname -s': $(uname -s) and 'uname -m': $(uname -m)"
WORKDIR /workspace
# Use cache mounts to cache Go dependencies and bind mounts to avoid unnecessary
# layers when using COPY instructions for go.mod and go.sum.
# https://docs.docker.com/build/guide/mounts/
RUN --mount=type=cache,target=$GOPATH/pkg/mod \
--mount=type=cache,target=$GOCACHE \
--mount=type=bind,source=go.sum,target=go.sum \
--mount=type=bind,source=go.mod,target=go.mod \
go mod download -x
COPY controllers/ controllers/
COPY pkg/ pkg/
COPY internal/ internal/
COPY Makefile .
# Build
ARG TAG
ARG COMMIT
ARG REPO_INFO
# Use cache mounts to cache Go dependencies and bind mounts to avoid unnecessary
# layers when using COPY instructions for go.mod and go.sum.
# https://docs.docker.com/build/guide/mounts/
RUN --mount=type=cache,target=$GOPATH/pkg/mod \
--mount=type=cache,target=$GOCACHE \
--mount=type=bind,source=go.sum,target=go.sum \
--mount=type=bind,source=go.mod,target=go.mod \
CGO_ENABLED=0 GOOS=linux GOARCH="${TARGETARCH}" GO111MODULE=on make _build.debug
### Debug
# Create an image that runs a debug build with Delve installed
FROM golang:1.23.3 AS debug
RUN go install github.com/go-delve/delve/cmd/dlv@latest
# We want all source so Delve file location operations work
COPY --from=builder /workspace/bin/manager-debug /
USER 65532:65532
ENTRYPOINT ["/go/bin/dlv"]
CMD ["exec", "--continue", "--accept-multiclient", "--headless", "--api-version=2", "--listen=:2345", "--log", "/manager-debug"]