Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(build): fix debug dockerfile and debug skaffold makefile targets #71

Merged
merged 1 commit into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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", "--" ]
Loading