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

Add build target which creates debug image #110

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
30 changes: 30 additions & 0 deletions Dockerfile.delve
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM golang:1.21-alpine3.19 AS build
Copy link
Collaborator

@andyasp andyasp Dec 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't update to alpine 3.19 yet, see #97.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above has been resolved now, but the main Dockerfile now compiles in bookworm. I don't think that difference matters here besides consistency.


ARG TARGETOS
ARG TARGETARCH
ARG BUILDTARGET=rollout-operator-debug

RUN apk add --no-cache build-base git

COPY . /src/rollout-operator
WORKDIR /src/rollout-operator
RUN go install github.com/go-delve/delve/cmd/[email protected]
RUN /go/bin/dlv -h
RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} make ${BUILDTARGET}

FROM alpine:3.19
RUN apk add --no-cache ca-certificates

COPY --from=build /go/bin/dlv /bin/dlv
COPY --from=build /src/rollout-operator/rollout-operator /bin/rollout-operator
ENTRYPOINT [ "/bin/dlv", "--headless=true", "--listen=:49988", "--api-version=2", "--accept-multiclient", "exec", "/bin/rollout-operator" , "--continue", "--"]

# Create rollout-operator user to run as non-root.
RUN addgroup -g 10000 -S rollout-operator && \
adduser -u 10000 -S rollout-operator -G rollout-operator
USER rollout-operator:rollout-operator

ARG revision
LABEL org.opencontainers.image.title="rollout-operator-debug" \
org.opencontainers.image.source="https://github.com/grafana/rollout-operator" \
org.opencontainers.image.revision="${revision}"
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ GIT_REVISION := $(shell git rev-parse --short HEAD)

IMAGE_PREFIX ?= grafana
IMAGE_TAG ?= $(subst /,-,$(GIT_BRANCH))-$(GIT_REVISION)
IMAGE_TAG_DEBUG ?= $(IMAGE_TAG)-debug

GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
Expand All @@ -21,6 +22,9 @@ help: ## Display this help and any documented user-facing targets
rollout-operator: $(GO_FILES) ## Build the rollout-operator binary
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=0 go build -ldflags '-extldflags "-static"' ./cmd/rollout-operator

rollout-operator-debug: $(GO_FILES) ## Build the rollout-operator binary without optimizations
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=0 go build -gcflags "all=-N -l" -ldflags '-extldflags "-static"' ./cmd/rollout-operator

.PHONY: rollout-operator-boringcrypto
rollout-operator-boringcrypto: $(GO_FILES) ## Build the rollout-operator binary with boringcrypto
GOEXPERIMENT=boringcrypto GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=1 go build -tags netgo ./cmd/rollout-operator
Expand All @@ -29,6 +33,15 @@ rollout-operator-boringcrypto: $(GO_FILES) ## Build the rollout-operator binary
build-image: clean ## Build the rollout-operator image
docker buildx build --load --platform linux/amd64 --build-arg revision=$(GIT_REVISION) -t rollout-operator:latest -t rollout-operator:$(IMAGE_TAG) .

# Separate build targets per architecture because docker exporter currently doesn't support multi-arch builds on mac.
.PHONY: build-debug-image-amd64 ## Build a rollout-operator debug image running in delve
build-debug-image-amd64: clean
docker buildx build --load --platform linux/amd64 --build-arg revision=$(GIT_REVISION) -t rollout-operator:$(IMAGE_TAG_DEBUG) -f Dockerfile.delve .

.PHONY: build-debug-image-arm64 ## Build a rollout-operator debug image running in delve
build-debug-image-arm64: clean
docker buildx build --load --platform linux/arm64 --build-arg revision=$(GIT_REVISION) -t rollout-operator:$(IMAGE_TAG_DEBUG) -f Dockerfile.delve .

.PHONY: build-image-boringcrypto
build-image-boringcrypto: clean ## Build the rollout-operator image with boringcrypto
# Tags with the regular image repo for integration testing
Expand All @@ -41,6 +54,10 @@ publish-images: publish-standard-image publish-boringcrypto-image ## Build and p
publish-standard-image: clean ## Build and publish only the standard rollout-operator image
docker buildx build --push --platform linux/amd64,linux/arm64 --build-arg revision=$(GIT_REVISION) --build-arg BUILDTARGET=rollout-operator -t $(IMAGE_PREFIX)/rollout-operator:$(IMAGE_TAG) .

.PHONY: publish-debug-image
publish-debug-image: clean
docker buildx build --push --platform linux/amd64,linux/arm64 --build-arg revision=$(GIT_REVISION) --build-arg BUILDTARGET=rollout-operator-debug -t $(IMAGE_PREFIX)/rollout-operator:$(IMAGE_TAG_DEBUG) -f Dockerfile.delve .

.PHONY: publish-boringcrypto-image
publish-boringcrypto-image: clean ## Build and publish only the boring-crypto rollout-operator image
docker buildx build --push --platform linux/amd64,linux/arm64 --build-arg revision=$(GIT_REVISION) --build-arg BUILDTARGET=rollout-operator-boringcrypto -t $(IMAGE_PREFIX)/rollout-operator-boringcrypto:$(IMAGE_TAG) .
Expand Down