# Build stage FROM golang:1.21-alpine AS builder WORKDIR /app # Install build dependencies RUN apk add --no-cache git # Copy go mod files COPY go.mod go.sum ./ RUN go mod download # Copy source code COPY . . # Build the application RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o beat-harvester . # Runtime stage FROM alpine:latest # Install runtime dependencies RUN apk add --no-cache \ python3 \ py3-pip \ ffmpeg \ libwebp-tools \ ca-certificates \ tzdata # Install yt-dlp RUN pip3 install --no-cache-dir yt-dlp # Create app user RUN addgroup -g 1001 -S appgroup && \ adduser -u 1001 -S appuser -G appgroup # Create directories RUN mkdir -p /app/downloads /app/temp && \ chown -R appuser:appgroup /app # Copy binary from builder COPY --from=builder /app/beat-harvester /app/ # Switch to non-root user USER appuser WORKDIR /app # Expose port EXPOSE 3000 # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ CMD wget --no-verbose --tries=1 --spider http://localhost:3000/api/health || exit 1 CMD ["./beat-harvester"]