Skip to content

feat(audit): replace mattn/go-sqlite3 with modernc.org/sqlite to remove CGO dependency#152

Merged
mrhillsman merged 3 commits into
mainfrom
150-replace-cgo-sqlite-driver
May 30, 2026
Merged

feat(audit): replace mattn/go-sqlite3 with modernc.org/sqlite to remove CGO dependency#152
mrhillsman merged 3 commits into
mainfrom
150-replace-cgo-sqlite-driver

Conversation

@mrhillsman

Copy link
Copy Markdown
Contributor

Summary

  • Replace the CGO-based SQLite driver (mattn/go-sqlite3) with the pure-Go driver (modernc.org/sqlite), eliminating the need for a C compiler at build time
  • Update driver name ("sqlite3" ? "sqlite"), DSN pragma syntax (_key=value ? _pragma=key(value)), and all build files to set CGO_ENABLED=0
  • Simplify Dockerfile builder stage from golang:1.26-bookworm with gcc/libsqlite3-dev to golang:1.26-alpine, and remove sqlite-libs runtime dependency from both Dockerfiles

Motivation

This is a prerequisite for #151 (multi-platform builds). With CGO eliminated, GoReleaser can cross-compile to Linux ARM64, macOS amd64, and macOS ARM64 without C cross-compilers or osxcross.

What changed

File Change
internal/audit/audit.go Import modernc.org/sqlite, driver name "sqlite", _pragma= DSN syntax
internal/audit/migrate_test.go Same driver/DSN updates for pre-migration test
.goreleaser.yaml CGO_ENABLED=0
Dockerfile Alpine builder, no gcc/libsqlite3-dev, no sqlite-libs at runtime
Dockerfile.ci No sqlite-libs at runtime
internal/testutil/binary.go CGO_ENABLED=0 for E2E test binary build

Existing virtwork.db files remain compatible ? same SQLite file format.

Resolves #150

…e and DSN

Prepare for CGO-free SQLite driver migration by updating the
pre-migration test to use the "sqlite" driver name and pragma()
DSN syntax expected by modernc.org/sqlite.

This test intentionally fails until the driver is swapped.

Resolves #150

Signed-off-by: Melvin Hillsman <mhillsma@redhat.com>
Switch to the pure-Go SQLite driver, eliminating the CGO build
requirement. The driver name changes from "sqlite3" to "sqlite"
and DSN pragmas use function-call syntax (_pragma=key(value)).

Existing virtwork.db files remain compatible — same SQLite format.

Resolves #150

Signed-off-by: Melvin Hillsman <mhillsma@redhat.com>
With modernc.org/sqlite (pure Go), CGO is no longer needed.

- .goreleaser.yaml: CGO_ENABLED=0
- Dockerfile: switch to alpine builder, drop gcc/libsqlite3-dev/sqlite-libs
- Dockerfile.ci: drop sqlite-libs runtime dependency
- testutil/binary.go: build E2E binary with CGO_ENABLED=0

Resolves #150

Signed-off-by: Melvin Hillsman <mhillsma@redhat.com>
@exe-prow-github-app exe-prow-github-app Bot requested a review from OchiengEd May 30, 2026 15:21
@exe-prow-github-app

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mrhillsman

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@exe-prow-github-app exe-prow-github-app Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 30, 2026
@mrhillsman mrhillsman merged commit 435aeea into main May 30, 2026
3 of 4 checks passed
@mrhillsman mrhillsman deleted the 150-replace-cgo-sqlite-driver branch May 31, 2026 04:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace mattn/go-sqlite3 with modernc.org/sqlite to remove CGO dependency

1 participant