~bigbes/sr-ht-dolt

ref: 11c622f38dc9e15a1c23880fca39e2f6b1d8b1b1 sr-ht-dolt/APKBUILD -rw-r--r-- 5.3 KiB
11c622f3 — Eugene Blikh web: stop printing browse errors to the reader 5 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Maintainer: bigbes <bigbes@gmail.com>
#
# Built by builds.sr.ht (.build.yml) and published to our own apk repo at
# repo.bigb.es/alpine/v3.22/bigbes. The srht deployment installs it from there
# instead of cloning and compiling this repo inside its Dockerfile.
#
# pkgver is READ FROM THE ENVIRONMENT and must stay that way. CI used to `sed`
# the literal below in place before calling abuild; that rewrites a tracked file
# inside the checkout, and Go decides half of the VCS stamp it puts into every
# binary — vcs.modified — from exactly that. Measured on go1.26.5: one `sed` of
# APKBUILD makes every binary abuild compiles afterwards record itself as
# "<sha>-dirty" for the life of the apk. The export cannot do that. .gitignore
# covers the rest of what abuild writes into this directory.
#
# .build.yml's version task exports PKGVER out of a single `git describe`: a tag
# (v0.2.0 -> 0.2.0), a tag plus commits since it (0.2.0_git7, which sorts AFTER
# the release in Alpine's grammar), or 0.0.<commit count> when there is no tag —
# which is where this repository stands today. A local `abuild` has no PKGVER
# and builds 0.0.0, which is what a package built by hand honestly is.
pkgname=dolt.sr.ht
pkgver="${PKGVER:-0.0.0}"
pkgrel=0
pkgdesc="Dolt database hosting for a sourcehut instance"
url="https://sourcecraft.dev/bigbes/sr-ht-dolt"
arch="x86_64"
license="MIT"
# !check      — the suites are run by the `test` task of .build.yml, against the
#               Postgres that manifest brings up, and they run BEFORE this
#               package is built. Letting abuild run them again would repeat the
#               work with DOLTSRHT_TEST_PG unset, i.e. with 9 of db/'s 10 tests
#               skipping. What makes this option honest rather than a licence to
#               ship untested code is that task's DSN guard: an empty
#               DOLTSRHT_TEST_PG fails it loudly instead of skipping the
#               database suites and going green.
# !tracedeps  — CGO_ENABLED=0 with -tags gms_pure_go, so the binaries are
#               static: no ICU, no gozstd, nothing to trace
options="!check !tracedeps"
# The hook subpackage carries dolt-git-hook alone: it is installed into the
# git.sr.ht container (as its post-update-script), not the dolt one, and
# pulling the full service package in there would drag doltsrht along.
subpackages="$pkgname-hook:hook"

source=""
builddir="$startdir"

# The pure-Go build tag is what keeps this package free of cgo: it selects
# go-mysql-server's stdlib regexp instead of go-icu-regex (the SQL engine is
# never run here), and a replace directive backs gozstd with a klauspost shim.
# Dropping it would pull in libicu and make the package arch/libc-specific.
export GO_TAGS="gms_pure_go"

build() {
	cd "$builddir"
	# abuild redirects GOCACHE into $tmpdir (wiped after packaging), and an
	# upstream typo makes GOMODCACHE follow GOCACHE's value rather than its
	# own. Re-pin both to the stable home locations here — after abuild's own
	# exports — so CI's cache_restore/cache_save tasks see them survive.
	export GOCACHE="$HOME/.cache/go-build"
	export GOMODCACHE="$HOME/go/pkg/mod"
	# `make all` is all-bin ONLY — this Makefile deliberately keeps the CSS off
	# the default path because sassc/minify aren't always on a dev machine. So
	# `css` has to be asked for by name; building `all` alone silently produces
	# a package with no stylesheet.
	#
	# -trimpath so the binaries do not carry this builder's directory layout,
	# and -modcacherw for a reason beyond tidiness: without it the module cache
	# is left read-only, and the CI cache tarball made from it cannot be
	# unpacked on the next build (mkdir into 0555 dirs fails).
	CGO_ENABLED=0 make all-bin GO_TAGS="$GO_TAGS" GOFLAGS="-trimpath -modcacherw"
	# Needs the shared sourcehut scss partials pre-assembled at ASSETS/scss (no
	# apk ships them); CI does that before calling abuild.
	make css ASSETS=/usr/share/sourcehut

	# install-share copies static/*.css under `2>/dev/null || true`, so a
	# stylesheet that never got built would ship as an unstyled service without
	# failing anything. Assert instead. `make check-css` and not the `ls` that
	# stood here: two hashed stylesheets are as wrong as none and quieter, since
	# web/router.go resolves the glob and takes the first match.
	make check-css
}

package() {
	cd "$builddir"
	# This Makefile's install rules do not honour DESTDIR (they write to
	# $(BINDIR)/$(SHAREDIR) directly), so the staging dir is passed as PREFIX.
	# MIGRATIONDIR and STATICDIR are both derived from SHAREDIR, so they follow.
	#
	# `install-files` and not `install`, and no CGO_ENABLED or GOFLAGS beside it,
	# because this function must not compile anything. abuild runs package() in a
	# FRESH abuild process under fakeroot (abuild.in's rootpkg), which re-sources
	# this file and never calls build(): the cache pins above are gone here and
	# cannot be restored — abuild's own GOMODCACHE line overwrites them — so a
	# `make install` staged a second compilation of all three binaries, made from
	# a cold module cache and with none of the flags above, and it was that copy
	# that went into the apk while build()'s checks were left behind with the
	# copy nobody shipped.
	make install-files PREFIX="$pkgdir/usr"
}

hook() {
	pkgdesc="post-update hook that provisions companion Dolt databases (for the git.sr.ht container)"
	amove usr/bin/dolt-git-hook
}