From 8b28d7eb39ad89ba9336a720d98dc5aad4dc499c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20D=C3=BCren?= Date: Fri, 14 Mar 2025 23:41:56 +0100 Subject: [PATCH] Fix permission issues with go.mod by using a writable copy --- Dockerfile | 8 ++++++-- start.sh | 18 ++++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 105f98a..a7ff0d8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -98,14 +98,18 @@ WORKDIR /app/code # Clone the ente repository during build (for the Museum server) RUN git clone --depth=1 https://github.com/ente-io/ente.git . && \ - sed -i 's/go 1.23/go 1.24.1/' server/go.mod + sed -i 's/go 1.23/go 1.24.1/' server/go.mod && \ + mkdir -p /app/data/go && \ + cp -r server/go.mod server/go.sum /app/data/go/ && \ + chmod 777 /app/data/go/go.mod /app/data/go/go.sum # Set Go environment variables ENV GOTOOLCHAIN=local ENV GO111MODULE=on -ENV GOFLAGS="-mod=mod" +ENV GOFLAGS="-modfile=/app/data/go/go.mod -mod=mod" ENV PATH="/usr/local/go/bin:${PATH}" ENV GOSUMDB=off +ENV GOMODCACHE="/app/data/go/pkg/mod" # Copy the web app built files from the first stage COPY --from=web-builder /build/web/photos /app/web/photos diff --git a/start.sh b/start.sh index 53087f3..e3c46c7 100644 --- a/start.sh +++ b/start.sh @@ -318,7 +318,7 @@ if [ -x "$(command -v go)" ]; then # Don't try to modify the go.mod file since filesystem is read-only # Instead, use environment variables to override version requirements echo "==> Setting Go flags to override version requirements" - export GOFLAGS="-mod=mod" + export GOFLAGS="-modfile=/app/data/go/go.mod -mod=mod" export GO111MODULE=on export GOTOOLCHAIN=local fi @@ -354,8 +354,18 @@ export GOPATH=/app/data/go export GO111MODULE=on # Use local toolchain to avoid downloading required version export GOTOOLCHAIN=local + +# Ensure go.mod is in the writable directory +if [ ! -f "/app/data/go/go.mod" ] && [ -f "$SERVER_DIR/go.mod" ]; then + echo "==> Copying go.mod and go.sum to writable location" + mkdir -p /app/data/go + cp -f "$SERVER_DIR/go.mod" "$SERVER_DIR/go.sum" /app/data/go/ || echo "==> Warning: Could not copy go.mod/go.sum" + chmod 666 /app/data/go/go.mod /app/data/go/go.sum || echo "==> Warning: Could not set permissions" +fi + # Override version requirements and force module mode -export GOFLAGS="-mod=mod -modcacherw" +export GOFLAGS="-modfile=/app/data/go/go.mod -mod=mod -modcacherw" + # Create a temporary directory for Go module cache and build in writable area export GOCACHE=/app/data/go/cache export GOMODCACHE=/app/data/go/modcache @@ -433,7 +443,7 @@ elif [ -d "$SERVER_DIR/cmd/museum" ]; then # Instead of modifying go.mod, set environment variables for compatibility echo "==> Setting Go environment variables for compatibility" - export GOFLAGS="-mod=mod -modcacherw" + export GOFLAGS="-modfile=/app/data/go/go.mod -mod=mod -modcacherw" # Use local toolchain to avoid downloading required version export GOTOOLCHAIN=local @@ -513,7 +523,7 @@ else # Instead of trying to modify go.mod, set environment variables for compatibility echo "==> Setting Go environment variables for compatibility" - export GOFLAGS="-mod=mod -modcacherw" + export GOFLAGS="-modfile=/app/data/go/go.mod -mod=mod -modcacherw" export GOTOOLCHAIN=local echo "==> Running main.go with Go"