Skip to content

Commit 1d1d8a0

Browse files
committed
feat(postgres): modify the docker base image as postgres:11-alpine
1 parent 247bc5c commit 1d1d8a0

File tree

7 files changed

+42
-50
lines changed

7 files changed

+42
-50
lines changed

Dockerfile

+30-38
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,39 @@
1-
FROM postgres:11
2-
3-
ARG DEBIAN_FRONTEND=noninteractive
4-
ARG BUILD_DEPS='gcc git libffi-dev libssl-dev python3-dev python3-pip python3-wheel'
5-
6-
RUN apt-get update && \
7-
apt-get install -y --no-install-recommends \
8-
$BUILD_DEPS \
9-
gosu \
10-
lzop \
11-
libpq-dev \
12-
pv \
13-
python3 \
14-
util-linux \
15-
# swift package needs pkg_resources and setuptools
16-
python3-pkg-resources \
17-
python3-setuptools \
18-
python3-pip && \
19-
ln -sf /usr/bin/python3 /usr/bin/python && \
20-
ln -sf /usr/bin/pip3 /usr/bin/pip
21-
22-
# setuptools from ubuntu archives is too old for googleapis-common-protos
23-
RUN pip install --upgrade setuptools && \
24-
pip install --disable-pip-version-check --no-cache-dir \
25-
envdir==1.0.1 \
26-
wal-e[aws,azure,google,swift]==1.1.0 \
27-
gcloud==0.18.3 \
28-
oauth2client==4.1.3 \
29-
azure-storage==0.20.0
30-
31-
# cleanup
32-
RUN apt-get purge -y --auto-remove $BUILD_DEPS && \
33-
apt-get autoremove -y && \
34-
apt-get clean -y
1+
FROM postgres:11-alpine
2+
3+
ENV WALE_LOG_DESTINATION stderr
4+
ENV WALE_ENVDIR /etc/wal-e.d/env
5+
6+
RUN mkdir -p $WALE_ENVDIR \
7+
&& echo 'http://dl-cdn.alpinelinux.org/alpine/v3.5/main' >> /etc/apk/repositories \
8+
&& apk add --update --virtual .build-deps \
9+
git \
10+
build-base \
11+
libffi-dev \
12+
openssl-dev \
13+
python3-dev=3.5.6-r0 \
14+
linux-headers \
15+
&& apk add \
16+
lzo \
17+
pv \
18+
util-linux \
19+
python3=3.5.6-r0 \
20+
&& pip3 install --upgrade pip setuptools \
21+
&& pip install --disable-pip-version-check --no-cache-dir \
22+
psycopg2-binary==2.7.6.1 \
23+
envdir==1.0.1 \
24+
wal-e[aws,azure,google,swift]==1.1.0 \
25+
gcloud==0.18.3 \
26+
oauth2client==4.1.3 \
27+
azure-storage==0.20.0 \
28+
&& apk del .build-deps \
29+
&& rm -rf /var/cache/apk/*
3530

3631
COPY rootfs /
37-
ENV WALE_ENVDIR=/etc/wal-e.d/env
38-
RUN mkdir -p $WALE_ENVDIR
3932

4033
ARG PATCH_CMD="python3 /patcher-script.py"
4134
RUN $PATCH_CMD file /bin/create_bucket /patcher-script.d/patch_boto_s3.py
42-
RUN $PATCH_CMD file /usr/local/bin/wal-e /patcher-script.d/patch_boto_s3.py
35+
RUN $PATCH_CMD module wal_e.cmd /patcher-script.d/patch_boto_s3.py
4336
RUN $PATCH_CMD module wal_e.worker.worker_util /patcher-script.d/patch_wal_e_s3.py
4437

45-
4638
CMD ["/docker-entrypoint.sh", "postgres"]
4739
EXPOSE 5432

charts/database/templates/database-deployment.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ spec:
4545
preStop:
4646
exec:
4747
command:
48-
- gosu
48+
- su-exec
4949
- postgres
5050
- do_backup
5151
readinessProbe:

rootfs/bin/create_bucket

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22

33
import os
44

rootfs/bin/is_running

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ if [[ -f "$PGDATA/recovery.conf" ]]; then
88
exit 1
99
fi
1010

11-
gosu postgres pg_ctl status
11+
su-exec postgres pg_ctl status

rootfs/docker-entrypoint-initdb.d/003_restore_from_backup.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ chmod 0700 "$PGDATA"
1313

1414
# reboot the server for wal_level to be set before backing up
1515
echo "Rebooting postgres to enable archive mode"
16-
gosu postgres pg_ctl -D "$PGDATA" -w restart
16+
su-exec postgres pg_ctl -D "$PGDATA" -w restart
1717

1818
# check if there are any backups -- if so, let's restore
1919
# we could probably do better than just testing number of lines -- one line is just a heading, meaning no backups
2020
if [[ $(envdir "$WALE_ENVDIR" wal-e --terse backup-list | wc -l) -gt "1" ]]; then
2121
echo "Found backups. Restoring from backup..."
22-
gosu postgres pg_ctl -D "$PGDATA" -w stop
22+
su-exec postgres pg_ctl -D "$PGDATA" -w stop
2323
rm -rf "$PGDATA/*"
2424
envdir "$WALE_ENVDIR" wal-e backup-fetch "$PGDATA" LATEST
2525
cat << EOF > "$PGDATA/postgresql.conf"
@@ -50,7 +50,7 @@ EOF
5050
echo "restore_command = 'envdir /etc/wal-e.d/env wal-e wal-fetch \"%f\" \"%p\"'" >> "$PGDATA/recovery.conf"
5151
chown -R postgres:postgres "$PGDATA"
5252
chmod 0700 "$PGDATA"
53-
gosu postgres pg_ctl -D "$PGDATA" \
53+
su-exec postgres pg_ctl -D "$PGDATA" \
5454
-o "-c listen_addresses=''" \
5555
-w start
5656

@@ -62,7 +62,7 @@ EOF
6262
fi
6363

6464
echo "Performing an initial backup..."
65-
gosu postgres envdir "$WALE_ENVDIR" wal-e backup-push "$PGDATA"
65+
su-exec postgres envdir "$WALE_ENVDIR" wal-e backup-push "$PGDATA"
6666

6767
# ensure $PGDATA has the right permissions
6868
chown -R postgres:postgres "$PGDATA"
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env bash
22

33
# Run periodic backups in the background
4-
gosu postgres backup &
4+
su-exec postgres backup &

rootfs/docker-entrypoint.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ if [ "$1" = 'postgres' ]; then
2323

2424
# look specifically for PG_VERSION, as it is expected in the DB dir
2525
if [ ! -s "$PGDATA/PG_VERSION" ]; then
26-
gosu postgres initdb
26+
su-exec postgres initdb
2727

2828
# check password first so we can output the warning before postgres
2929
# messes it up
@@ -54,7 +54,7 @@ if [ "$1" = 'postgres' ]; then
5454

5555
# internal start of server in order to allow set-up using psql-client
5656
# does not listen on TCP/IP and waits until start finishes
57-
gosu postgres pg_ctl -D "$PGDATA" \
57+
su-exec postgres pg_ctl -D "$PGDATA" \
5858
-o "-c listen_addresses=''" \
5959
-w start
6060

@@ -94,15 +94,15 @@ if [ "$1" = 'postgres' ]; then
9494
echo
9595
done
9696

97-
gosu postgres pg_ctl -D "$PGDATA" -m fast -w stop
97+
su-exec postgres pg_ctl -D "$PGDATA" -m fast -w stop
9898
set_listen_addresses '*'
9999

100100
echo
101101
echo 'PostgreSQL init process complete; ready for start up.'
102102
echo
103103
fi
104104

105-
exec gosu postgres "$@"
105+
exec su-exec postgres "$@"
106106
fi
107107

108108
exec "$@"

0 commit comments

Comments
 (0)