# syntax=docker/dockerfile:1

FROM golang:1.26-alpine AS builder
WORKDIR /src
RUN apk add --no-cache git ca-certificates
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o /out/wg-panel ./cmd/server

FROM alpine:3.21
WORKDIR /app
RUN apk add --no-cache ca-certificates tzdata curl
COPY --from=builder /out/wg-panel /app/wg-panel
COPY migrations /app/migrations
COPY web /app/web
COPY wg.sql /data/wg.sql
ENV APP_ROOT=/app \
    MIGRATIONS_DIR=/app/migrations \
    TEMPLATES_DIR=/app/web/templates \
    STATIC_DIR=/app/web/static \
    MYSQL_DUMP_PATH=/data/wg.sql \
    APP_PORT=4000
EXPOSE 4000
HEALTHCHECK --interval=30s --timeout=5s --start-period=40s --retries=3 \
  CMD curl -fsS http://127.0.0.1:4000/healthz >/dev/null || exit 1
USER nobody
CMD ["/app/wg-panel"]
