Skip to content

Commit

Permalink
Makefile: support for golang debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
schuellerf committed Apr 11, 2024
1 parent 2a3aafe commit 83e14f4
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 8 deletions.
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ WORKER_SRC_DEPS := $(SRC_DEPS)
COMPOSER_SRC_DEPS := $(SRC_DEPS)

GOMODARGS ?= -modfile=go.local.mod
# gcflags "-N -l" for golang to allow debugging
GCFLAGS ?= -gcflags=all=-N -gcflags=all=-l

CONTAINER_DEPS_COMPOSER := ./containers/osbuild-composer/entrypoint.py

USE_BTRFS ?= yes

Expand All @@ -331,12 +335,12 @@ go.local.mod go.local.sum: $(SRC_DEPS_EXTERNAL_DIRS) go.mod $(SRC_DEPS_EXTERNAL)
env GOPROXY=$(GOPROXY) go mod vendor $(GOMODARGS)

container_worker_built.info: go.local.mod $(WORKER_SRC_DEPS) $(DOCKERFILE_WORKER)
$(CONTAINER_EXECUTABLE) build -t $(DOCKER_IMAGE_WORKER) -f $(DOCKERFILE_WORKER) --build-arg GOMODARGS=$(GOMODARGS) --build-arg USE_BTRFS=$(USE_BTRFS) .
$(CONTAINER_EXECUTABLE) build -t $(DOCKER_IMAGE_WORKER) -f $(DOCKERFILE_WORKER) --build-arg GOMODARGS="$(GOMODARGS)" --build-arg GCFLAGS="$(GCFLAGS)" --build-arg USE_BTRFS=$(USE_BTRFS) .
echo "Worker last built on" > $@
date >> $@

container_composer_built.info: go.local.mod $(COMPOSER_SRC_DEPS) $(DOCKERFILE_COMPOSER)
$(CONTAINER_EXECUTABLE) build -t $(DOCKER_IMAGE_COMPOSER) -f $(DOCKERFILE_COMPOSER) --build-arg GOMODARGS=$(GOMODARGS) .
container_composer_built.info: go.local.mod $(COMPOSER_SRC_DEPS) $(DOCKERFILE_COMPOSER) $(CONTAINER_DEPS_COMPOSER)
$(CONTAINER_EXECUTABLE) build -t $(DOCKER_IMAGE_COMPOSER) -f $(DOCKERFILE_COMPOSER) --build-arg GOMODARGS="$(GOMODARGS)" --build-arg GCFLAGS="$(GCFLAGS)" .
echo "Composer last built on" > $@
date >> $@

Expand Down
33 changes: 31 additions & 2 deletions containers/osbuild-composer/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,37 @@ def handler(signum, frame):
liveness.touch()

try:
if self.args.builtin_worker:
should_launch_composer = any([self.args.weldr_api, self.args.composer_api, self.args.local_worker_api, self.args.remote_worker_api])
if self.args.builtin_worker or not should_launch_composer:
if not should_launch_composer:
print(f"NOTE: launching worker only - no API for composer enabled")
proc_worker = self._spawn_worker()

if any([self.args.weldr_api, self.args.composer_api, self.args.local_worker_api, self.args.remote_worker_api]):
if should_launch_composer:
proc_composer = self._spawn_composer(sockets)

debug_port = os.environ.get('GODEBUG_PORT')
debugger = None

if debug_port:
# only debug one - either composer or worker if there is no composer
child_pid = proc_composer.pid if proc_composer else proc_worker.pid
debug_target_name = "image-builder-composer" if proc_composer else "image-builder-worker"

debugger_cmd = [
"/usr/bin/dlv",
"attach",
"--headless=true",
"--api-version", "2",
"--listen", f":{debug_port}",
str(child_pid),
"/usr/libexec/osbuild-composer/osbuild-composer"
]

print(f"NOTE: you HAVE to attach the debugger NOW otherwise { debug_target_name } "
f"will not continue running")
debugger = subprocess.Popen(debugger_cmd)

if proc_composer:
res = proc_composer.wait()

Expand All @@ -347,6 +372,10 @@ def handler(signum, frame):
proc_worker.terminate()
proc_worker.wait()

if debugger:
debugger.wait()


except KeyboardInterrupt:
if proc_composer:
proc_composer.terminate()
Expand Down
5 changes: 3 additions & 2 deletions distribution/Dockerfile-composer
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ ARG GOPROXY=https://proxy.golang.org,direct
RUN go env -w GOPROXY=$GOPROXY

ARG GOMODARGS=""
ARG GCFLAGS=""

RUN go install $GOMODARGS ./cmd/osbuild-composer/
RUN go install $GOMODARGS $GCFLAGS ./cmd/osbuild-composer/

FROM registry.access.redhat.com/ubi9/go-toolset:latest AS builder2
RUN go install github.com/jackc/tern@latest

FROM fedora:39

RUN dnf install -y python3 python3-dnf gpgme libassuan device-mapper-libs
RUN dnf install -y python3 python3-dnf gpgme libassuan device-mapper-libs delve
RUN mkdir -p "/usr/libexec/osbuild-composer"
RUN mkdir -p "/etc/osbuild-composer/"
RUN mkdir -p "/run/osbuild-composer/"
Expand Down
3 changes: 2 additions & 1 deletion distribution/Dockerfile-worker_srcinstall
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ ARG GOPROXY=https://proxy.golang.org,direct
RUN go env -w GOPROXY=$GOPROXY

ARG GOMODARGS=""
ARG GCFLAGS=""

RUN go install $GOMODARGS ./cmd/osbuild-worker
RUN go install $GOMODARGS $GCFLAGS ./cmd/osbuild-worker

FROM osbuild_devel

Expand Down

0 comments on commit 83e14f4

Please sign in to comment.