fix: set GOCACHE alongside GOMODCACHE for users without home write access

- Go build cache was trying to write to /app/.cache/go-build (unwritable)
- Now uses /opt/receiptnext/.go/build instead
This commit is contained in:
Claus Lohmar 2026-05-30 16:13:26 +00:00
parent de29841341
commit 51c5d9a23e

View file

@ -70,6 +70,10 @@ if [ "${1:-}" = "-update" ]; then
info "Rebuilding binary..." info "Rebuilding binary..."
if command -v go &>/dev/null; then if command -v go &>/dev/null; then
export GOMODCACHE="${INSTALL_DIR}/.go/mod"
export GOPATH="${INSTALL_DIR}/.go"
export GOCACHE="${INSTALL_DIR}/.go/build"
mkdir -p "${GOMODCACHE}" "${GOCACHE}" 2>/dev/null || sudo_if mkdir -p "${GOMODCACHE}" "${GOCACHE}"
CGO_ENABLED=0 go build -ldflags="-s -w" -o app . CGO_ENABLED=0 go build -ldflags="-s -w" -o app .
else else
warn "Go not found — downloading pre-built binary..." warn "Go not found — downloading pre-built binary..."
@ -126,10 +130,11 @@ esac
if command -v go &>/dev/null; then if command -v go &>/dev/null; then
info "Building binary from source (pure Go, no CGO)..." info "Building binary from source (pure Go, no CGO)..."
# Use a writable module cache — the user's home may not be writable # Use a writable cache — the user's home (/app/) may not be writable
export GOMODCACHE="${INSTALL_DIR}/.go/mod" export GOMODCACHE="${INSTALL_DIR}/.go/mod"
export GOPATH="${INSTALL_DIR}/.go" export GOPATH="${INSTALL_DIR}/.go"
mkdir -p "${GOMODCACHE}" 2>/dev/null || sudo_if mkdir -p "${GOMODCACHE}" export GOCACHE="${INSTALL_DIR}/.go/build"
mkdir -p "${GOMODCACHE}" "${GOCACHE}" 2>/dev/null || sudo_if mkdir -p "${GOMODCACHE}" "${GOCACHE}"
CGO_ENABLED=0 go build -ldflags="-s -w" -o app . CGO_ENABLED=0 go build -ldflags="-s -w" -o app .
else else
info "Go not found — downloading pre-built binary..." info "Go not found — downloading pre-built binary..."