# Multi-stage build: Angular -> Go -> Runtime

FROM node:22-slim AS frontend
WORKDIR /app/ui
COPY ui/package*.json ./
RUN npm install --no-audit --no-fund
COPY ui .
RUN npm run build

FROM golang:1.23 AS backend
WORKDIR /app/back
COPY back/go.mod back/go.sum ./
RUN go mod download
COPY back .
# Copy built frontend into embed directory BEFORE go build
RUN mkdir -p /app/back/cmd/public
COPY --from=frontend /app/ui/dist/project-front/browser/ /app/back/cmd/public/
RUN CGO_ENABLED=0 GOOS=linux go build -o /app/knocker-serve .

FROM gcr.io/distroless/base-debian12
WORKDIR /app
ENV GO_KNOCKER_SERVE_PORT=8888
COPY --from=backend /app/knocker-serve /app/knocker-serve
EXPOSE 8888
USER nonroot:nonroot
ENTRYPOINT ["/app/knocker-serve", "serve"]

