From f1ccaa7e9893525e0a692f702256ba13191e1527 Mon Sep 17 00:00:00 2001 From: Roman Perekhod Date: Wed, 17 Jan 2024 17:53:31 +0100 Subject: [PATCH] added ability to debug the ocis in a docker compose stack via delve --- .make/go.mk | 12 +++++++ .vscode/launch.json | 7 ++++ docs/ocis/development/debugging.md | 46 ++++++++++++++++++++++++ ocis/Makefile | 6 ++++ ocis/docker/Dockerfile.linux.debug.amd64 | 41 +++++++++++++++++++++ 5 files changed, 112 insertions(+) create mode 100644 ocis/docker/Dockerfile.linux.debug.amd64 diff --git a/.make/go.mk b/.make/go.mk index 87abab4cc..5f5847fa2 100644 --- a/.make/go.mk +++ b/.make/go.mk @@ -107,3 +107,15 @@ $(BIN)/$(EXECUTABLE)-debug: $(SOURCES) .PHONY: watch watch: $(REFLEX) $(REFLEX) -c reflex.conf + +debug-linux-docker-amd64: release-dirs + GOOS=linux \ + GOARCH=amd64 \ + go build \ + -gcflags="all=-N -l" \ + -tags 'netgo $(TAGS)' \ + -buildmode=exe \ + -trimpath \ + -ldflags '-extldflags "-static" $(DEBUG_LDFLAGS) $(DOCKER_LDFLAGS)' \ + -o '$(DIST)/binaries/$(EXECUTABLE)-linux-amd64' \ + ./cmd/$(NAME) diff --git a/.vscode/launch.json b/.vscode/launch.json index 0d8cdaae0..39cc02800 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -6,6 +6,13 @@ "type": "php", "request": "launch" }, + { + "name": "Debug remote :40000", + "type": "go", + "request": "attach", + "mode": "remote", + "port": 40000 + }, { "name": "oCIS server", "type": "go", diff --git a/docs/ocis/development/debugging.md b/docs/ocis/development/debugging.md index ed65bd2ff..3d9c25add 100644 --- a/docs/ocis/development/debugging.md +++ b/docs/ocis/development/debugging.md @@ -134,6 +134,52 @@ bin/ocis --log-level=$LOG_LEVEL proxy & 4. Start the service you are interested in debug mode. When using make to build the binary there is already a `bin/ocis-debug` binary for you. When running an IDE tell it which service to start by providing the corresponding sub command, e.g. `bin\ocis-debug reva-frontend`. +### Debugging the ocis in a docker container + +Remote debugging is the debug mode commonly used to work with a debugger and target running on a remote machine or a container for example a wopi stack `deployments/examples/ocis_wopi/docker-compose.yml`. +Below we describe the steps how to build the image, run the docker-compose and connect via remote debugger. +1. Build the image: +```bash +cd github.com/owncloud/ocis/ocis +make debug-docker +``` +2. Change the tag label: +```bash +export OCIS_DOCKER_TAG=debug +``` +3. Change the docker-compose `ocis` or `ocis-appprovider-collabora` or `ocis-appprovider-onlyoffice` depends on what do you want to debug: +For example `deployments/examples/ocis_wopi/docker-compose.yml` +```yaml + ocis: + image: owncloud/ocis:${OCIS_DOCKER_TAG:-latest} + networks: + ocis-net: + entrypoint: + - /bin/sh +# Comment out command +# command: ["-c", "ocis init || true; ocis server"] +# Replace the command and expose the port + command: [ "-c", "ocis init || true; dlv --listen=:40000 --headless=true --api-version=2 --accept-multiclient exec /usr/bin/ocis server" ] + ports: + - 40000:40000 +``` +4. Run the docker-compose +5. Connect to remote `delve` +* For the VS Code add the configuration to the `.vscode/launch.json` [https://github.com/golang/vscode-go/wiki/debugging#remote-debugging](https://github.com/golang/vscode-go/wiki/debugging#remote-debugging) +```json + { + "name": "Debug remote :40000", + "type": "go", + "request": "attach", + "mode": "remote", + "port": 40000, + "host": "localhost", // optional + "trace": "verbose", // optional + "showLog": true // optional +}, +``` + + ### Gather error messages We recommend you collect all related information in a single file or in a GitHub issue. Let us start with an error that pops up in the Web UI: diff --git a/ocis/Makefile b/ocis/Makefile index 687806ec1..7a2fef061 100644 --- a/ocis/Makefile +++ b/ocis/Makefile @@ -31,6 +31,12 @@ dev-docker: $(MAKE) --no-print-directory release-linux-docker-$(GOARCH) docker build -f docker/Dockerfile.linux.$(GOARCH) -t owncloud/ocis:dev . +############ debug-docker ############ +.PHONY: debug-docker +debug-docker: + $(MAKE) --no-print-directory debug-linux-docker-$(GOARCH) + docker build -f docker/Dockerfile.linux.debug.$(GOARCH) -t owncloud/ocis:debug . + ############ generate ############ include ../.make/generate.mk diff --git a/ocis/docker/Dockerfile.linux.debug.amd64 b/ocis/docker/Dockerfile.linux.debug.amd64 new file mode 100644 index 000000000..59fc57185 --- /dev/null +++ b/ocis/docker/Dockerfile.linux.debug.amd64 @@ -0,0 +1,41 @@ +FROM amd64/alpine:3.19 + +ARG VERSION="" +ARG REVISION="" + +RUN apk add --no-cache ca-certificates mailcap tree attr curl libc6-compat delve && \ + echo 'hosts: files dns' >| /etc/nsswitch.conf + +LABEL maintainer="ownCloud GmbH " \ + org.opencontainers.image.title="ownCloud Infinite Scale" \ + org.opencontainers.image.vendor="ownCloud GmbH" \ + org.opencontainers.image.authors="ownCloud GmbH" \ + org.opencontainers.image.description="oCIS - ownCloud Infinite Scale is a modern file-sync and share platform" \ + org.opencontainers.image.licenses="Apache-2.0" \ + org.opencontainers.image.documentation="https://github.com/owncloud/ocis" \ + org.opencontainers.image.url="https://hub.docker.com/r/owncloud/ocis" \ + org.opencontainers.image.source="https://github.com/owncloud/ocis" \ + org.opencontainers.image.version="${VERSION}" \ + org.opencontainers.image.revision="${REVISION}" + +RUN addgroup -g 1000 -S ocis-group && \ + adduser -S --ingroup ocis-group --uid 1000 ocis-user --home /var/lib/ocis + +RUN mkdir -p /var/lib/ocis && \ + chown -R ocis-user:ocis-group /var/lib/ocis && \ + chmod -R 751 /var/lib/ocis && \ + mkdir -p /etc/ocis && \ + chown -R ocis-user:ocis-group /etc/ocis && \ + chmod -R 751 /etc/ocis + +VOLUME [ "/var/lib/ocis", "/etc/ocis" ] +WORKDIR /var/lib/ocis + +USER 1000 + +EXPOSE 9200/tcp + +ENTRYPOINT ["/usr/bin/ocis"] +CMD ["server"] + +COPY dist/binaries/ocis-linux-amd64 /usr/bin/ocis