Skip to content

Add build target which creates debug image #110

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

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 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
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}"
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,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)
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 +32,10 @@ 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) .

.PHONY: build-debug-image ## Build a rollout-operator image running in delve
build-debug-image: clean
docker buildx build --load --platform linux/arm64 --build-arg revision=$(GIT_REVISION) -t rollout-operator:latest -t rollout-operator:$(IMAGE_TAG) -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 +48,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