From 42cd73c5b8dc58c9dd19a80f50b912d9d21fc7d4 Mon Sep 17 00:00:00 2001 From: mrhid6 Date: Fri, 24 Jul 2026 13:45:45 +0100 Subject: [PATCH] build: build Go images from the repo root for the shared module Also pins the explicit shared require in both go.mod files. `go mod tidy` in workspace mode drops it, which breaks the Docker build where no workspace exists. --- .gitea/workflows/server-deploy.yml | 6 ++++-- server/Dockerfile | 19 ++++++++++++------- server/go.mod | 1 + sitesvc/Dockerfile | 13 ++++++++----- sitesvc/go.mod | 1 + 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/.gitea/workflows/server-deploy.yml b/.gitea/workflows/server-deploy.yml index 6f27bd8..c3dc78d 100644 --- a/.gitea/workflows/server-deploy.yml +++ b/.gitea/workflows/server-deploy.yml @@ -24,7 +24,8 @@ jobs: - name: Build and push server image run: | IMAGE="${{ vars.DOCKER_HOST }}/${{ github.repository_owner }}/vantage/server:latest" - docker build -t "$IMAGE" -f server/Dockerfile server/ + # Root context: server depends on the shared module. + docker build -t "$IMAGE" -f server/Dockerfile . docker push "$IMAGE" - name: Build and push web image @@ -49,5 +50,6 @@ jobs: - name: Build and push sitesvc image run: | IMAGE="${{ vars.DOCKER_HOST }}/${{ github.repository_owner }}/vantage/sitesvc:latest" - docker build -t "$IMAGE" -f sitesvc/Dockerfile sitesvc/ + # Root context: sitesvc depends on the shared module. + docker build -t "$IMAGE" -f sitesvc/Dockerfile . docker push "$IMAGE" diff --git a/server/Dockerfile b/server/Dockerfile index 89ad212..2cf4cfe 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -1,17 +1,22 @@ # Build stage +# +# Context is the repository root, not server/, because server depends on the +# shared module through a replace directive. FROM golang:1.26 AS builder -WORKDIR /app +WORKDIR /src -# Download dependencies first (layer cache) -COPY go.mod go.sum ./ -RUN go mod download +# Manifests first so the dependency layer caches independently of source edits. +COPY shared/go.mod shared/go.sum ./shared/ +COPY server/go.mod server/go.sum ./server/ +RUN cd server && go mod download -# Copy source and build -COPY . . +COPY shared/ ./shared/ +COPY server/ ./server/ ARG VERSION=dev -RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w -X main.Version=${VERSION}" -o /vantage-server ./cmd +RUN cd server && CGO_ENABLED=0 GOOS=linux go build \ + -ldflags="-s -w -X main.Version=${VERSION}" -o /vantage-server ./cmd # Runtime stage FROM scratch diff --git a/server/go.mod b/server/go.mod index a8bc080..46b15bc 100644 --- a/server/go.mod +++ b/server/go.mod @@ -36,6 +36,7 @@ require ( github.com/mattn/go-isatty v0.0.20 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/mrhid6/vantage/shared v0.0.0 github.com/pelletier/go-toml/v2 v2.2.2 // indirect github.com/sirupsen/logrus v1.4.2 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect diff --git a/sitesvc/Dockerfile b/sitesvc/Dockerfile index 97c124f..f39689b 100644 --- a/sitesvc/Dockerfile +++ b/sitesvc/Dockerfile @@ -1,13 +1,16 @@ +# Context is the repository root; sitesvc depends on the shared module. FROM golang:1.26-alpine AS builder -WORKDIR /app +WORKDIR /src -COPY go.mod go.sum ./ -RUN go mod download +COPY shared/go.mod shared/go.sum ./shared/ +COPY sitesvc/go.mod sitesvc/go.sum ./sitesvc/ +RUN cd sitesvc && go mod download -COPY . . +COPY shared/ ./shared/ +COPY sitesvc/ ./sitesvc/ -RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o /out/sitesvc ./cmd +RUN cd sitesvc && CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o /out/sitesvc ./cmd FROM alpine:3.20 AS runner diff --git a/sitesvc/go.mod b/sitesvc/go.mod index e28028d..f2bb26c 100644 --- a/sitesvc/go.mod +++ b/sitesvc/go.mod @@ -11,6 +11,7 @@ require ( require ( github.com/klauspost/compress v1.17.6 // indirect + github.com/mrhid6/vantage/shared v0.0.0 github.com/xdg-go/pbkdf2 v1.0.0 // indirect github.com/xdg-go/scram v1.2.0 // indirect github.com/xdg-go/stringprep v1.0.4 // indirect