diff --git a/Makefile b/Makefile index c10c45c48..6cd9fc30e 100644 --- a/Makefile +++ b/Makefile @@ -102,6 +102,11 @@ LDFLAGS = \ -X=github.com/containers/nri-plugins/pkg/version.Build=$(BUILD_BUILDID) \ -B 0x$(RANDOM_ID)" +ifeq ($(DEBUG),1) + GCFLAGS ?= -gcflags "all=-N -l" + DOCKER_BUILD_DEBUG := --build-arg DEBUG=1 +endif + # Documentation-related variables SPHINXOPTS ?= -W SPHINXBUILD = sphinx-build @@ -139,12 +144,12 @@ verify: verify-godeps verify-fmt verify-generate verify-build verify-docs build-plugins: $(foreach bin,$(PLUGINS),$(BIN_PATH)/$(bin)) build-plugins-static: - $(MAKE) STATIC=1 build-plugins + $(MAKE) STATIC=1 DEBUG=$(DEBUG) build-plugins build-binaries: $(foreach bin,$(BINARIES),$(BIN_PATH)/$(bin)) build-binaries-static: - $(MAKE) STATIC=1 build-binaries + $(MAKE) STATIC=1 DEBUG=$(DEBUG) build-binaries build-images: images @@ -236,6 +241,7 @@ image.%: tag=$(patsubst image.%,%,$@); \ $(DOCKER_BUILD) . -f "$$dir/Dockerfile" \ --build-arg GO_VERSION=$(GO_VERSION) \ + $(DOCKER_BUILD_DEBUG) \ --build-arg IMAGE_VERSION=$(IMAGE_VERSION) \ --build-arg BUILD_VERSION=$(BUILD_VERSION) \ --build-arg BUILD_BUILDID=$(BUILD_BUILDID) \ @@ -507,7 +513,7 @@ generate-manifests: controller-gen generate-types: controller-gen $(CONTROLLER_GEN) object:headerFile="./docs/license-header.go.txt" paths="./pkg/apis/..." -# client generation rules +# client generation rules .PHONY: generate-clients generate-clients: $(GENERATE_GROUPS) $(GENERATE_GROUPS) client \ diff --git a/cmd/plugins/balloons/Dockerfile b/cmd/plugins/balloons/Dockerfile index 443140c62..ad5aba86a 100644 --- a/cmd/plugins/balloons/Dockerfile +++ b/cmd/plugins/balloons/Dockerfile @@ -5,8 +5,14 @@ FROM golang:${GO_VERSION}-bullseye AS builder ARG IMAGE_VERSION ARG BUILD_VERSION ARG BUILD_BUILDID +ARG DEBUG=0 + WORKDIR /go/builder +RUN if [ "$DEBUG" = 1 ]; then \ + GOBIN=/go/builder/build/bin go install -tags osusergo,netgo -ldflags "-extldflags=-static" github.com/go-delve/delve/cmd/dlv@latest; \ + fi + # Fetch go dependencies in a separate layer for caching COPY go.mod go.sum ./ COPY pkg/topology/ pkg/topology/ @@ -16,10 +22,21 @@ RUN go mod download COPY . . RUN make clean -RUN make IMAGE_VERSION=${IMAGE_VERSION} BUILD_VERSION=${BUILD_VERSION} BUILD_BUILDID=${BUILD_BUILDID} PLUGINS=nri-resource-policy-balloons build-plugins-static +RUN make IMAGE_VERSION=${IMAGE_VERSION} BUILD_VERSION=${BUILD_VERSION} BUILD_BUILDID=${BUILD_BUILDID} PLUGINS=nri-resource-policy-balloons DEBUG=$DEBUG V=$DEBUG build-plugins-static +RUN if [ "$DEBUG" = 0 ]; then \ + for d in /go/builder/build/bin/dlv /go/builder/pkg /go/builder/cmd /go/pkg /usr/local/go/src ; do \ + mv $d $d-dont-copy 2>/dev/null; \ + touch $d; \ + done; \ + fi FROM gcr.io/distroless/static COPY --from=builder /go/builder/build/bin/nri-resource-policy-balloons /bin/nri-resource-policy-balloons +COPY --from=builder /go/builder/build/bin/dlv /bin/dlv +COPY --from=builder /go/builder/pkg /go/builder/pkg +COPY --from=builder /go/builder/cmd /go/builder/cmd +COPY --from=builder /go/pkg /go/pkg +COPY --from=builder /usr/local/go/src /usr/local/go/src ENTRYPOINT ["/bin/nri-resource-policy-balloons"]