60 lines
1.3 KiB
Docker
60 lines
1.3 KiB
Docker
# Build stage
|
|
FROM golang:1.22-alpine AS builder
|
|
|
|
# Install build dependencies
|
|
RUN apk --no-cache add gcc musl-dev sqlite-dev git
|
|
|
|
# Set working directory
|
|
WORKDIR /app
|
|
|
|
# Copy go mod files
|
|
COPY go.mod go.sum ./
|
|
|
|
# Download dependencies
|
|
RUN go mod download
|
|
|
|
# Copy source code
|
|
COPY . .
|
|
|
|
# Build the application
|
|
RUN CGO_ENABLED=1 GOOS=linux go build -a -ldflags '-linkmode external -extldflags "-static"' -o dealroom ./cmd/dealroom
|
|
|
|
# Production stage
|
|
FROM alpine:3.19
|
|
|
|
# Install runtime dependencies
|
|
RUN apk --no-cache add ca-certificates tzdata
|
|
|
|
# Create app user
|
|
RUN addgroup -g 1001 -S dealroom && \
|
|
adduser -S dealroom -u 1001 -G dealroom
|
|
|
|
# Create data directories
|
|
RUN mkdir -p /data/db /data/files /data/backups && \
|
|
chown -R dealroom:dealroom /data
|
|
|
|
# Copy binary from builder
|
|
COPY --from=builder /app/dealroom /usr/local/bin/dealroom
|
|
RUN chmod +x /usr/local/bin/dealroom
|
|
|
|
# Switch to app user
|
|
USER dealroom
|
|
|
|
# Set working directory
|
|
WORKDIR /data
|
|
|
|
# Expose port
|
|
EXPOSE 8080
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
|
|
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/health || exit 1
|
|
|
|
# Set environment variables
|
|
ENV PORT=8080 \
|
|
DB_PATH=/data/db/dealroom.db \
|
|
FILES_PATH=/data/files \
|
|
BACKUP_PATH=/data/backups
|
|
|
|
# Run the application
|
|
CMD ["dealroom"] |