BlueGit

timfa bluegit

fix: geef de bouwgebruiker een homedir en een cache in de werkmap

sysusers schrijft /var/lib/bluegit-build alleen in passwd. tmpfiles maakt
de map. Go gebruikt tot die tijd GOCACHE en GOPATH onder de werkmap, ook
in de PKGBUILD die de nu geïnstalleerde updater bouwt.

Co-authored-by: tim <tim@timfalken.com>

timfa project_87923614_bot_3aff574f6f98414b945a8799374f9092 · pushed by timfa

Authored 2026-10-23 · 3 weeks ago

Hash
1c1a6b9b5d1271f14c5b379dc2c409c72c49a64c
Parent
89a156fd
5 files changed +25 −5
internal/update/packaging_test.go +14 −3
@@ -69,6 +69,13 @@ func TestPackagingFiles(t *testing.T) {
69 69 if !strings.Contains(string(sysusers), "u bluegit-build ") {
70 70 t.Fatal("sysusers mist bluegit-build")
71 71 }
72 tmpfiles, err := os.ReadFile(filepath.Join(base, "packaging", "tmpfiles.conf"))
73 if err != nil {
74 t.Fatal(err)
75 }
76 if !strings.Contains(string(tmpfiles), "d /var/lib/bluegit-build 0750 bluegit-build bluegit-build -") {
77 t.Fatal("tmpfiles maakt /var/lib/bluegit-build niet")
78 }
72 79 hook, err := os.ReadFile(filepath.Join(base, "packaging", "aur", "bluegit.install"))
73 80 if err != nil {
74 81 t.Fatal(err)
@@ -76,6 +83,9 @@ func TestPackagingFiles(t *testing.T) {
76 83 if !strings.Contains(string(hook), "bluegit-build") || !strings.Contains(string(hook), "systemd-sysusers bluegit.conf") {
77 84 t.Fatal("install-hook maakt de bouwgebruiker niet")
78 85 }
86 if !strings.Contains(string(hook), "systemd-tmpfiles --create bluegit.conf") {
87 t.Fatal("install-hook maakt de homedir van bluegit-build niet")
88 }
79 89 if !strings.Contains(string(hook), "try-restart bluegit.service") {
80 90 t.Fatal("upgrade hoort de service te herstarten")
81 91 }
@@ -201,7 +211,7 @@ func TestMakepkgRunsBesidePkgbuild(t *testing.T) {
201 211 bin := t.TempDir()
202 212 record := filepath.Join(t.TempDir(), "pwd")
203 213 runuser := "#!/bin/bash\nset -euo pipefail\nwhile [[ $# -gt 0 && \"$1\" != \"--\" ]]; do shift; done\n[[ $# -gt 0 ]] || exit 1\nshift\nexec \"$@\"\n"
204 makepkg := "#!/bin/bash\nset -euo pipefail\npwd > " + shellQuote(record) + "\n[[ -f PKGBUILD ]]\n"
214 makepkg := "#!/bin/bash\nset -euo pipefail\n{\nprintf '%s\\n' \"$(pwd)\"\nprintf '%s\\n' \"$GOCACHE\"\nprintf '%s\\n' \"$GOPATH\"\n} > " + shellQuote(record) + "\n[[ -f PKGBUILD ]]\n"
205 215 if err := os.WriteFile(filepath.Join(bin, "runuser"), []byte(runuser), 0o755); err != nil {
206 216 t.Fatal(err)
207 217 }
@@ -219,8 +229,9 @@ func TestMakepkgRunsBesidePkgbuild(t *testing.T) {
219 229 if err != nil {
220 230 t.Fatal(err)
221 231 }
222 if strings.TrimSpace(string(raw)) != work {
223 t.Fatalf("makepkg draaide in %q, PKGBUILD staat in %q", strings.TrimSpace(string(raw)), work)
232 lines := strings.Split(strings.TrimRight(string(raw), "\n"), "\n")
233 if len(lines) != 3 || lines[0] != work || lines[1] != filepath.Join(work, "gocache") || lines[2] != filepath.Join(work, "gopath") {
234 t.Fatalf("makepkg zag %q, verwacht cwd %s en cache daaronder", lines, work)
224 235 }
225 236 }
226 237
@@ -69,6 +69,13 @@ func TestPackagingFiles(t *testing.T) {
69 if !strings.Contains(string(sysusers), "u bluegit-build ") {
69 if !strings.Contains(string(sysusers), "u bluegit-build ") {
70 t.Fatal("sysusers mist bluegit-build")
70 t.Fatal("sysusers mist bluegit-build")
71 }
71 }
72 tmpfiles, err := os.ReadFile(filepath.Join(base, "packaging", "tmpfiles.conf"))
73 if err != nil {
74 t.Fatal(err)
75 }
76 if !strings.Contains(string(tmpfiles), "d /var/lib/bluegit-build 0750 bluegit-build bluegit-build -") {
77 t.Fatal("tmpfiles maakt /var/lib/bluegit-build niet")
78 }
72 hook, err := os.ReadFile(filepath.Join(base, "packaging", "aur", "bluegit.install"))
79 hook, err := os.ReadFile(filepath.Join(base, "packaging", "aur", "bluegit.install"))
73 if err != nil {
80 if err != nil {
74 t.Fatal(err)
81 t.Fatal(err)
@@ -76,6 +83,9 @@ func TestPackagingFiles(t *testing.T) {
76 if !strings.Contains(string(hook), "bluegit-build") || !strings.Contains(string(hook), "systemd-sysusers bluegit.conf") {
83 if !strings.Contains(string(hook), "bluegit-build") || !strings.Contains(string(hook), "systemd-sysusers bluegit.conf") {
77 t.Fatal("install-hook maakt de bouwgebruiker niet")
84 t.Fatal("install-hook maakt de bouwgebruiker niet")
78 }
85 }
86 if !strings.Contains(string(hook), "systemd-tmpfiles --create bluegit.conf") {
87 t.Fatal("install-hook maakt de homedir van bluegit-build niet")
88 }
79 if !strings.Contains(string(hook), "try-restart bluegit.service") {
89 if !strings.Contains(string(hook), "try-restart bluegit.service") {
80 t.Fatal("upgrade hoort de service te herstarten")
90 t.Fatal("upgrade hoort de service te herstarten")
81 }
91 }
@@ -201,7 +211,7 @@ func TestMakepkgRunsBesidePkgbuild(t *testing.T) {
201 bin := t.TempDir()
211 bin := t.TempDir()
202 record := filepath.Join(t.TempDir(), "pwd")
212 record := filepath.Join(t.TempDir(), "pwd")
203 runuser := "#!/bin/bash\nset -euo pipefail\nwhile [[ $# -gt 0 && \"$1\" != \"--\" ]]; do shift; done\n[[ $# -gt 0 ]] || exit 1\nshift\nexec \"$@\"\n"
213 runuser := "#!/bin/bash\nset -euo pipefail\nwhile [[ $# -gt 0 && \"$1\" != \"--\" ]]; do shift; done\n[[ $# -gt 0 ]] || exit 1\nshift\nexec \"$@\"\n"
204 makepkg := "#!/bin/bash\nset -euo pipefail\npwd > " + shellQuote(record) + "\n[[ -f PKGBUILD ]]\n"
214 makepkg := "#!/bin/bash\nset -euo pipefail\n{\nprintf '%s\\n' \"$(pwd)\"\nprintf '%s\\n' \"$GOCACHE\"\nprintf '%s\\n' \"$GOPATH\"\n} > " + shellQuote(record) + "\n[[ -f PKGBUILD ]]\n"
205 if err := os.WriteFile(filepath.Join(bin, "runuser"), []byte(runuser), 0o755); err != nil {
215 if err := os.WriteFile(filepath.Join(bin, "runuser"), []byte(runuser), 0o755); err != nil {
206 t.Fatal(err)
216 t.Fatal(err)
207 }
217 }
@@ -219,8 +229,9 @@ func TestMakepkgRunsBesidePkgbuild(t *testing.T) {
219 if err != nil {
229 if err != nil {
220 t.Fatal(err)
230 t.Fatal(err)
221 }
231 }
222 if strings.TrimSpace(string(raw)) != work {
232 lines := strings.Split(strings.TrimRight(string(raw), "\n"), "\n")
223 t.Fatalf("makepkg draaide in %q, PKGBUILD staat in %q", strings.TrimSpace(string(raw)), work)
233 if len(lines) != 3 || lines[0] != work || lines[1] != filepath.Join(work, "gocache") || lines[2] != filepath.Join(work, "gopath") {
234 t.Fatalf("makepkg zag %q, verwacht cwd %s en cache daaronder", lines, work)
224 }
235 }
225}
236}
226
237
packaging/aur/PKGBUILD +4 −0
@@ -19,6 +19,10 @@ build() {
19 19 cd "$srcdir/bluegit-${_commit}"
20 20 export CGO_ENABLED=0
21 21 export GOFLAGS='-trimpath'
22 # De geïnstalleerde updater zet HOME op /var/lib/bluegit-build. Die map
23 # bestaat pas na tmpfiles, dus deze bouw mag daar niet schrijven.
24 export GOCACHE="${BUILDDIR:-$srcdir}/gocache"
25 export GOPATH="${BUILDDIR:-$srcdir}/gopath"
22 26 go build -ldflags='-s -w' -o bluegit ./cmd/bluegit
23 27 }
24 28
@@ -19,6 +19,10 @@ build() {
19 cd "$srcdir/bluegit-${_commit}"
19 cd "$srcdir/bluegit-${_commit}"
20 export CGO_ENABLED=0
20 export CGO_ENABLED=0
21 export GOFLAGS='-trimpath'
21 export GOFLAGS='-trimpath'
22 # De geïnstalleerde updater zet HOME op /var/lib/bluegit-build. Die map
23 # bestaat pas na tmpfiles, dus deze bouw mag daar niet schrijven.
24 export GOCACHE="${BUILDDIR:-$srcdir}/gocache"
25 export GOPATH="${BUILDDIR:-$srcdir}/gopath"
22 go build -ldflags='-s -w' -o bluegit ./cmd/bluegit
26 go build -ldflags='-s -w' -o bluegit ./cmd/bluegit
23}
27}
24
28
packaging/bluegit-update.sh +4 −0
@@ -107,11 +107,15 @@ prepare_build() {
107 107
108 108 # runuser houdt de cwd van de unit. Die is /, dus makepkg meldt
109 109 # "PKGBUILD does not exist" tenzij we eerst naar de werkmap gaan.
110 # sysusers zet de homedir alleen in passwd. Zolang tmpfiles die map niet
111 # heeft aangemaakt, mag go daar geen cache schrijven.
110 112 build_package() {
111 113 local work="$1"
112 114 cd "$work"
113 115 runuser -u "$BLUEGIT_BUILD_USER" -- env \
114 116 HOME="/var/lib/${BLUEGIT_BUILD_USER}" \
117 GOCACHE="$work/gocache" \
118 GOPATH="$work/gopath" \
115 119 BUILDDIR="$work/build" \
116 120 SRCDEST="$work" \
117 121 PKGDEST="$work/pkg" \
@@ -107,11 +107,15 @@ prepare_build() {
107
107
108# runuser houdt de cwd van de unit. Die is /, dus makepkg meldt
108# runuser houdt de cwd van de unit. Die is /, dus makepkg meldt
109# "PKGBUILD does not exist" tenzij we eerst naar de werkmap gaan.
109# "PKGBUILD does not exist" tenzij we eerst naar de werkmap gaan.
110# sysusers zet de homedir alleen in passwd. Zolang tmpfiles die map niet
111# heeft aangemaakt, mag go daar geen cache schrijven.
110build_package() {
112build_package() {
111 local work="$1"
113 local work="$1"
112 cd "$work"
114 cd "$work"
113 runuser -u "$BLUEGIT_BUILD_USER" -- env \
115 runuser -u "$BLUEGIT_BUILD_USER" -- env \
114 HOME="/var/lib/${BLUEGIT_BUILD_USER}" \
116 HOME="/var/lib/${BLUEGIT_BUILD_USER}" \
117 GOCACHE="$work/gocache" \
118 GOPATH="$work/gopath" \
115 BUILDDIR="$work/build" \
119 BUILDDIR="$work/build" \
116 SRCDEST="$work" \
120 SRCDEST="$work" \
117 PKGDEST="$work/pkg" \
121 PKGDEST="$work/pkg" \
packaging/tmpfiles.conf +1 −0
@@ -1 +1,2 @@
1 1 d /var/lib/bluegit 0750 bluegit bluegit -
2 d /var/lib/bluegit-build 0750 bluegit-build bluegit-build -
@@ -1 +1,2 @@
1d /var/lib/bluegit 0750 bluegit bluegit -
1d /var/lib/bluegit 0750 bluegit bluegit -
2d /var/lib/bluegit-build 0750 bluegit-build bluegit-build -
scripts/aur_test.go +2 −2
@@ -80,8 +80,8 @@ func TestRewritePkgbuild(t *testing.T) {
80 80 t.Fatal("hook hoort geen bestanden te verwijderen")
81 81 }
82 82 installBody, ok := shellFunc(hookText, "post_install")
83 if !ok || !strings.Contains(installBody, "enable --now bluegit.service") {
84 t.Fatal("post_install start de service niet")
83 if !ok || !strings.Contains(installBody, "enable --now bluegit.service") || !strings.Contains(installBody, "systemd-tmpfiles --create") {
84 t.Fatal("post_install start de service niet of maakt de homedir niet")
85 85 }
86 86 upgradeBody, ok := shellFunc(hookText, "post_upgrade")
87 87 if !ok || strings.Contains(upgradeBody, "post_install") || !strings.Contains(upgradeBody, "try-restart bluegit.service") {
@@ -80,8 +80,8 @@ func TestRewritePkgbuild(t *testing.T) {
80 t.Fatal("hook hoort geen bestanden te verwijderen")
80 t.Fatal("hook hoort geen bestanden te verwijderen")
81 }
81 }
82 installBody, ok := shellFunc(hookText, "post_install")
82 installBody, ok := shellFunc(hookText, "post_install")
83 if !ok || !strings.Contains(installBody, "enable --now bluegit.service") {
83 if !ok || !strings.Contains(installBody, "enable --now bluegit.service") || !strings.Contains(installBody, "systemd-tmpfiles --create") {
84 t.Fatal("post_install start de service niet")
84 t.Fatal("post_install start de service niet of maakt de homedir niet")
85 }
85 }
86 upgradeBody, ok := shellFunc(hookText, "post_upgrade")
86 upgradeBody, ok := shellFunc(hookText, "post_upgrade")
87 if !ok || strings.Contains(upgradeBody, "post_install") || !strings.Contains(upgradeBody, "try-restart bluegit.service") {
87 if !ok || strings.Contains(upgradeBody, "post_install") || !strings.Contains(upgradeBody, "try-restart bluegit.service") {