pastebin / Dockerfile
Akay Borana
Initial upload
421b222
# Build stage
FROM golang:1.25.3-alpine AS builder
WORKDIR /build
# Copy go mod files
COPY go.mod go.sum ./
RUN go mod download
# Copy source code
COPY . .
# Build the binary
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o patbin .
# Runtime stage
FROM alpine:3.19
WORKDIR /app
# Install ca-certificates for HTTPS
RUN apk --no-cache add ca-certificates tzdata
# Create non-root user
RUN adduser -D -g '' appuser
# Copy binary from builder
COPY --from=builder /build/patbin .
# Copy static files and templates
COPY --from=builder /build/static ./static
COPY --from=builder /build/templates ./templates
# Create data directory for SQLite
RUN mkdir -p /app/data && chown -R appuser:appuser /app
# Switch to non-root user
USER appuser
# Environment variables
ENV PORT=7860
ENV DB_PATH=/app/data/patbin.db
ENV GIN_MODE=release
# Expose port
EXPOSE 7860
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:7860/ || exit 1
# Run the binary
CMD ["./patbin"]