-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
81 lines (59 loc) · 2.18 KB
/
Dockerfile
File metadata and controls
81 lines (59 loc) · 2.18 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
# Use Alpine-based image for smaller footprint and better security
FROM postgres:17-alpine
# Add label metadata
LABEL org.opencontainers.image.source="https://github.com/synehq/pg-pgvector"
LABEL org.opencontainers.image.description="SyneHQ PostgreSQL with pg_stat_statements"
LABEL org.opencontainers.image.licenses="MIT"
# Install additional required packages
RUN apk add --no-cache tzdata musl-locales musl-locales-lang
# Set environment variables
ENV LANG=en_US.UTF-8
ENV LC_ALL=en_US.UTF-8
# Create directory for logs
RUN mkdir -p /var/lib/postgresql/log && \
chown -R postgres:postgres /var/lib/postgresql/log
# Create directory for custom configurations
RUN mkdir -p /etc/postgresql/conf.d && \
chown -R postgres:postgres /etc/postgresql/conf.d
# Create directory for SSL certificates
RUN mkdir -p /etc/postgresql/ssl && \
chown -R postgres:postgres /etc/postgresql/ssl && \
chmod 700 /etc/postgresql/ssl
# Copy custom PostgreSQL configuration
COPY postgresql.conf /etc/postgresql/conf.d/
RUN chown postgres:postgres /etc/postgresql/conf.d/postgresql.conf
# Set up initialization scripts
COPY init.sql /docker-entrypoint-initdb.d/
RUN chown postgres:postgres /docker-entrypoint-initdb.d/init.sql
# Copy entrypoint file
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
# make entrypoint executable
RUN chmod +x /usr/local/bin/entrypoint.sh
# Expose PostgreSQL port
EXPOSE 5432
# Create healthcheck script
COPY --chown=postgres:postgres <<'EOF' /usr/local/bin/docker-healthcheck
#!/bin/bash
set -eo pipefail
host="$(hostname -i || echo '127.0.0.1')"
user="${POSTGRES_USER:-postgres}"
db="${POSTGRES_DB:-$user}"
export PGPASSWORD="${POSTGRES_PASSWORD:-}"
args=(
--host "$host"
--username "$user"
--dbname "$db"
--quiet --no-align --tuples-only
)
if SELECT 1 FROM pg_database WHERE datname='$db' >/dev/null 2>&1; then
exit 0
fi
exit 1
EOF
RUN chmod +x /usr/local/bin/docker-healthcheck
# Add healthcheck
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
CMD ["docker-healthcheck"]
# Create a volume for persistent data
VOLUME ["/var/lib/postgresql/data", "/var/lib/postgresql/log", "/etc/postgresql/ssl"]
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]