55 lines
981 B
Docker
55 lines
981 B
Docker
# Build stage
|
|
FROM golang:1.25-alpine AS builder
|
|
|
|
# Install build dependencies
|
|
RUN apk add --no-cache git
|
|
|
|
WORKDIR /build
|
|
|
|
# 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=0 GOOS=linux go build -a -installsuffix cgo -o backup .
|
|
|
|
# Runtime stage
|
|
FROM alpine:latest
|
|
|
|
# Install required tools for backup operations
|
|
RUN apk add --no-cache \
|
|
ca-certificates \
|
|
mysql-client \
|
|
mariadb-client \
|
|
postgresql-client \
|
|
tar \
|
|
gzip \
|
|
tzdata
|
|
|
|
# Create config directory
|
|
RUN mkdir -p /config
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy the binary from builder
|
|
COPY --from=builder /build/backup .
|
|
|
|
# Set timezone (can be overridden)
|
|
ENV TZ=UTC
|
|
|
|
# Run as non-root user
|
|
RUN addgroup -g 1000 backup && \
|
|
adduser -D -u 1000 -G backup backup && \
|
|
chown -R backup:backup /app /config
|
|
|
|
USER backup
|
|
|
|
# Default command
|
|
ENTRYPOINT ["/app/backup"]
|
|
CMD ["-config", "/config/backup.yaml"]
|