Skip to content

Commit

Permalink
fix(build): fix debug dockerfile (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmalek authored Mar 29, 2024
1 parent eb54ade commit 4e516db
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -471,11 +471,13 @@ debug: webhook-certs-dir manifests generate install _ensure-kong-system-namespac

.PHONY: debug.skaffold
debug.skaffold: _ensure-kong-system-namespace
GOCACHE=$(shell go env GOCACHE) \
TAG=$(TAG)-debug REPO_INFO=$(REPO_INFO) COMMIT=$(COMMIT) \
$(SKAFFOLD) debug --port-forward=pods --profile=debug

.PHONY: debug.skaffold.continuous
debug.skaffold.continuous: _ensure-kong-system-namespace
GOCACHE=$(shell go env GOCACHE) \
TAG=$(TAG)-debug REPO_INFO=$(REPO_INFO) COMMIT=$(COMMIT) \
$(SKAFFOLD) debug --port-forward=pods --profile=debug --auto-build --auto-deploy --auto-sync

Expand Down
36 changes: 24 additions & 12 deletions debug.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

FROM golang:1.22.1 as debug

ARG GOPATH
ARG GOCACHE

ARG TAG
ARG NAME="Kong Gateway Operator"
ARG DESCRIPTION="Kong Gateway Operator debug image"
Expand All @@ -30,15 +33,18 @@ RUN printf "Building for TARGETPLATFORM=${TARGETPLATFORM}" \

WORKDIR /workspace

COPY go.mod go.mod
COPY go.sum go.sum
RUN go mod download
RUN --mount=type=cache,target=$GOPATH/pkg/mod \
--mount=type=cache,target=$GOCACHE \
go install github.com/go-delve/delve/cmd/[email protected]

COPY Makefile Makefile
COPY third_party/go.mod third_party/go.mod
COPY third_party/go.sum third_party/go.sum
COPY third_party/dlv.go third_party/dlv.go
RUN make dlv
# 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 main.go main.go
COPY modules/ modules/
Expand All @@ -49,11 +55,17 @@ COPY internal/ internal/
COPY Makefile Makefile
COPY .git/ .git/

RUN CGO_ENABLED=0 GOOS=linux GOARCH="${TARGETARCH}" \
# 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 && \
mv ./bin/dlv /go/bin/dlv
mv ./bin/manager /go/bin/manager

ENTRYPOINT [ "/go/bin/dlv" ]
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", "--" ]

0 comments on commit 4e516db

Please sign in to comment.