# Build stage
FROM golang:1.24-alpine AS builder

# # Install git and build dependencies
# RUN apk add --no-cache git make build-base

# Set working directory
WORKDIR /app

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

# Copy the source code
COPY . .

# Build the application
RUN CGO_ENABLED=0 GOOS=linux go build -o junk2jive-server ./cmd/junk2jive

# Release stage
FROM alpine:latest

# Add CA certificates and timezone data
RUN apk --no-cache add ca-certificates tzdata

WORKDIR /app

# Copy the binary from builder
COPY --from=builder /app/junk2jive-server /app/
# Copy configuration if needed
COPY data/config.yaml /app/data/

# Create a non-root user to run our application
RUN adduser -D -g '' appuser
USER appuser

# Expose the port the app runs on
EXPOSE 8080

# Command to run the executable
ENTRYPOINT ["/app/junk2jive-server"]