Skip to content

Commit

Permalink
feat(postgres): use docker's official postgres:11 image
Browse files Browse the repository at this point in the history
  • Loading branch information
duanhongyi authored and duanhongyi committed Nov 6, 2018
1 parent 263f50e commit c7aea2c
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 56 deletions.
75 changes: 19 additions & 56 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,79 +1,42 @@
FROM quay.io/deis/base:v0.3.6
FROM postgres:11

ENV LANG=en_US.utf8 \
PG_MAJOR=9.4 \
PG_VERSION=9.4.17-1.pgdg16.04+1 \
PGDATA=/var/lib/postgresql/data

# Set this separately from those above since it depends on one of them
ENV PATH=/usr/lib/postgresql/$PG_MAJOR/bin:$PATH

# Add postgres user and group
RUN adduser --system \
--shell /bin/bash \
--disabled-password \
--group \
postgres
ARG DEBIAN_FRONTEND=noninteractive

RUN buildDeps='gcc git libffi-dev libssl-dev python3-dev python3-pip python3-wheel' && \
localedef -i en_US -c -f UTF-8 -A /etc/locale.alias en_US.UTF-8 && \
export DEBIAN_FRONTEND=noninteractive && \
apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8 && \
echo 'deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main' $PG_MAJOR > /etc/apt/sources.list.d/pgdg.list && \
apt-get update && \
apt-get install -y --no-install-recommends \
$buildDeps \
gosu \
lzop \
postgresql-$PG_MAJOR=$PG_VERSION \
postgresql-contrib-$PG_MAJOR=$PG_VERSION \
libpq-dev \
pv \
python3 \
postgresql-common \
util-linux \
# swift package needs pkg_resources and setuptools
python3-pkg-resources \
python3-setuptools && \
python3-setuptools \
python3-pip && \
ln -sf /usr/bin/python3 /usr/bin/python && \
ln -sf /usr/bin/pip3 /usr/bin/pip && \
mkdir -p /run/postgresql && \
chown -R postgres /run/postgresql && \
# setuptools from ubuntu archives is too old for googleapis-common-protos
pip install --upgrade setuptools && \
ln -sf /usr/bin/pip3 /usr/bin/pip

# setuptools from ubuntu archives is too old for googleapis-common-protos
RUN pip install --upgrade setuptools && \
pip install --disable-pip-version-check --no-cache-dir \
envdir==0.7 \
wal-e[aws,azure,google,swift]==v1.0.2 \
# pin azure-storage to version wal-e uses (see docker-entrypoint.sh)
azure-storage==0.20.0 && \
# "upgrade" boto to 2.43.0 + the patch to fix minio connections
pip install --disable-pip-version-check --no-cache-dir --upgrade git+https://github.com/teamhephy/boto@88c980e56d1053892eb940d43a15a68af4ebb5e6 && \
# cleanup
apt-get purge -y --auto-remove $buildDeps && \
envdir==1.0.1 \
wal-e[aws,azure,google,swift]==1.1.0 \
gcloud==0.18.3 \
oauth2client==4.1.3 \
azure-storage==0.20.0

# cleanup
RUN apt-get purge -y --auto-remove $buildDeps && \
apt-get autoremove -y && \
apt-get clean -y && \
# package up license files if any by appending to existing tar
COPYRIGHT_TAR='/usr/share/copyrights.tar' && \
gunzip -f $COPYRIGHT_TAR.gz && \
tar -rf $COPYRIGHT_TAR /usr/share/doc/*/copyright && \
gzip $COPYRIGHT_TAR && \
rm -rf \
/usr/share/doc \
/usr/share/man \
/usr/share/info \
/usr/share/locale \
/var/lib/apt/lists/* \
/var/log/* \
/var/cache/debconf/* \
/etc/systemd \
/lib/lsb \
/lib/udev \
/usr/lib/x86_64-linux-gnu/gconv/IBM* \
/usr/lib/x86_64-linux-gnu/gconv/EBC* && \
bash -c "mkdir -p /usr/share/man/man{1..8}"
apt-get clean -y

COPY rootfs /
ENV WALE_ENVDIR=/etc/wal-e.d/env
RUN mkdir -p $WALE_ENVDIR
RUN python3 /patch_wal_e.py

CMD ["/docker-entrypoint.sh", "postgres"]
EXPOSE 5432
8 changes: 8 additions & 0 deletions rootfs/docker-entrypoint-initdb.d/003_restore_from_backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ EOF
-w start
fi

echo "Waiting for recovery completion..."
while [ ! -f "$PGDATA/recovery.done" ]
do
sleep 1
done

#gosu postgres pg_ctl -D "$PGDATA" -w restart

echo "Performing an initial backup..."
gosu postgres envdir "$WALE_ENVDIR" wal-e backup-push "$PGDATA"

Expand Down
30 changes: 30 additions & 0 deletions rootfs/patch_wal_e.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
patch_script = """
def patch_s3():
import os
from boto.auth import HmacAuthV4Handler
init = HmacAuthV4Handler.__init__
def wrap(self, *args, **kwargs):
init(self, *args, **kwargs)
self.region_name = os.getenv('AWS_REGION', self.region_name)
HmacAuthV4Handler.__init__ = wrap
patch_s3()
"""


def main():
result_list = []
with open("/usr/local/bin/wal-e", "r") as f:
has_patched = False
for line in f:
if not has_patched and line.startswith('import'):
result_list.append(patch_script)
has_patched = True
result_list.append(line)
with open("/usr/local/bin/wal-e", "w") as f:
for line in result_list:
f.write(line)

if __name__ == '__main__':
main()

0 comments on commit c7aea2c

Please sign in to comment.