From 0aea1d776054048f5b8c83beb96f58dfabdb82d2 Mon Sep 17 00:00:00 2001 From: yaroslavborbat Date: Mon, 9 Sep 2024 14:46:43 +0300 Subject: [PATCH] fix Signed-off-by: yaroslavborbat --- .../Taskfile.dist.yaml | 8 +++ .../hack/dlv-apiserver.Dockerfile | 31 ++++++++++++ images/virtualization-artifact/hack/dlv.sh | 49 +++++++++++++------ .../apiserver/registry/vm/storage/storage.go | 4 +- .../pkg/apiserver/registry/vm/storage/util.go | 2 +- 5 files changed, 78 insertions(+), 16 deletions(-) create mode 100644 images/virtualization-artifact/hack/dlv-apiserver.Dockerfile diff --git a/images/virtualization-artifact/Taskfile.dist.yaml b/images/virtualization-artifact/Taskfile.dist.yaml index a40d39d0c..495cfbde0 100644 --- a/images/virtualization-artifact/Taskfile.dist.yaml +++ b/images/virtualization-artifact/Taskfile.dist.yaml @@ -681,6 +681,14 @@ tasks: desc: "Push image virtualization-controller with dlv" cmd: ./hack/dlv.sh push controller --image="$DLV_IMAGE" + dlv:build:apiserver: + desc: "Build image virtualization-api with dlv" + cmd: ./hack/dlv.sh build apiserver --image="$DLV_IMAGE" + + dlv:build-push:apiserver: + desc: "Push image virtualization-api with dlv" + cmd: ./hack/dlv.sh push apiserver --image="$DLV_IMAGE" + _copy_d8_registry_secret: internal: true vars: diff --git a/images/virtualization-artifact/hack/dlv-apiserver.Dockerfile b/images/virtualization-artifact/hack/dlv-apiserver.Dockerfile new file mode 100644 index 000000000..ad65390a4 --- /dev/null +++ b/images/virtualization-artifact/hack/dlv-apiserver.Dockerfile @@ -0,0 +1,31 @@ +FROM golang:1.21.8-bookworm@sha256:ac14cc827536ef1a124cd2f7a03178c3335c1db8ad3807e7fdd57f74096abfa0 AS builder +ARG TARGETOS +ARG TARGETARCH + +WORKDIR /app/images/virtualization-artifact +RUN go install github.com/go-delve/delve/cmd/dlv@latest + +COPY ./images/virtualization-artifact/go.mod /app/images/virtualization-artifact/ +COPY ./images/virtualization-artifact/go.sum /app/images/virtualization-artifact/ +COPY ./api/ /app/api/ + +RUN go mod download + +COPY ./images/virtualization-artifact/cmd /app/images/virtualization-artifact/cmd +COPY ./images/virtualization-artifact/pkg /app/images/virtualization-artifact/pkg + +ENV GO111MODULE=on +ENV GOOS=${TARGETOS:-linux} +ENV GOARCH=${TARGETARCH:-amd64} +ENV CGO_ENABLED=0 + +RUN go build -gcflags "all=-N -l" -a -o virtualization-api ./cmd/virtualization-api + +FROM busybox:1.36.1-glibc + +WORKDIR /app +COPY --from=builder /go/bin/dlv /app/dlv +COPY --from=builder /app/images/virtualization-artifact/virtualization-api /app/virtualization-api +USER 65532:65532 + +ENTRYPOINT ["./dlv", "--listen=:2345", "--headless=true", "--continue", "--log=true", "--log-output=debugger,debuglineerr,gdbwire,lldbout,rpc", "--accept-multiclient", "--api-version=2", "exec", "./virtualization-api", "--"] diff --git a/images/virtualization-artifact/hack/dlv.sh b/images/virtualization-artifact/hack/dlv.sh index 1288a93f6..78e60be38 100755 --- a/images/virtualization-artifact/hack/dlv.sh +++ b/images/virtualization-artifact/hack/dlv.sh @@ -20,8 +20,8 @@ function usage { Usage: $0 COMMAND OPTIONS Commands: - build Build docker image with dlv. - push Build and Push docker image with dlv. + build Build docker image with dlv. + push Build and Push docker image with dlv. Global Flags: --image,-i (optional) The name of the image being built. @@ -30,7 +30,7 @@ Examples: # build" $(basename "$0") build controller --image=myimage:latest # push" - $(basename "$0") push controller + $(basename "$0") push apiserver EOF } @@ -42,33 +42,45 @@ function usage_exit { } function build_controller { + build "dlv-controller.Dockerfile" +} + +function build_apiserver { + build "dlv-apiserver.Dockerfile" +} + +function build { + local dockerfile=$1 cd "$ROOT" - docker build -f ./images/virtualization-artifact/hack/dlv-controller.Dockerfile -t "${IMAGE}" . + docker build -f "./images/virtualization-artifact/hack/$dockerfile" -t "${IMAGE}" . } function push { docker push "${IMAGE}" } +# shellcheck disable=SC2120 function print_patches_controller { + local deployment=$1 + cat <