From 3b3c5acdfdb692cd167cd91de8c13d955f772991 Mon Sep 17 00:00:00 2001 From: Juan Manuel Leflet Estrada Date: Wed, 11 Oct 2023 12:49:56 +0200 Subject: [PATCH 1/2] Add Dockerfile for debugging Signed-off-by: Juan Manuel Leflet Estrada --- debug.Dockerfile | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 debug.Dockerfile diff --git a/debug.Dockerfile b/debug.Dockerfile new file mode 100644 index 00000000..5140f9ea --- /dev/null +++ b/debug.Dockerfile @@ -0,0 +1,46 @@ +FROM golang:1.19 as builder +WORKDIR /analyzer-lsp + +COPY cmd /analyzer-lsp/cmd +COPY engine /analyzer-lsp/engine +COPY output /analyzer-lsp/output +COPY jsonrpc2 /analyzer-lsp/jsonrpc2 +COPY lsp /analyzer-lsp/lsp +COPY parser /analyzer-lsp/parser +COPY provider /analyzer-lsp/provider +COPY tracing /analyzer-lsp/tracing +COPY external-providers /analyzer-lsp/external-providers +COPY go.mod /analyzer-lsp/go.mod +COPY go.sum /analyzer-lsp/go.sum +COPY Makefile /analyzer-lsp/Makefile + +# Install delve (go debugger) +RUN go install github.com/go-delve/delve/cmd/dlv@latest + +RUN go build -gcflags="all=-N -l" -o konveyor-analyzer ./cmd/analyzer/main.go +RUN go build -gcflags="all=-N -l" -o konveyor-analyzer-dep ./cmd/dep/main.go +RUN cd external-providers/generic-external-provider && go mod edit -replace=github.com/konveyor/analyzer-lsp=../../ && go build -gcflags="all=-N -l" -o generic-external-provider main.go +RUN cd external-providers/golang-dependency-provider && go mod edit -replace=github.com/konveyor/analyzer-lsp=../../ && go build -gcflags="all=-N -l" -o golang-dependency-provider main.go + +FROM jaegertracing/all-in-one:latest AS jaeger-builder + +# The unofficial base image w/ jdtls and gopls installed +FROM quay.io/konveyor/jdtls-server-base + +COPY --from=jaeger-builder /go/bin/all-in-one-linux /usr/bin/ + +COPY --from=builder /analyzer-lsp/konveyor-analyzer /usr/bin/konveyor-analyzer +COPY --from=builder /analyzer-lsp/konveyor-analyzer-dep /usr/bin/konveyor-analyzer-dep +COPY --from=builder /analyzer-lsp/external-providers/generic-external-provider/generic-external-provider /usr/bin/generic-external-provider +COPY --from=builder /analyzer-lsp/external-providers/golang-dependency-provider/golang-dependency-provider /usr/bin/golang-dependency-provider + +COPY --from=builder /go/bin/dlv / + +COPY provider_container_settings.json /analyzer-lsp/provider_settings.json + +WORKDIR /analyzer-lsp + +EXPOSE 16686 40000 + +ENTRYPOINT ["/dlv", "--listen=:40000", "--headless=true", "--api-version=2", "--accept-multiclient", "exec"] +CMD ["/usr/bin/konveyor-analyzer"] From 4728289c8413c25b862fbc533c3bba1a91d9c2e1 Mon Sep 17 00:00:00 2001 From: Juan Manuel Leflet Estrada Date: Tue, 21 Nov 2023 14:10:31 +0100 Subject: [PATCH 2/2] Add README, move to 'debug' Signed-off-by: Juan Manuel Leflet Estrada --- debug/README.md | 12 ++++++++++ debug.Dockerfile => debug/debug.Dockerfile | 26 +++++++++++----------- 2 files changed, 25 insertions(+), 13 deletions(-) create mode 100644 debug/README.md rename debug.Dockerfile => debug/debug.Dockerfile (73%) diff --git a/debug/README.md b/debug/README.md new file mode 100644 index 00000000..21667160 --- /dev/null +++ b/debug/README.md @@ -0,0 +1,12 @@ +Debugging within the container +== +Given the containerized nature of the analyzer, and its dependency on external components, many times it will be convenient to debug its code +running inside a container. This can be achieved by executing the main command with the [Go Delve debugger](https://github.com/go-delve/delve). + +`debug.Dockerfile` makes it possible to do this, and also to connect from an external IDE, like GoLand or VSCode. + +### Debugging from Goland +You can follow [these instructions](https://blog.jetbrains.com/go/2020/05/06/debugging-a-go-application-inside-a-docker-container/) to debug the analyzer from the GoLand IDE. + +### Debugging from VSCode +Follow [this blog post](https://dev.to/bruc3mackenzi3/debugging-go-inside-docker-using-vscode-4f67) to debug from VSCode. The Dockerfile creation steps can be skipped. \ No newline at end of file diff --git a/debug.Dockerfile b/debug/debug.Dockerfile similarity index 73% rename from debug.Dockerfile rename to debug/debug.Dockerfile index 5140f9ea..0870c3d7 100644 --- a/debug.Dockerfile +++ b/debug/debug.Dockerfile @@ -1,18 +1,18 @@ FROM golang:1.19 as builder WORKDIR /analyzer-lsp -COPY cmd /analyzer-lsp/cmd -COPY engine /analyzer-lsp/engine -COPY output /analyzer-lsp/output -COPY jsonrpc2 /analyzer-lsp/jsonrpc2 -COPY lsp /analyzer-lsp/lsp -COPY parser /analyzer-lsp/parser -COPY provider /analyzer-lsp/provider -COPY tracing /analyzer-lsp/tracing -COPY external-providers /analyzer-lsp/external-providers -COPY go.mod /analyzer-lsp/go.mod -COPY go.sum /analyzer-lsp/go.sum -COPY Makefile /analyzer-lsp/Makefile +COPY ../cmd /analyzer-lsp/cmd +COPY ../engine /analyzer-lsp/engine +COPY ../output /analyzer-lsp/output +COPY ../jsonrpc2 /analyzer-lsp/jsonrpc2 +COPY ../lsp /analyzer-lsp/lsp +COPY ../parser /analyzer-lsp/parser +COPY ../provider /analyzer-lsp/provider +COPY ../tracing /analyzer-lsp/tracing +COPY ../external-providers /analyzer-lsp/external-providers +COPY ../go.mod /analyzer-lsp/go.mod +COPY ../go.sum /analyzer-lsp/go.sum +COPY ../Makefile /analyzer-lsp/Makefile # Install delve (go debugger) RUN go install github.com/go-delve/delve/cmd/dlv@latest @@ -36,7 +36,7 @@ COPY --from=builder /analyzer-lsp/external-providers/golang-dependency-provider/ COPY --from=builder /go/bin/dlv / -COPY provider_container_settings.json /analyzer-lsp/provider_settings.json +COPY ../provider_container_settings.json /analyzer-lsp/provider_settings.json WORKDIR /analyzer-lsp