Skip to content

Commit c0f42c3

Browse files
duanhongyiduanhongyi
authored and
duanhongyi
committed
feat(postgres): use docker's official postgres:11 image
1 parent 263f50e commit c0f42c3

File tree

5 files changed

+71
-58
lines changed

5 files changed

+71
-58
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ sudo: required
22
language: go
33
services:
44
- docker
5-
script: make test
5+
script: make docker-build && make test
66
notifications:
77
slack:
88
secure: pWDCV3od8gxvzxh9DrOTvBL54XoCfWYhZZlwd2ZbyyOz6SS12Psg/ZuCT2253p4yMfF/LPlsz76mr7NgcCrMI0ReveTa/rnt3XBZtyY+1rlsQsy2oxgdAzbO587ENCQeMw2F/OWHaixMT8NDqxEqQd6xafK9Zmg6BeBjwgs7XfXKcR3WzNIuCO0ZG05+Yd0FIxmd/8Xm5tGiFEYr05+Ix6MLdF9MSCXZUPeu1EsYXhDljokLq49w63W1UMU10tm4t7VCEdaO+X9w6EJ5Ov8HDxb6L6IviUYY6+IGTZ01nwIoM6OrGQqfEAytYqgTKdehgQzQnAbLI6TW2wJ0twqEsLrlbTa4NW4j0KkazQJkN5kqcKYQvaeKJJhvJIG44Gi/u78pW3S6W7NU5DhrlE6bbxdIBHJW1vJBimkqu2oBNrO5ZoBB9MS9zflBsU5g/pQpVeHWMnWE8fcYDGa1PqAcr7q6wtdPsrVZhnHmmARN3PwZzIVVVsXbaIQG8VLC5grLGnwMf1Y1fz2nK3sVpCftvrYZT3G6CNAASo+eLOwYdZdiJ9jIS7WNLN1GtpIEvjeDt3QRqsDyH8YoAKUvY5h/v8IWPP/BaSwQbJwep4+Dj7xkpXX5/4wm4jEnVFV1p4xE0lD1AXvEMAVHtPhhggvscNhF9j6oeoPju6eTPcxG+5o=

Dockerfile

Lines changed: 19 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,42 @@
1-
FROM quay.io/deis/base:v0.3.6
1+
FROM postgres:11
22

3-
ENV LANG=en_US.utf8 \
4-
PG_MAJOR=9.4 \
5-
PG_VERSION=9.4.17-1.pgdg16.04+1 \
6-
PGDATA=/var/lib/postgresql/data
7-
8-
# Set this separately from those above since it depends on one of them
9-
ENV PATH=/usr/lib/postgresql/$PG_MAJOR/bin:$PATH
10-
11-
# Add postgres user and group
12-
RUN adduser --system \
13-
--shell /bin/bash \
14-
--disabled-password \
15-
--group \
16-
postgres
3+
ARG DEBIAN_FRONTEND=noninteractive
174

185
RUN buildDeps='gcc git libffi-dev libssl-dev python3-dev python3-pip python3-wheel' && \
19-
localedef -i en_US -c -f UTF-8 -A /etc/locale.alias en_US.UTF-8 && \
20-
export DEBIAN_FRONTEND=noninteractive && \
21-
apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8 && \
22-
echo 'deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main' $PG_MAJOR > /etc/apt/sources.list.d/pgdg.list && \
236
apt-get update && \
247
apt-get install -y --no-install-recommends \
258
$buildDeps \
269
gosu \
2710
lzop \
28-
postgresql-$PG_MAJOR=$PG_VERSION \
29-
postgresql-contrib-$PG_MAJOR=$PG_VERSION \
11+
libpq-dev \
3012
pv \
3113
python3 \
32-
postgresql-common \
3314
util-linux \
3415
# swift package needs pkg_resources and setuptools
3516
python3-pkg-resources \
36-
python3-setuptools && \
17+
python3-setuptools \
18+
python3-pip && \
3719
ln -sf /usr/bin/python3 /usr/bin/python && \
38-
ln -sf /usr/bin/pip3 /usr/bin/pip && \
39-
mkdir -p /run/postgresql && \
40-
chown -R postgres /run/postgresql && \
41-
# setuptools from ubuntu archives is too old for googleapis-common-protos
42-
pip install --upgrade setuptools && \
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 && \
4324
pip install --disable-pip-version-check --no-cache-dir \
44-
envdir==0.7 \
45-
wal-e[aws,azure,google,swift]==v1.0.2 \
46-
# pin azure-storage to version wal-e uses (see docker-entrypoint.sh)
47-
azure-storage==0.20.0 && \
48-
# "upgrade" boto to 2.43.0 + the patch to fix minio connections
49-
pip install --disable-pip-version-check --no-cache-dir --upgrade git+https://github.com/teamhephy/boto@88c980e56d1053892eb940d43a15a68af4ebb5e6 && \
50-
# cleanup
51-
apt-get purge -y --auto-remove $buildDeps && \
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 $buildDeps && \
5233
apt-get autoremove -y && \
53-
apt-get clean -y && \
54-
# package up license files if any by appending to existing tar
55-
COPYRIGHT_TAR='/usr/share/copyrights.tar' && \
56-
gunzip -f $COPYRIGHT_TAR.gz && \
57-
tar -rf $COPYRIGHT_TAR /usr/share/doc/*/copyright && \
58-
gzip $COPYRIGHT_TAR && \
59-
rm -rf \
60-
/usr/share/doc \
61-
/usr/share/man \
62-
/usr/share/info \
63-
/usr/share/locale \
64-
/var/lib/apt/lists/* \
65-
/var/log/* \
66-
/var/cache/debconf/* \
67-
/etc/systemd \
68-
/lib/lsb \
69-
/lib/udev \
70-
/usr/lib/x86_64-linux-gnu/gconv/IBM* \
71-
/usr/lib/x86_64-linux-gnu/gconv/EBC* && \
72-
bash -c "mkdir -p /usr/share/man/man{1..8}"
34+
apt-get clean -y
7335

7436
COPY rootfs /
7537
ENV WALE_ENVDIR=/etc/wal-e.d/env
7638
RUN mkdir -p $WALE_ENVDIR
39+
RUN python3 /patcher-script.py
7740

7841
CMD ["/docker-entrypoint.sh", "postgres"]
7942
EXPOSE 5432

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ gosu postgres pg_ctl -D "$PGDATA" -w restart
2020
if [[ $(envdir "$WALE_ENVDIR" wal-e --terse backup-list | wc -l) -gt "1" ]]; then
2121
echo "Found backups. Restoring from backup..."
2222
gosu postgres pg_ctl -D "$PGDATA" -w stop
23-
rm -rf "$PGDATA"
23+
rm -rf "$PGDATA/*"
2424
envdir "$WALE_ENVDIR" wal-e backup-fetch "$PGDATA" LATEST
2525
cat << EOF > "$PGDATA/postgresql.conf"
2626
# These settings are initialized by initdb, but they can be changed.
@@ -53,6 +53,12 @@ EOF
5353
gosu postgres pg_ctl -D "$PGDATA" \
5454
-o "-c listen_addresses=''" \
5555
-w start
56+
57+
echo "Waiting for recovery completion..."
58+
while [ ! -f "$PGDATA/recovery.done" ]
59+
do
60+
sleep 2
61+
done
5662
fi
5763

5864
echo "Performing an initial backup..."
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
def patch_wal_e_hmac_auth_v4_handler():
2+
import os
3+
from boto.auth import HmacAuthV4Handler
4+
_init = HmacAuthV4Handler.__init__
5+
def wrap_init(self, *args, **kwargs):
6+
_init(self, *args, **kwargs)
7+
self.region_name = os.getenv('AWS_REGION', self.region_name)
8+
HmacAuthV4Handler.__init__ = wrap_init
9+
10+
11+
if __name__ == '__main__':
12+
patch_wal_e_hmac_auth_v4_handler()

rootfs/patcher-script.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
patch_script = """
2+
3+
def run_patch_scripts(patch_script_path):
4+
import os
5+
for patch in os.listdir(patch_script_path):
6+
full_patch_file = os.path.join(patch_script_path, patch)
7+
if full_patch_file.endswith('.py') and os.path.isfile(full_patch_file):
8+
with open(full_patch_file, 'r') as f:
9+
try:
10+
exec(f.read())
11+
except:
12+
pass
13+
run_patch_scripts('/patcher-script.d')
14+
15+
"""
16+
17+
18+
def main():
19+
result_list = []
20+
with open("/usr/local/bin/wal-e", "r") as f:
21+
has_patched = False
22+
for line in f:
23+
if not has_patched and line.startswith('import'):
24+
result_list.append(patch_script)
25+
has_patched = True
26+
result_list.append(line)
27+
with open("/usr/local/bin/wal-e", "w") as f:
28+
for line in result_list:
29+
f.write(line)
30+
31+
if __name__ == '__main__':
32+
main()

0 commit comments

Comments
 (0)