Merged in feature/debug-queryapi (pull request #170)

new compose and dockerfile

* new compose and dockerfile

* add  task docker:build:debug

* update readme

* Merged main into feature/debug-queryapi
This commit is contained in:
Jay Brown
2025-06-30 21:00:49 +00:00
parent 3e64ea7944
commit 79e0085fb3
4 changed files with 153 additions and 2 deletions
+72
View File
@@ -70,3 +70,75 @@ This will:
1. Implement the controller in `./api/<runner_name>/` which implements the `Controller` interface in `./internal/queue`. The runner name must be in the format `<functionality>Runner`. E.g. queryRunner, csvExportRunner
2. Create a command in `./cmd/<runner_name>/main.go` which creates a new instance from `./internal/queue`
## Debugging in Containers
This project supports debugging Go applications running inside Docker containers using [Delve](https://github.com/go-delve/delve), the Go debugger.
### Building Debug Images
The project includes two build tasks for different use cases:
- `task docker:build` - Build the regular production image
- `task docker:build:debug` - Build the debug image with Delve
The debug image is built using `build/Dockerfile.debug`, which:
- Installs Delve debugger with static linking for Alpine compatibility
- Builds Go binaries with debug symbols (`-gcflags="all=-N -l"`)
- Exposes port 2345 for debugger connections
### Container Configuration for Debugging
To enable debugging for a service in `deployments/compose.local.yaml`, modify the service configuration:
```yaml
query_api:
image: queryorchestration:debug # Use debug image instead of latest
command: ["/dlv", "exec", "./queryAPI", "--listen=:2345", "--headless", "--api-version=2", "--accept-multiclient", "--continue"]
ports:
- "8080:8080" # Application port
- "2345:2345" # Debugger port
expose:
- 8080
- 2345
```
Key changes from production configuration:
1. **Image**: Use `queryorchestration:debug` instead of `queryorchestration:latest`
2. **Command**: Replace direct binary execution with Delve wrapper
3. **Ports**: Expose port 2345 for debugger connections
4. **Delve flags**:
- `--listen=:2345`: Listen on port 2345 for debugger connections
- `--headless`: Run without terminal interface
- `--accept-multiclient`: Allow multiple debugger connections
- `--continue`: Start the application immediately (don't wait for debugger)
### Connecting a Debugger
#### GoLand/IntelliJ IDEA
1. Go to **Run → Edit Configurations...**
2. Click **"+"** → **"Go Remote"**
3. Configure:
- **Name**: `Docker Debug`
- **Host**: `localhost`
- **Port**: `2345`
4. Click **Apply** and **OK**
5. Select the configuration and click **Debug** (Shift+F9)
6. Set breakpoints in your code and make HTTP requests to trigger them
#### VS Code
1. Add to `.vscode/launch.json`:
```json
{
"name": "Connect to Docker",
"type": "go",
"request": "attach",
"mode": "remote",
"remotePath": "/app",
"port": 2345,
"host": "localhost"
}
```
2. Set breakpoints and start debugging
The debugger will connect to the running container and pause execution when breakpoints are hit, allowing you to inspect variables, step through code, and debug issues in the containerized environment.