FROM golang:1.26-alpine AS builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
ARG VERSION=dev
RUN CGO_ENABLED=0 GOOS=linux go build \
    -ldflags="-s -w" \
    -o spa-server \
    ./cmd/spa-server

FROM alpine:3.21
RUN apk add --no-cache ca-certificates tzdata
WORKDIR /app
COPY --from=builder /app/spa-server .

ARG VERSION=dev
ARG GIT_SHA=unknown
ARG BASE_DIGEST=

LABEL org.opencontainers.image.source="https://code.nochebuena.dev/einherjar/spa-server"
LABEL org.opencontainers.image.version="$VERSION"
LABEL org.opencontainers.image.revision="$GIT_SHA"
LABEL org.opencontainers.image.base.name="alpine:3.21"
LABEL org.opencontainers.image.base.digest="$BASE_DIGEST"
LABEL dev.nochebuena.healthz="/health"

# Mount your SPA dist/ here, or COPY it in a downstream Dockerfile.
VOLUME ["/srv/www"]
EXPOSE 8080
ENTRYPOINT ["/app/spa-server"]
