# Supermarket's web app. Built locally by install.sh / update.sh through
# compose.yaml; nothing is pulled from a registry but the base images.

FROM golang:1.26-alpine AS build
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
ARG VERSION=dev
RUN CGO_ENABLED=0 go build -trimpath -ldflags "-s -w -X 'main.version=${VERSION}'" \
      -o /out/supermarket ./cmd/supermarket

FROM alpine:3.22
# git and hugo: for the SEO and Sites modules, which change Hugo repositories
# and build them to check a change.
RUN apk add --no-cache ca-certificates tzdata git hugo
COPY --from=build /out/supermarket /usr/local/bin/supermarket
LABEL org.opencontainers.image.title="supermarket"
ENV SUPERMARKET_DATA=/data
EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s \
  CMD wget -q -O /dev/null http://127.0.0.1:8080/healthz || exit 1
ENTRYPOINT ["/usr/local/bin/supermarket"]
