Images Postgres Alpine, optimization (#207)
This commit is contained in:
parent
e895c0d4dd
commit
4e242572f1
@ -1,24 +1,19 @@
|
|||||||
FROM postgres:9.4
|
FROM postgres:9.4-alpine
|
||||||
|
|
||||||
|
ENV DEFAULT_TIMEZONE UTC
|
||||||
|
|
||||||
# Install some packages to use WAL
|
# Install some packages to use WAL
|
||||||
RUN apt-get update \
|
RUN apk add --no-cache \
|
||||||
&& apt-get install -y \
|
build-base \
|
||||||
build-essential \
|
|
||||||
curl \
|
curl \
|
||||||
daemontools \
|
libc6-compat \
|
||||||
libffi-dev \
|
libffi-dev \
|
||||||
libssl-dev \
|
linux-headers \
|
||||||
lzop \
|
|
||||||
pv \
|
|
||||||
python-dev \
|
python-dev \
|
||||||
|
py-cryptography \
|
||||||
&& curl --silent --show-error --retry 5 https://bootstrap.pypa.io/get-pip.py | python \
|
&& curl --silent --show-error --retry 5 https://bootstrap.pypa.io/get-pip.py | python \
|
||||||
&& pip install 'wal-e<1.0.0' \
|
&& pip --no-cache-dir install 'wal-e<1.0.0' envdir \
|
||||||
&& apt-get remove -y \
|
&& rm -rf /var/cache/apk/* /tmp/* /var/tmp/*
|
||||||
build-essential \
|
|
||||||
python-dev \
|
|
||||||
&& apt-get autoremove -y \
|
|
||||||
&& apt-get clean \
|
|
||||||
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin /tmp/* /var/tmp/*
|
|
||||||
|
|
||||||
# Add wale script
|
# Add wale script
|
||||||
COPY setup-wale.sh /docker-entrypoint-initdb.d/
|
COPY setup-wale.sh /docker-entrypoint-initdb.d/
|
||||||
|
@ -1,53 +1,62 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# if wal backup is not enabled, use minimal wal logging to reduce disk space
|
# if wal-e backup is not enabled, use minimal wal-e logging to reduce disk space
|
||||||
: ${WAL_LEVEL:=minimal}
|
export WAL_LEVEL=${WAL_LEVEL:-minimal}
|
||||||
: ${ARCHIVE_MODE:=off}
|
export ARCHIVE_MODE=${ARCHIVE_MODE:-off}
|
||||||
: ${ARCHIVE_TIMEOUT:=60}
|
export ARCHIVE_TIMEOUT=${ARCHIVE_TIMEOUT:-60}
|
||||||
|
|
||||||
export WAL_LEVEL
|
|
||||||
export ARCHIVE_MODE
|
|
||||||
export ARCHIVE_TIMEOUT
|
|
||||||
|
|
||||||
# PGDATA is defined in upstream postgres dockerfile
|
|
||||||
|
|
||||||
function update_conf () {
|
function update_conf () {
|
||||||
if [ -f $PGDATA/postgresql.conf ]; then
|
wal=$1
|
||||||
sed -i "s/wal_level =.*$/wal_level = $WAL_LEVEL/g" $PGDATA/postgresql.conf
|
# PGDATA is defined in upstream postgres dockerfile
|
||||||
sed -i "s/archive_mode =.*$/archive_mode = $ARCHIVE_MODE/g" $PGDATA/postgresql.conf
|
config_file=$PGDATA/postgresql.conf
|
||||||
sed -i "s/archive_timeout =.*$/archive_timeout = $ARCHIVE_TIMEOUT/g" $PGDATA/postgresql.conf
|
|
||||||
fi
|
# Check if configuration file exists. If not, it probably means that database is not initialized yet
|
||||||
|
if [ ! -f $config_file ]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
# Reinitialize config
|
||||||
|
sed -i "s/log_timezone =.*$//g" $PGDATA/postgresql.conf
|
||||||
|
sed -i "s/timezone =.*$//g" $PGDATA/postgresql.conf
|
||||||
|
sed -i "s/wal_level =.*$//g" $config_file
|
||||||
|
sed -i "s/archive_mode =.*$//g" $config_file
|
||||||
|
sed -i "s/archive_timeout =.*$//g" $config_file
|
||||||
|
sed -i "s/archive_command =.*$//g" $config_file
|
||||||
|
|
||||||
|
# Configure wal-e
|
||||||
|
if [ "$wal" = true ] ; then
|
||||||
|
/docker-entrypoint-initdb.d/setup-wale.sh
|
||||||
|
fi
|
||||||
|
echo "log_timezone = $DEFAULT_TIMEZONE" >> $config_file
|
||||||
|
echo "timezone = $DEFAULT_TIMEZONE" >> $config_file
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ "${1:0:1}" = '-' ]; then
|
if [ "${1:0:1}" = '-' ]; then
|
||||||
set -- postgres "$@"
|
set -- postgres "$@"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$1" = 'postgres' ]; then
|
if [ "$1" = 'postgres' ]; then
|
||||||
VARS=(AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY WALE_S3_PREFIX AWS_REGION)
|
# Check wal-e variables
|
||||||
|
wal_enable=true
|
||||||
|
VARS=(AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY WALE_S3_PREFIX AWS_REGION)
|
||||||
|
for v in ${VARS[@]}; do
|
||||||
|
if [ "${!v}" = "" ]; then
|
||||||
|
echo "$v is required for Wal-E but not set. Skipping Wal-E setup."
|
||||||
|
wal_enable=false
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Setup wal-e env variables
|
||||||
|
if [ "$wal_enable" = true ] ; then
|
||||||
for v in ${VARS[@]}; do
|
for v in ${VARS[@]}; do
|
||||||
if [ "${!v}" = "" ]; then
|
export $v="${!v}"
|
||||||
echo "$v is required for Wal-E but not set. Skipping Wal-E setup."
|
|
||||||
update_conf
|
|
||||||
# Run the postgresql entrypoint
|
|
||||||
. /docker-entrypoint.sh
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
|
||||||
umask u=rwx,g=rx,o=
|
|
||||||
mkdir -p /etc/wal-e.d/env
|
|
||||||
|
|
||||||
for v in ${VARS[@]}; do
|
|
||||||
echo "${!v}" > /etc/wal-e.d/env/$v
|
|
||||||
done
|
|
||||||
chown -R root:postgres /etc/wal-e.d
|
|
||||||
|
|
||||||
WAL_LEVEL=archive
|
WAL_LEVEL=archive
|
||||||
ARCHIVE_MODE=on
|
ARCHIVE_MODE=on
|
||||||
|
fi
|
||||||
|
|
||||||
update_conf
|
# Update postgresql configuration
|
||||||
# Run the postgresql entrypoint
|
update_conf $wal_enable
|
||||||
. /docker-entrypoint.sh
|
|
||||||
|
# Run the postgresql entrypoint
|
||||||
|
. /docker-entrypoint.sh
|
||||||
fi
|
fi
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# wal-e specific
|
# wal-e specific configuration
|
||||||
echo "wal_level = $WAL_LEVEL" >> $PGDATA/postgresql.conf
|
echo "wal_level = $WAL_LEVEL" >> $PGDATA/postgresql.conf
|
||||||
echo "archive_mode = $ARCHIVE_MODE" >> $PGDATA/postgresql.conf
|
echo "archive_mode = $ARCHIVE_MODE" >> $PGDATA/postgresql.conf
|
||||||
echo "archive_command = 'envdir /etc/wal-e.d/env /usr/local/bin/wal-e wal-push %p'" >> $PGDATA/postgresql.conf
|
echo "archive_command = '/usr/bin/wal-e wal-push %p'" >> $PGDATA/postgresql.conf
|
||||||
echo "archive_timeout = $ARCHIVE_TIMEOUT" >> $PGDATA/postgresql.conf
|
echo "archive_timeout = $ARCHIVE_TIMEOUT" >> $PGDATA/postgresql.conf
|
||||||
|
Reference in New Issue
Block a user