feat: add Delve debugger support and update entrypoint for debugging
This commit is contained in:
@@ -34,6 +34,9 @@ WORKDIR /app/backend
|
||||
# Install build dependencies
|
||||
RUN apk add --no-cache gcc musl-dev sqlite-dev
|
||||
|
||||
# Install Delve so we can attach during debugging
|
||||
RUN go install github.com/go-delve/delve/cmd/dlv@v1.22.0
|
||||
|
||||
# Copy Go module files
|
||||
COPY backend/go.mod backend/go.sum ./
|
||||
RUN go mod download
|
||||
@@ -64,6 +67,7 @@ RUN apk --no-cache add ca-certificates sqlite-libs \
|
||||
|
||||
# Copy Go binary from backend builder
|
||||
COPY --from=backend-builder /app/backend/cpmp /app/cpmp
|
||||
COPY --from=backend-builder /go/bin/dlv /usr/local/bin/dlv
|
||||
|
||||
# Copy frontend build from frontend builder
|
||||
COPY --from=frontend-builder /app/frontend/dist /app/frontend/dist
|
||||
|
||||
@@ -27,11 +27,15 @@ done
|
||||
|
||||
# Start CPM+ management application
|
||||
echo "Starting CPM+ management application..."
|
||||
/app/cpmp &
|
||||
if [ "$CPMP_DEBUG" = "1" ]; then
|
||||
DEBUG_PORT=${CPMP_DEBUG_PORT:-2345}
|
||||
echo "Running CPM+ under Delve (port $DEBUG_PORT)"
|
||||
/usr/local/bin/dlv exec /app/cpmp --headless --listen=":$DEBUG_PORT" --api-version=2 --accept-multiclient --log -- &
|
||||
else
|
||||
/app/cpmp &
|
||||
fi
|
||||
APP_PID=$!
|
||||
echo "CPM+ started (PID: $APP_PID)"
|
||||
|
||||
# Function to handle shutdown gracefully
|
||||
shutdown() {
|
||||
echo "Shutting down..."
|
||||
kill -TERM "$APP_PID" 2>/dev/null || true
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
# Debugging the Local Docker Image
|
||||
|
||||
Use the `cpmp:local` image as the source of truth and attach VS Code debuggers directly to the running container.
|
||||
|
||||
## 1. Enable the debugger
|
||||
The image now ships with the Delve debugger. When you start the container, set `CPMP_DEBUG=1` (and optionally `CPMP_DEBUG_PORT`) so CPM+ runs under Delve.
|
||||
|
||||
```bash
|
||||
docker run --rm -it \
|
||||
--name cpmp-debug \
|
||||
-p 8080:8080 \
|
||||
-p 2345:2345 \
|
||||
-e CPM_ENV=development \
|
||||
-e CPM_DEBUG=1 \
|
||||
cpmp:local
|
||||
```
|
||||
|
||||
Delve will listen on `localhost:2345`, while the UI remains available at `http://localhost:8080`.
|
||||
|
||||
## 2. Attach VS Code
|
||||
- Use the **Attach to CPMP backend** configuration in `.vscode/launch.json` to connect the Go debugger to Delve.
|
||||
- Use the **Open CPMP frontend** configuration to launch Chrome against the management UI.
|
||||
|
||||
These launch configurations assume the ports above are exposed. If you need a different port, set `CPMP_DEBUG_PORT` when running the container and update the Go configuration's `port` field accordingly.
|
||||
Reference in New Issue
Block a user