-
Notifications
You must be signed in to change notification settings - Fork 11
/
debug.Dockerfile
71 lines (60 loc) · 2.49 KB
/
debug.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
68
69
70
71
# ------------------------------------------------------------------------------
# Debug image
# ------------------------------------------------------------------------------
FROM --platform=$BUILDPLATFORM golang:1.23.1 as debug
ARG GOPATH
ARG GOCACHE
ARG TAG
ARG NAME="Kong Gateway Operator"
ARG DESCRIPTION="Kong Gateway Operator debug image"
ARG TARGETPLATFORM
ARG TARGETOS
ARG TARGETARCH
ARG COMMIT
ARG REPO_INFO
LABEL name="${NAME}" \
description="${DESCRIPTION}" \
org.opencontainers.image.description="${DESCRIPTION}" \
vendor="Kong" \
version="${TAG}" \
release="1" \
url="https://github.com/Kong/gateway-operator" \
summary="A Kubernetes Operator for the Kong Gateway."
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
RUN --mount=type=cache,target=$GOPATH/pkg/mod \
--mount=type=cache,target=$GOCACHE \
go install github.com/go-delve/delve/cmd/dlv@v1.22.1
# 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 cmd/main.go cmd/main.go
COPY modules/ modules/
COPY api/ api/
COPY controller/ controller/
COPY pkg/ pkg/
COPY internal/ internal/
COPY Makefile Makefile
COPY .git/ .git/
# 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}" \
TAG="${TAG}" COMMIT="${COMMIT}" REPO_INFO="${REPO_INFO}" \
make build.operator.debug && \
mv ./bin/manager /go/bin/manager
ENTRYPOINT [ "dlv" ]
CMD [ "--continue", "--accept-multiclient", "--listen=:40000", "--check-go-version=false", "--headless=true", "--api-version=2", "--log=true", "--log-output=debugger,debuglineerr,gdbwire", "exec", "/go/bin/manager", "--" ]