Files
chat/Dockerfile
clawbot ae1c67050e build: update Dockerfile with tests and multi-stage build, add Makefile
- Dockerfile runs go test before building
- Multi-stage: build+test stage, minimal alpine final image
- Add gcc/musl-dev for CGO (sqlite)
- Trim binaries with -s -w ldflags
- Makefile with build, test, clean, docker targets
- Version injection via ldflags
2026-02-10 18:21:07 -08:00

26 lines
573 B
Docker

# Build stage
FROM golang:1.24-alpine AS builder
WORKDIR /src
RUN apk add --no-cache make gcc musl-dev
COPY go.mod go.sum ./
RUN go mod download
COPY . .
# Run tests
ENV DBURL="file::memory:?cache=shared"
RUN go test ./...
# Build binaries
RUN CGO_ENABLED=1 go build -trimpath -ldflags="-s -w" -o /chatd ./cmd/chatd/
RUN CGO_ENABLED=1 go build -trimpath -ldflags="-s -w" -o /chat-cli ./cmd/chat-cli/
# Final stage — server only
FROM alpine:3.21
RUN apk add --no-cache ca-certificates
COPY --from=builder /chatd /usr/local/bin/chatd
EXPOSE 8080
ENTRYPOINT ["chatd"]