# Stage 1: Build UI with Node.js
FROM node:25.2.1-trixie-slim AS ui-builder

WORKDIR /app

# Copy UI source
COPY ui/package*.json ./
RUN npm install -g typescript && npm ci --only=production
RUN npm install --save-dev @types/react @types/react-dom

# Build UI
COPY ui/ ./
RUN npm run build

# Stage 2: Build Go binary with embedded UI
FROM golang:1.25.4 AS go-builder

WORKDIR /app

# Copy go mod and sum files
COPY go.mod go.sum ./

# Download dependencies
RUN go mod download

# Copy all source code
COPY . .

# Copy UI build artifacts to embed directory
#COPY --from=ui-builder /app/build ./ui/build
COPY --from=ui-builder /proxy/ui_dist ./proxy/ui_dist
# Build the binary (Linux AMD64)
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
    go build -ldflags="-X main.commit=$(git rev-parse --short HEAD) -X main.version=local_$(git rev-parse --short HEAD) -X main.date=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \
    -o build/llama-swap


FROM ghcr.io/ggml-org/llama.cpp:full-vulkan

# has to be after the FROM
ARG LS_VER=170

# Add user/group
ENV HOME=/app



WORKDIR /app

# Copy the binary from builder stage
COPY --from=go-builder /app/build/llama-swap .


COPY  ./docker/config.example.yaml /config.yaml


ENTRYPOINT [ "/app/llama-swap", "-config", "/config.yaml" ]



