# Multi-stage build for investool
FROM golang:1.20-alpine AS builder
# Install necessary tools
RUN apk add --no-cache git ca-certificates
WORKDIR /src
# Cache dependencies
COPY go.mod go.sum ./
RUN go mod download
# Copy the source code
COPY . .
# Build the binary (static) and embed version information
ENV CGO_ENABLED=0
ENV GOOS=linux
ENV GOARCH=amd64
RUN go build -ldflags "-X github.com/axiaoxin-com/investool/version.Version=$(date +%y%m%d%H%M)" -o investool
# Final runtime image
FROM alpine:3.19
# Install CA certificates for TLS if needed
RUN apk add --no-cache ca-certificates
WORKDIR /srv/investool
# Copy the built binary and configuration
COPY --from=builder /src/investool .
COPY --from=builder /src/config.toml ./config.toml
EXPOSE 4869 4870
ENTRYPOINT ["./investool", "-c", "./config.toml"]