-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
83 lines (71 loc) · 2.85 KB
/
Dockerfile
File metadata and controls
83 lines (71 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Use Ubuntu as base image for better package management
FROM ubuntu:24.04
# Metadata labels for the image
LABEL org.opencontainers.image.title="PostgreSQL Backup Service"
LABEL org.opencontainers.image.description="Automated PostgreSQL backup service with S3/R2 sync and retention policies"
LABEL org.opencontainers.image.vendor="ServiceStack"
LABEL org.opencontainers.image.licenses="MIT"
LABEL org.opencontainers.image.source="https://github.com/ServiceStack/backup-postgres"
LABEL org.opencontainers.image.documentation="https://github.com/ServiceStack/backup-postgres#readme"
# Avoid interactive prompts during package installation
ENV DEBIAN_FRONTEND=noninteractive
# Add PostgreSQL official APT repository for latest version
RUN apt-get update && apt-get install -y \
curl \
ca-certificates \
gnupg \
lsb-release \
&& curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor -o /usr/share/keyrings/postgresql-keyring.gpg \
&& echo "deb [signed-by=/usr/share/keyrings/postgresql-keyring.gpg] http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list
# Update package list and install required packages
RUN apt-get update && apt-get install -y \
# PostgreSQL client tools (latest version)
postgresql-client-17 \
# AWS CLI dependencies
unzip \
python3 \
python3-pip \
# Utilities
cron \
bash \
findutils \
&& rm -rf /var/lib/apt/lists/*
# Install AWS CLI v2
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" \
&& unzip awscliv2.zip \
&& ./aws/install \
&& rm -rf awscliv2.zip aws/
# Configure AWS CLI for R2 compatibility
RUN mkdir -p /root/.aws \
&& echo '[default]' > /root/.aws/config \
&& echo 's3 =' >> /root/.aws/config \
&& echo ' signature_version = s3v4' >> /root/.aws/config \
&& echo ' addressing_style = path' >> /root/.aws/config \
&& echo ' multipart_threshold = 1GB' >> /root/.aws/config \
&& echo ' multipart_chunksize = 64MB' >> /root/.aws/config
# Create backup directory
RUN mkdir -p /backups
# Create backup script
COPY backup-script.sh /usr/local/bin/backup-script.sh
RUN chmod +x /usr/local/bin/backup-script.sh
# Set working directory
WORKDIR /backups
# Environment variables documentation
ENV BACKUP_INTERVAL=86400 \
RETENTION_DAYS=7 \
S3_BUCKET="" \
S3_PREFIX="db-backups" \
S3_RETENTION_DAYS="" \
POSTGRES_HOST="" \
POSTGRES_USER="" \
POSTGRES_PASSWORD="" \
POSTGRES_DB="" \
AWS_ACCESS_KEY_ID="" \
AWS_SECRET_ACCESS_KEY="" \
AWS_DEFAULT_REGION="" \
AWS_ENDPOINT_URL=""
# Health check to verify the service is running
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD pgrep -f backup-script.sh > /dev/null || exit 1
# Default command
CMD ["/usr/local/bin/backup-script.sh"]