Skip to content

[fix] Docker build fails with "LoadExtension undefined" after PR #131 #135

@hrygo

Description

@hrygo

问题描述

Docker 镜像构建失败,错误信息:

store/db/sqlite/sqlite_extension.go:35:21: sqliteConn.LoadExtension undefined 
(type *sqlite3.SQLiteConn has no field or method LoadExtension)

CI 失败链接: https://github.com/hrygo/divinesense/actions/runs/21849819582/job/63053719047

根本原因

PR #131 将 SQLite 驱动从 modernc.org/sqlite (pure Go) 切换到 mattn/go-sqlite3 (CGO),并引入了 sqlite_extension.go 使用 LoadExtension() 方法。

但 Dockerfile 使用 CGO_ENABLED=0 进行静态编译:

RUN --mount=type=cache,target=/go/pkg/mod \
    --mount=type=cache,target=/root/.cache/go-build \
    CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH \
    go build ...

LoadExtension() 方法只在 CGO 模式下可用,导致编译失败。

解决方案

store/db/sqlite/sqlite_extension.go 顶部添加 CGO build tag 约束:

//go:build cgo
// +build cgo

package sqlite

// ... rest of the file

这样该文件只在 CGO 环境下编译,非 CGO 环境(如 Docker 静态构建)会跳过它。

影响范围

  • CI/CD: build-and-push-canary-image.yml 工作流失败
  • Docker 镜像构建无法完成
  • 阻止 main 分支的正常部署

关联 PR

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions