Skip to content

Commit f9c0782

Browse files
committed
Create image that can be easily be integrated with barman for backups.
See https://github.com/tbeadle/docker-barman for an image to be used as the barman server.
1 parent 8d0977b commit f9c0782

38 files changed

+717
-679
lines changed

9.2/Dockerfile

+7-6
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ RUN set -ex; \
3737
rm -r "$GNUPGHOME"; \
3838
apt-key list
3939

40-
ENV PG_MAJOR 9.2
41-
ENV PG_VERSION 9.2.19-1.pgdg80+1
40+
ENV \
41+
PG_MAJOR=9.2 \
42+
PG_VERSION=9.2.19-1.pgdg80+1 \
43+
PATH=/usr/lib/postgresql/9.2/bin:$PATH \
44+
PGDATA=/var/lib/postgresql/data
4245

4346
RUN echo 'deb http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main' $PG_MAJOR > /etc/apt/sources.list.d/pgdg.list
4447

@@ -57,8 +60,6 @@ RUN mv -v /usr/share/postgresql/$PG_MAJOR/postgresql.conf.sample /usr/share/post
5760

5861
RUN mkdir -p /var/run/postgresql && chown -R postgres /var/run/postgresql
5962

60-
ENV PATH /usr/lib/postgresql/$PG_MAJOR/bin:$PATH
61-
ENV PGDATA /var/lib/postgresql/data
6263
VOLUME /var/lib/postgresql/data
6364

6465
RUN apt-get update \
@@ -68,8 +69,8 @@ RUN apt-get update \
6869
&& rm -rf /var/lib/apt/lists/*
6970

7071
COPY docker-entrypoint.sh /
71-
72-
ENTRYPOINT ["/docker-entrypoint.sh"]
72+
COPY functions.sh /usr/local/bin/
7373

7474
EXPOSE 5432
75+
ENTRYPOINT ["/docker-entrypoint.sh"]
7576
CMD ["postgres"]

9.2/alpine/docker-entrypoint.sh

+11-58
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,18 @@
22
set -e
33
shopt -s nullglob
44

5-
6-
# usage: file_env VAR [DEFAULT]
7-
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
8-
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
9-
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
10-
file_env() {
11-
local var="$1"
12-
local fileVar="${var}_FILE"
13-
local def="${2:-}"
14-
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
15-
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
16-
exit 1
17-
fi
18-
local val="$def"
19-
if [ "${!var:-}" ]; then
20-
val="${!var}"
21-
elif [ "${!fileVar:-}" ]; then
22-
val="$(< "${!fileVar}")"
23-
fi
24-
export "$var"="$val"
25-
unset "$fileVar"
26-
}
27-
28-
verlte() {
29-
[ "$1" == "`echo -e "$1\n$2" | sort -V | head -n1`" ]
30-
}
31-
32-
verlt() {
33-
[ "$1" == "$2" ] && return 1 || verlte $1 $2
34-
}
5+
. /usr/local/bin/functions.sh
356

367
if [ "${1:0:1}" = '-' ]; then
378
set -- postgres "$@"
389
fi
3910

11+
file_env 'PGUSER' 'postgres'
12+
file_env 'PGDATABASE' "$PGUSER"
13+
file_env 'PGPASSWORD'
14+
4015
if [ "$1" = 'postgres' ]; then
41-
for x in /docker-pre-builtin.d/*; do
42-
if [ -f "${x}" -a -x "${x}" ]; then
43-
echo "-----> Running ${x}"
44-
"${x}"
45-
fi
46-
done
47-
for x in /docker-pre-entrypoint.d/*; do
16+
for x in /image-pre-entrypoint.d/* /docker-pre-entrypoint.d/*; do
4817
if [ -f "${x}" -a -x "${x}" ]; then
4918
echo "-----> Running ${x}"
5019
"${x}"
@@ -53,11 +22,11 @@ if [ "$1" = 'postgres' ]; then
5322

5423
mkdir -p "$PGDATA"
5524
chmod 700 "$PGDATA"
56-
chown -R postgres "$PGDATA"
25+
chown -R postgres: "$PGDATA"
5726

5827
mkdir -p /run/postgresql
5928
chmod g+s /run/postgresql
60-
chown -R postgres /run/postgresql
29+
chown -R postgres: /run/postgresql
6130

6231
# look specifically for PG_VERSION, as it is expected in the DB dir
6332
if [ ! -s "$PGDATA/PG_VERSION" ]; then
@@ -66,7 +35,6 @@ if [ "$1" = 'postgres' ]; then
6635

6736
# check password first so we can output the warning before postgres
6837
# messes it up
69-
file_env 'PGPASSWORD'
7038
if [ "$PGPASSWORD" ]; then
7139
pass="PASSWORD '$PGPASSWORD'"
7240
authMethod=md5
@@ -121,10 +89,7 @@ EOF
12189

12290
echo
12391

124-
file_env 'PGUSER' 'postgres'
125-
file_env 'PGDATABASE' "$PGUSER"
126-
127-
for x in /docker-builtin-pre-start.d/*; do
92+
for x in /image-pre-start.d/*; do
12893
if [ -f "${x}" -a -x "${x}" ]; then
12994
echo "-----> Running ${x}"
13095
"${x}"
@@ -156,14 +121,8 @@ EOF
156121
EOSQL
157122

158123
echo
159-
for x in /docker-builtin-initdb.d/*; do
160-
if [ -f "${x}" -a -x "${x}" ]; then
161-
echo "-----> Running ${x}"
162-
"${x}"
163-
fi
164-
done
165124

166-
for f in /docker-entrypoint-initdb.d/*; do
125+
for f in /image-entrypoint-initdb.d/* /docker-entrypoint-initdb.d/*; do
167126
case "$f" in
168127
*.sh) echo "$0: running $f"; . "$f" ;;
169128
*.sql) echo "$0: running $f"; "${psql[@]}" -f "$f"; echo ;;
@@ -180,13 +139,7 @@ EOF
180139
echo
181140
fi
182141

183-
for x in /docker-post-builtin.d/*; do
184-
if [ -f "${x}" -a -x "${x}" ]; then
185-
echo "-----> Running ${x}"
186-
"${x}"
187-
fi
188-
done
189-
for x in /docker-post-entrypoint.d/*; do
142+
for x in /image-post-entrypoint.d/* /docker-post-entrypoint.d/*; do
190143
if [ -f "${x}" -a -x "${x}" ]; then
191144
echo "-----> Running ${x}"
192145
"${x}"

9.2/docker-entrypoint.sh

+11-58
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,18 @@
22
set -e
33
shopt -s nullglob
44

5-
6-
# usage: file_env VAR [DEFAULT]
7-
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
8-
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
9-
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
10-
file_env() {
11-
local var="$1"
12-
local fileVar="${var}_FILE"
13-
local def="${2:-}"
14-
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
15-
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
16-
exit 1
17-
fi
18-
local val="$def"
19-
if [ "${!var:-}" ]; then
20-
val="${!var}"
21-
elif [ "${!fileVar:-}" ]; then
22-
val="$(< "${!fileVar}")"
23-
fi
24-
export "$var"="$val"
25-
unset "$fileVar"
26-
}
27-
28-
verlte() {
29-
[ "$1" == "`echo -e "$1\n$2" | sort -V | head -n1`" ]
30-
}
31-
32-
verlt() {
33-
[ "$1" == "$2" ] && return 1 || verlte $1 $2
34-
}
5+
. /usr/local/bin/functions.sh
356

367
if [ "${1:0:1}" = '-' ]; then
378
set -- postgres "$@"
389
fi
3910

11+
file_env 'PGUSER' 'postgres'
12+
file_env 'PGDATABASE' "$PGUSER"
13+
file_env 'PGPASSWORD'
14+
4015
if [ "$1" = 'postgres' ]; then
41-
for x in /docker-pre-builtin.d/*; do
42-
if [ -f "${x}" -a -x "${x}" ]; then
43-
echo "-----> Running ${x}"
44-
"${x}"
45-
fi
46-
done
47-
for x in /docker-pre-entrypoint.d/*; do
16+
for x in /image-pre-entrypoint.d/* /docker-pre-entrypoint.d/*; do
4817
if [ -f "${x}" -a -x "${x}" ]; then
4918
echo "-----> Running ${x}"
5019
"${x}"
@@ -53,11 +22,11 @@ if [ "$1" = 'postgres' ]; then
5322

5423
mkdir -p "$PGDATA"
5524
chmod 700 "$PGDATA"
56-
chown -R postgres "$PGDATA"
25+
chown -R postgres: "$PGDATA"
5726

5827
mkdir -p /run/postgresql
5928
chmod g+s /run/postgresql
60-
chown -R postgres /run/postgresql
29+
chown -R postgres: /run/postgresql
6130

6231
# look specifically for PG_VERSION, as it is expected in the DB dir
6332
if [ ! -s "$PGDATA/PG_VERSION" ]; then
@@ -66,7 +35,6 @@ if [ "$1" = 'postgres' ]; then
6635

6736
# check password first so we can output the warning before postgres
6837
# messes it up
69-
file_env 'PGPASSWORD'
7038
if [ "$PGPASSWORD" ]; then
7139
pass="PASSWORD '$PGPASSWORD'"
7240
authMethod=md5
@@ -121,10 +89,7 @@ EOF
12189

12290
echo
12391

124-
file_env 'PGUSER' 'postgres'
125-
file_env 'PGDATABASE' "$PGUSER"
126-
127-
for x in /docker-builtin-pre-start.d/*; do
92+
for x in /image-pre-start.d/*; do
12893
if [ -f "${x}" -a -x "${x}" ]; then
12994
echo "-----> Running ${x}"
13095
"${x}"
@@ -156,14 +121,8 @@ EOF
156121
EOSQL
157122

158123
echo
159-
for x in /docker-builtin-initdb.d/*; do
160-
if [ -f "${x}" -a -x "${x}" ]; then
161-
echo "-----> Running ${x}"
162-
"${x}"
163-
fi
164-
done
165124

166-
for f in /docker-entrypoint-initdb.d/*; do
125+
for f in /image-entrypoint-initdb.d/* /docker-entrypoint-initdb.d/*; do
167126
case "$f" in
168127
*.sh) echo "$0: running $f"; . "$f" ;;
169128
*.sql) echo "$0: running $f"; "${psql[@]}" -f "$f"; echo ;;
@@ -180,13 +139,7 @@ EOF
180139
echo
181140
fi
182141

183-
for x in /docker-post-builtin.d/*; do
184-
if [ -f "${x}" -a -x "${x}" ]; then
185-
echo "-----> Running ${x}"
186-
"${x}"
187-
fi
188-
done
189-
for x in /docker-post-entrypoint.d/*; do
142+
for x in /image-post-entrypoint.d/* /docker-post-entrypoint.d/*; do
190143
if [ -f "${x}" -a -x "${x}" ]; then
191144
echo "-----> Running ${x}"
192145
"${x}"

9.2/functions.sh

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
# usage: file_env VAR [DEFAULT]
4+
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
5+
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
6+
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
7+
file_env() {
8+
local var="$1"
9+
local fileVar="${var}_FILE"
10+
local def="${2:-}"
11+
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
12+
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
13+
exit 1
14+
fi
15+
local val="$def"
16+
if [ "${!var:-}" ]; then
17+
val="${!var}"
18+
elif [ "${!fileVar:-}" ]; then
19+
val="$(< "${!fileVar}")"
20+
fi
21+
export "$var"="$val"
22+
unset "$fileVar"
23+
}
24+
25+
# Compare 2 version numbers
26+
verlte() {
27+
[ "$1" == "`echo -e "$1\n$2" | sort -V | head -n1`" ]
28+
}
29+
30+
verlt() {
31+
[ "$1" == "$2" ] && return 1 || verlte $1 $2
32+
}

9.3/Dockerfile

+7-6
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ RUN set -ex; \
3737
rm -r "$GNUPGHOME"; \
3838
apt-key list
3939

40-
ENV PG_MAJOR 9.3
41-
ENV PG_VERSION 9.3.15-1.pgdg80+1
40+
ENV \
41+
PG_MAJOR=9.3 \
42+
PG_VERSION=9.3.15-1.pgdg80+1 \
43+
PATH=/usr/lib/postgresql/9.3/bin:$PATH \
44+
PGDATA=/var/lib/postgresql/data
4245

4346
RUN echo 'deb http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main' $PG_MAJOR > /etc/apt/sources.list.d/pgdg.list
4447

@@ -57,8 +60,6 @@ RUN mv -v /usr/share/postgresql/$PG_MAJOR/postgresql.conf.sample /usr/share/post
5760

5861
RUN mkdir -p /var/run/postgresql && chown -R postgres /var/run/postgresql
5962

60-
ENV PATH /usr/lib/postgresql/$PG_MAJOR/bin:$PATH
61-
ENV PGDATA /var/lib/postgresql/data
6263
VOLUME /var/lib/postgresql/data
6364

6465
RUN apt-get update \
@@ -68,8 +69,8 @@ RUN apt-get update \
6869
&& rm -rf /var/lib/apt/lists/*
6970

7071
COPY docker-entrypoint.sh /
71-
72-
ENTRYPOINT ["/docker-entrypoint.sh"]
72+
COPY functions.sh /usr/local/bin/
7373

7474
EXPOSE 5432
75+
ENTRYPOINT ["/docker-entrypoint.sh"]
7576
CMD ["postgres"]

0 commit comments

Comments
 (0)