# Build stage
FROM golang:1.21-alpine AS builder

WORKDIR /build

# Install build dependencies (required for CGO and SQLite)
RUN apk add --no-cache gcc musl-dev sqlite-dev

# Copy go mod files
COPY go.mod go.sum ./
RUN go mod download

# Copy source code
COPY . .

# Build the application with CGO enabled for SQLite
RUN CGO_ENABLED=1 go build -o taskmaster ./cmd/taskmaster

# Runtime stage
FROM alpine:latest

WORKDIR /app

# Install runtime dependencies
RUN apk add --no-cache sqlite-libs

# Copy binary from build stage
COPY --from=builder /build/taskmaster .

# Create data directory for database
RUN mkdir -p /app/data

# Set environment variable for database path
ENV DB_PATH=/app/data/tasks.db

# Use the data directory for the database
WORKDIR /app/data

ENTRYPOINT ["/app/taskmaster"]
CMD ["help"]
