From b9582a1ba010a3f497af8efc74b5e1b5617ea298 Mon Sep 17 00:00:00 2001 From: Ashish Jhanwar Date: Wed, 10 Apr 2024 00:14:00 +0530 Subject: [PATCH] added debug config for docker and local, to make it easier to debug yagpdb --- .gitignore | 2 + .vscode/launch.json | 28 +++++++++++++ yagpdb_docker/Dockerfile.debug | 17 ++++++++ yagpdb_docker/docker-compose.debug.yml | 54 ++++++++++++++++++++++++++ 4 files changed, 101 insertions(+) create mode 100644 .vscode/launch.json create mode 100644 yagpdb_docker/Dockerfile.debug create mode 100644 yagpdb_docker/docker-compose.debug.yml diff --git a/.gitignore b/.gitignore index fc29d66461..698caf3c6a 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,5 @@ cmd/shardorchestrator/shardorchestrator *.agent *.exe cmd/shardorchestrator/capturepanics +__debug_bin* +app.env \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000000..acea3e79b5 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,28 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "YAGPDB Docker Debug", + "type": "go", + "request": "attach", + "port": 4000, + "host": "127.0.0.1", + "cwd": "${workspaceRoot}", + "showLog": true, + "mode": "remote", + "remotePath": "/app/yagpdb/", + "substitutePath": [ + { "from": "${workspaceFolder}", "to": "/app/yagpdb" }, + ] + }, { + "name": "YAGPDB Local Debug", + "type":"go", + "request": "launch", + "mode": "debug", + "envFile": "${workspaceFolder}/app.env", + "program": "${workspaceFolder}/cmd/yagpdb/main.go", + "output": "${workspaceFolder}/cmd/yagpdb/yagpdb", + "args": ["-all","https=false"] + } + ] +} \ No newline at end of file diff --git a/yagpdb_docker/Dockerfile.debug b/yagpdb_docker/Dockerfile.debug new file mode 100644 index 0000000000..9452538f04 --- /dev/null +++ b/yagpdb_docker/Dockerfile.debug @@ -0,0 +1,17 @@ +FROM golang:1.22.2-alpine +# Dependencies: ca-certificates for client TLS, tzdata for timezone and ffmpeg for soundboard support +RUN apk --no-cache add ca-certificates ffmpeg tzdata +RUN CGO_ENABLED=0 go install -ldflags "-s -w -extldflags '-static'" github.com/go-delve/delve/cmd/dlv@latest + +WORKDIR /app/yagpdb +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . + +WORKDIR /app/yagpdb/cmd/yagpdb + +VOLUME ["/app/soundboard", "/app/cert"] +EXPOSE 5000 4000 +EXPOSE 5100-5999 +CMD [ "/go/bin/dlv", "--listen=:4000", "--headless=true", "--log=true", "--accept-multiclient", "--api-version=2", "debug", "--continue", "--output=yagpdb", "--", "-all", "-https=false" ] diff --git a/yagpdb_docker/docker-compose.debug.yml b/yagpdb_docker/docker-compose.debug.yml new file mode 100644 index 0000000000..088f95e0ea --- /dev/null +++ b/yagpdb_docker/docker-compose.debug.yml @@ -0,0 +1,54 @@ +version: '3' + +volumes: + db: + redis: + cert_cache: + soundboard: + +networks: + default: + +services: + app: + build: + # We change context so that we can copy the local repo in during + # development + context: ../ + dockerfile: yagpdb_docker/Dockerfile.debug + restart: unless-stopped + depends_on: + - redis + - db + networks: + - default + volumes: + - cert_cache:/app/cert + - soundboard:/app/soundboard + - ..:/app/yagpdb + ports: + - '5000:5000' + - '4000:4000' + - '5100-5999:5100-5999' + env_file: + - app.env + security_opt: + - "seccomp:unconfined" + + redis: + image: redis + restart: unless-stopped + networks: + - default + volumes: + - redis:/data + + db: + image: postgres:11 + restart: unless-stopped + volumes: + - db:/var/lib/postgresql/data + networks: + - default + env_file: + - db.env