feat: pure-Go SQLite, distroless runtime images, no-CGO cross-compilation - #27
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates Gearbox to use a pure-Go SQLite driver to eliminate CGO and enable faster cross-compilation, while also switching both gearbox and gearbox-agent runtime containers to distroless images to reduce runtime surface area.
Changes:
- Replace
mattn/go-sqlite3withmodernc.org/sqliteand update golang-migrate to use the modernc-compatible sqlite driver. - Update Docker build to use
CGO_ENABLED=0and simplify builder dependencies. - Switch runtime images to
gcr.io/distroless/static-debian12:nonrootand remove Dockerfile-level health checks.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| gearbox/internal/framework/database/migrate_manager.go | Switch golang-migrate driver from sqlite3 to sqlite and update migrator instance name accordingly. |
| gearbox/internal/framework/database/database.go | Switch database/sql driver name from sqlite3 to sqlite and update blank import to modernc driver. |
| gearbox/go.mod | Remove CGO sqlite dependency and add modernc.org/sqlite (plus indirect deps). |
| gearbox/go.sum | Update module checksums to reflect the dependency switch. |
| gearbox/Dockerfile | Build with CGO_ENABLED=0 and change runtime base image to distroless :nonroot. |
| gearbox-agent/Dockerfile | Reduce builder deps and change runtime base image to distroless :nonroot. |
Comments suppressed due to low confidence (1)
gearbox-agent/Dockerfile:41
- The image now runs as distroless
:nonrootbut still defaultsHAPROXY_AGENT_DATA_DIRto/var/lib/gearbox-agent. On Debian-based images,/var/libis root-owned, soos.MkdirAll("/var/lib/gearbox-agent", …)(triggered by API key/cert creation) will usually fail with permission denied. Ensure the data dir exists and is owned by the nonroot user at build time (e.g., create it in the builder stage andCOPY --chownit into the final image), or switch the default to a writable path under/appand update docs/compose accordingly.
FROM gcr.io/distroless/static-debian12:nonroot
WORKDIR /app
# Copy binary from builder
COPY --from=go-builder /build/gearbox-agent .
# Expose API port
EXPOSE 8405
# Environment defaults (can be overridden)
ENV HAPROXY_AGENT_LISTEN=0.0.0.0:8405 \
HAPROXY_AGENT_DATA_DIR=/var/lib/gearbox-agent \
HAPROXY_AGENT_LOG_LEVEL=info
Eliminates CGO dependency for SQLite, enabling native cross-compilation
for linux/arm64 in Docker CI. arm64 builds should drop from 15-30 min
to 2-4 min.
- Switch database.go driver import and name ("sqlite3" → "sqlite")
- Switch migrate_manager.go to golang-migrate's modernc-compatible sqlite driver
- Remove gcc/musl-dev from Dockerfile builder stage
- Remove sqlite-libs from Dockerfile runtime stage
- Set CGO_ENABLED=0 in Dockerfile build step
Closes #26
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replaces Alpine runtime stages with gcr.io/distroless/static-debian12:nonroot for both gearbox and gearbox-agent. Drops internal HEALTHCHECK in favour of external probes (Docker Compose / Kubernetes). - Removes ca-certificates, tzdata, wget from runtime (distroless includes ca-certs and tzdata; wget not needed without internal health check) - Removes non-root user setup (distroless:nonroot provides UID 65532) - Removes unnecessary ca-certificates/tzdata from builder apk installs (builder only needs git for go mod download) - gearbox-agent data directory (/var/lib/gearbox-agent) is created at startup by crypto.LoadOrCreateAPIKey via os.MkdirAll on the API key path Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
sarg3nt
force-pushed
the
feature/modernc-sqlite
branch
from
May 10, 2026 07:59
67ce1aa to
113d421
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
mattn/go-sqlite3(CGO) withmodernc.org/sqlite(pure Go) — eliminates CGO, enabling fast native cross-compilation forlinux/arm64without QEMU overheadgolang-migratesqlite driver fromdatabase/sqlite3(mattn) todatabase/sqlite(modernc-compatible)gearboxandgearbox-agentruntime images from Alpine togcr.io/distroless/static-debian12:nonrootHEALTHCHECKfrom both images — rely on external probes (Docker Compose / Kubernetes)apk adddown togitonly — ca-certs, tzdata, gcc, musl-dev all removedExpected outcome
linux/arm64Docker builds drop from 15–30 min to 2–4 mingearbox-agentdata directory (/var/lib/gearbox-agent) created at startup by existingos.MkdirAllincrypto.LoadOrCreateAPIKeyTest plan
CGO_ENABLED=0 go build ./...passes ingearbox/linux/amd64andlinux/arm64gearboxstarts and database initialises (WAL mode, migrations)gearbox-agentstarts and creates/var/lib/gearbox-agenton first runCloses #26
🤖 Generated with Claude Code