# Multi-stage build: compile from source, run in Alpine runtime
FROM golang:1.20-alpine AS builder
# Disable CGO for a fully static-like binary (though we build for Linux/AMD64)
ENV CGO_ENABLED=0
WORKDIR /build
# Cache module downloads first
COPY go.mod go.sum ./
RUN go mod download
# Copy the source and build the binary
COPY . .
RUN GOOS=linux GOARCH=amd64 go build -ldflags "-X github.com/axiaoxin-com/investool/version.Version=$(TZ=Asia/Shanghai date +'%y%m%d%H%M')" -o investool
FROM alpine:3.22.4
# Install runtime dependencies
RUN apk add --no-cache ca-certificates
WORKDIR /srv/investool
# Copy the built binary and config into the runtime image
COPY --from=builder /build/investool ./investool
COPY config.toml ./config.toml
EXPOSE 4869 4870
ENTRYPOINT ["./investool", "-c", "./config.toml"]