Skip to content

Commit baf51b9

Browse files
authored
refactor: switch to cgo-free sqlite library (#56)
* chore: update deps Signed-off-by: Jian Zeng <anonymousknight96@gmail.com> * refactor: change sqlite library Signed-off-by: Jian Zeng <anonymousknight96@gmail.com> * chore: update config files Signed-off-by: Jian Zeng <anonymousknight96@gmail.com> * chore: update release workflow Signed-off-by: Jian Zeng <anonymousknight96@gmail.com> * doc: update README Signed-off-by: Jian Zeng <anonymousknight96@gmail.com> --------- Signed-off-by: Jian Zeng <anonymousknight96@gmail.com>
1 parent 56be740 commit baf51b9

File tree

11 files changed

+59
-75
lines changed

11 files changed

+59
-75
lines changed

.dockerignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
/yukid
21
/yukictl

.github/workflows/release.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ jobs:
2424
with:
2525
go-version: stable
2626

27+
- name: Install Go
28+
uses: actions/setup-go@v5
29+
with:
30+
go-version: stable
31+
check-latest: true
32+
2733
- name: Set up Docker Buildx
2834
uses: docker/setup-buildx-action@v3
2935

@@ -34,6 +40,10 @@ jobs:
3440
username: ${{ github.actor }}
3541
password: ${{ secrets.GITHUB_TOKEN }}
3642

43+
- name: Build yukid
44+
run: |
45+
CGO_ENABLED=0 make yukid
46+
3747
- name: Build and Push Image
3848
uses: docker/build-push-action@v5
3949
with:

.goreleaser.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ builds:
66
id: yukid
77
binary: yukid
88
env:
9-
# required by sqlite lib
10-
- CGO_ENABLED=1
9+
- CGO_ENABLED=0
1110
main: ./cmd/yukid
1211
goos:
1312
- linux

Dockerfile

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
# syntax=docker/dockerfile:1
2-
3-
FROM golang:1.21-bookworm AS build
4-
WORKDIR /app
5-
RUN --mount=type=cache,target=/root/.cache/go-build \
6-
--mount=type=cache,target=/go/pkg/mod \
7-
--mount=type=bind,target=/app \
8-
OUT_DIR=/tmp make yukid
9-
101
FROM debian:bookworm-slim
11-
RUN apt update && apt install -y sqlite3 && rm -rf /var/lib/apt/lists/*
12-
COPY --link --from=build /tmp/yukid /yukid
2+
COPY ./yukid /yukid
133
CMD ["/yukid"]

Makefile

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,18 @@ integration-test:
1212

1313
git_commit := $(shell git rev-parse HEAD)
1414
build_date := $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
15-
16-
VERSION ?= $(shell git describe --tags)
17-
OUT_DIR ?= $(PWD)
15+
version ?= $(shell git describe --tags)
1816

1917
.PHONY: yukid
2018
yukid:
2119
go build -ldflags "-X github.com/ustclug/Yuki/pkg/info.BuildDate=$(build_date) \
2220
-X github.com/ustclug/Yuki/pkg/info.GitCommit=$(git_commit) \
23-
-X github.com/ustclug/Yuki/pkg/info.Version=$(VERSION)" \
24-
-trimpath -o $(OUT_DIR)/yukid ./cmd/yukid
21+
-X github.com/ustclug/Yuki/pkg/info.Version=$(version)" \
22+
-trimpath ./cmd/yukid
2523

2624
.PHONY: yukictl
2725
yukictl:
2826
go build -ldflags "-X github.com/ustclug/Yuki/pkg/info.BuildDate=$(build_date) \
2927
-X github.com/ustclug/Yuki/pkg/info.GitCommit=$(git_commit) \
3028
-X github.com/ustclug/Yuki/pkg/info.Version=$(version)" \
3129
-trimpath ./cmd/yukictl
32-
33-
BUILD_IMAGE ?= golang:1.21-bookworm
34-
35-
.PHONY: yukid-linux
36-
yukid-linux:
37-
@docker run \
38-
--rm \
39-
--mount source=go-cache,destination=/root/.cache/go-build \
40-
--mount source=go-mod,destination=/go/pkg/mod \
41-
-v $(PWD):/app \
42-
$(BUILD_IMAGE) \
43-
bash -c 'cd /app && make yukid'

README.md

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ README
77
- [Requirements](#requirements)
88
- [Quickstart](#quickstart)
99
- [Handbook](#handbook)
10-
- [Troubleshooting](#troubleshooting)
1110
- [Development](#development)
1211

1312
Sync local repositories with remote.
@@ -109,30 +108,6 @@ For post sync hook, the environment variables that are passed to the hook script
109108
* `Dir` -> `DIR`: the directory of the repository
110109
* `Name` -> `NAME`: the name of the repository
111110

112-
## Troubleshooting
113-
114-
### version `GLIBC_2.XX' not found
115-
116-
You might encounter the following error when running yukid:
117-
118-
```
119-
$ ./yukid -V
120-
./yukid: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by ./yukid)
121-
./yukid: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.32' not found (required by ./yukid)
122-
./yukid: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by ./yukid)
123-
```
124-
125-
This is because `yukid` is complied with CGO enabled, which is required by https://github.com/mattn/go-sqlite3.
126-
The version of glibc that is linked to `yukid` might differ from the actual one that exists on your current machine.
127-
You will need to compile `yukid` on your current machine or run `yukid` in container.
128-
129-
Tips:
130-
* To check your current glibc version:
131-
```
132-
$ /lib/x86_64-linux-gnu/libc.so.6 | grep -i glibc
133-
```
134-
* The docker images of `yukid`: https://github.com/ustclug/Yuki/pkgs/container/yukid
135-
136111
## Development
137112

138113
* Build `yukid`:

go.mod

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.21
55
require (
66
github.com/cpuguy83/go-docker v0.3.0
77
github.com/docker/go-units v0.5.0
8+
github.com/glebarez/sqlite v1.10.0
89
github.com/go-playground/validator/v10 v10.17.0
910
github.com/go-resty/resty/v2 v2.11.0
1011
github.com/labstack/echo/v4 v4.11.4
@@ -15,20 +16,22 @@ require (
1516
github.com/spf13/viper v1.18.2
1617
github.com/stretchr/testify v1.8.4
1718
golang.org/x/sync v0.6.0
18-
gorm.io/driver/sqlite v1.5.4
19-
gorm.io/gorm v1.25.5
19+
gorm.io/gorm v1.25.6
2020
sigs.k8s.io/yaml v1.4.0
2121
)
2222

2323
require (
2424
github.com/Microsoft/go-winio v0.6.1 // indirect
2525
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
26+
github.com/dustin/go-humanize v1.0.1 // indirect
2627
github.com/fsnotify/fsnotify v1.7.0 // indirect
2728
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
29+
github.com/glebarez/go-sqlite v1.21.2 // indirect
2830
github.com/go-playground/locales v0.14.1 // indirect
2931
github.com/go-playground/universal-translator v0.18.1 // indirect
3032
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
3133
github.com/google/go-cmp v0.6.0 // indirect
34+
github.com/google/uuid v1.4.0 // indirect
3235
github.com/hashicorp/hcl v1.0.0 // indirect
3336
github.com/inconshreveable/mousetrap v1.1.0 // indirect
3437
github.com/jinzhu/inflection v1.0.0 // indirect
@@ -38,10 +41,10 @@ require (
3841
github.com/magiconair/properties v1.8.7 // indirect
3942
github.com/mattn/go-colorable v0.1.13 // indirect
4043
github.com/mattn/go-isatty v0.0.20 // indirect
41-
github.com/mattn/go-sqlite3 v1.14.19 // indirect
4244
github.com/mitchellh/mapstructure v1.5.0 // indirect
4345
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
4446
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
47+
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
4548
github.com/sagikazarmark/locafero v0.4.0 // indirect
4649
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
4750
github.com/sourcegraph/conc v0.3.0 // indirect
@@ -62,4 +65,8 @@ require (
6265
gopkg.in/ini.v1 v1.67.0 // indirect
6366
gopkg.in/yaml.v3 v3.0.1 // indirect
6467
gotest.tools/v3 v3.5.1 // indirect
68+
modernc.org/libc v1.22.5 // indirect
69+
modernc.org/mathutil v1.5.0 // indirect
70+
modernc.org/memory v1.5.0 // indirect
71+
modernc.org/sqlite v1.23.1 // indirect
6572
)

go.sum

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,18 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
99
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1010
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
1111
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
12+
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
13+
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
1214
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
1315
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
1416
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
1517
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
1618
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
1719
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
20+
github.com/glebarez/go-sqlite v1.21.2 h1:3a6LFC4sKahUunAmynQKLZceZCOzUthkRkEAl9gAXWo=
21+
github.com/glebarez/go-sqlite v1.21.2/go.mod h1:sfxdZyhQjTM2Wry3gVYWaW072Ri1WMdWJi0k6+3382k=
22+
github.com/glebarez/sqlite v1.10.0 h1:u4gt8y7OND/cCei/NMHmfbLxF6xP2wgKcT/BJf2pYkc=
23+
github.com/glebarez/sqlite v1.10.0/go.mod h1:IJ+lfSOmiekhQsFTJRx/lHtGYmCdtAiTaf5wI9u5uHA=
1824
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
1925
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
2026
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
@@ -30,6 +36,10 @@ github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzq
3036
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
3137
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
3238
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
39+
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbuBVKCudVG457BR2GZFIz3uw3hQ=
40+
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo=
41+
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
42+
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
3343
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
3444
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
3545
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
@@ -55,8 +65,6 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk
5565
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
5666
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
5767
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
58-
github.com/mattn/go-sqlite3 v1.14.19 h1:fhGleo2h1p8tVChob4I9HpmVFIAkKGpiukdrgQbWfGI=
59-
github.com/mattn/go-sqlite3 v1.14.19/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
6068
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
6169
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
6270
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
@@ -68,6 +76,9 @@ github.com/pelletier/go-toml/v2 v2.1.1/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdU
6876
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
6977
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
7078
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
79+
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
80+
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
81+
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
7182
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
7283
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
7384
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
@@ -173,11 +184,17 @@ gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
173184
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
174185
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
175186
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
176-
gorm.io/driver/sqlite v1.5.4 h1:IqXwXi8M/ZlPzH/947tn5uik3aYQslP9BVveoax0nV0=
177-
gorm.io/driver/sqlite v1.5.4/go.mod h1:qxAuCol+2r6PannQDpOP1FP6ag3mKi4esLnB/jHed+4=
178-
gorm.io/gorm v1.25.5 h1:zR9lOiiYf09VNh5Q1gphfyia1JpiClIWG9hQaxB/mls=
179-
gorm.io/gorm v1.25.5/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
187+
gorm.io/gorm v1.25.6 h1:V92+vVda1wEISSOMtodHVRcUIOPYa2tgQtyF+DfFx+A=
188+
gorm.io/gorm v1.25.6/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
180189
gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU=
181190
gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU=
191+
modernc.org/libc v1.22.5 h1:91BNch/e5B0uPbJFgqbxXuOnxBQjlS//icfQEGmvyjE=
192+
modernc.org/libc v1.22.5/go.mod h1:jj+Z7dTNX8fBScMVNRAYZ/jF91K8fdT2hYMThc3YjBY=
193+
modernc.org/mathutil v1.5.0 h1:rV0Ko/6SfM+8G+yKiyI830l3Wuz1zRutdslNoQ0kfiQ=
194+
modernc.org/mathutil v1.5.0/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
195+
modernc.org/memory v1.5.0 h1:N+/8c5rE6EqugZwHii4IFsaJ7MUhoWX07J5tC/iI5Ds=
196+
modernc.org/memory v1.5.0/go.mod h1:PkUhL0Mugw21sHPeskwZW4D6VscE/GQJOnIpCnW6pSU=
197+
modernc.org/sqlite v1.23.1 h1:nrSBg4aRQQwq59JpvGEQ15tNxoO5pX/kUjcRNwSAGQM=
198+
modernc.org/sqlite v1.23.1/go.mod h1:OrDj17Mggn6MhE+iPbBNf7RGKODDE9NFT0f3EwDzJqk=
182199
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
183200
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=

pkg/model/migrate.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
package model
22

33
import (
4+
"fmt"
5+
46
"gorm.io/gorm"
57
)
68

79
func AutoMigrate(db *gorm.DB) error {
10+
// enable WAL mode by default to improve performance
11+
err := db.Exec("PRAGMA journal_mode=WAL").Error
12+
if err != nil {
13+
return fmt.Errorf("set WAL mode: %w", err)
14+
}
815
return db.AutoMigrate(&Repo{}, &RepoMeta{})
916
}

pkg/server/main.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@ import (
88
"log/slog"
99
"net/http"
1010
"os"
11-
"strings"
1211

12+
"github.com/glebarez/sqlite"
1313
"github.com/go-playground/validator/v10"
1414
"github.com/labstack/echo/v4"
1515
"github.com/labstack/echo/v4/middleware"
1616
cmap "github.com/orcaman/concurrent-map/v2"
1717
"github.com/robfig/cron/v3"
1818
"github.com/spf13/viper"
19-
"gorm.io/driver/sqlite"
2019
"gorm.io/gorm"
2120

2221
"github.com/ustclug/Yuki/pkg/docker"
@@ -54,12 +53,7 @@ func New(configPath string) (*Server, error) {
5453
}
5554

5655
func NewWithConfig(cfg Config) (*Server, error) {
57-
dbURL := cfg.DbURL
58-
if !strings.ContainsRune(dbURL, '?') {
59-
// enable WAL mode by default to improve performance
60-
dbURL += "?_journal_mode=WAL"
61-
}
62-
db, err := gorm.Open(sqlite.Open(dbURL), &gorm.Config{
56+
db, err := gorm.Open(sqlite.Open(cfg.DbURL), &gorm.Config{
6357
QueryFields: true,
6458
})
6559
if err != nil {

0 commit comments

Comments
 (0)