# Build stage
FROM golang:1.25-alpine AS builder

RUN apk add --no-cache git make gcc musl-dev

# Install golangci-lint v2
RUN go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
RUN go install golang.org/x/tools/cmd/goimports@latest

WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download

COPY . .

# Run all checks - build fails if any check fails
RUN make check

# Build the binary
RUN make build

# Runtime stage
FROM alpine:3.21

RUN apk add --no-cache ca-certificates tzdata

WORKDIR /app

COPY --from=builder /src/bin/dnswatcher /app/dnswatcher

# Create data directory
RUN mkdir -p /var/lib/dnswatcher

ENV DNSWATCHER_DATA_DIR=/var/lib/dnswatcher

EXPOSE 8080

ENTRYPOINT ["/app/dnswatcher"]
