## Multi-stage Dockerfile for WGRplane
## Stage 1: Go backend build
FROM --platform=$BUILDPLATFORM golang:1.21-alpine AS builder-go
WORKDIR /src
COPY go.mod go.sum ./
RUN --mount=type=cache,target=/root/.cache/go-build \
    go mod download
COPY app ./app
ENV CGO_ENABLED=0
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
    go build -o /bin/wgrplane ./app

## Stage 2: Frontend build (Vue 3)
FROM node:20-alpine AS frontend-builder
WORKDIR /src/app/frontend
COPY app/frontend/package*.json ./
RUN npm ci
COPY app/frontend/ .
RUN npm run build

## Stage 3: Production image
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /root
COPY --from=builder-go /bin/wgrplane /usr/local/bin/wgrplane
COPY --from=frontend-builder /src/app/frontend/dist /var/www/frontend
ENV APP_FRONTEND_DIR=/var/www/frontend
EXPOSE 10087
ENTRYPOINT ["/usr/local/bin/wgrplane"]
