# syntax=docker/dockerfile:1

# --- build: compile a static binary ----------------------------------------
FROM golang:1.26 AS build
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -o /out/gitmanager ./cmd/server

# --- dev: hot reload with air (used by docker-compose) ---------------------
FROM golang:1.26 AS dev
RUN apt-get update \
 && apt-get install -y --no-install-recommends git ca-certificates openssh-client \
 && rm -rf /var/lib/apt/lists/*
RUN go install github.com/air-verse/air@latest
WORKDIR /app
EXPOSE 8080
CMD ["air", "-c", ".air.toml"]

# --- runtime: small image with git available -------------------------------
# git is required at runtime — the app shells out to it for every Git operation
# (AGENT.md §2). openssh-client + ca-certificates let it reach remotes.
FROM debian:stable-slim AS runtime
RUN apt-get update \
 && apt-get install -y --no-install-recommends git ca-certificates openssh-client \
 && rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY --from=build /out/gitmanager /usr/local/bin/gitmanager
COPY web ./web
COPY components ./components
EXPOSE 8080
CMD ["gitmanager"]
