Skip to content

Commit a4b2175

Browse files
committed
Add 10~beta1
1 parent 74857f4 commit a4b2175

8 files changed

+542
-5
lines changed

.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ env:
1212
- VERSION=9.3 VARIANT=alpine
1313
- VERSION=9.2
1414
- VERSION=9.2 VARIANT=alpine
15+
- VERSION=10
16+
- VERSION=10 VARIANT=alpine
1517

1618
install:
1719
- git clone https://github.com/docker-library/official-images.git ~/official-images

10/Dockerfile

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# vim:set ft=dockerfile:
2+
FROM debian:stretch
3+
4+
# explicitly set user/group IDs
5+
RUN groupadd -r postgres --gid=999 && useradd -r -g postgres --uid=999 postgres
6+
7+
# grab gosu for easy step-down from root
8+
ENV GOSU_VERSION 1.7
9+
RUN set -x \
10+
&& apt-get update && apt-get install -y --no-install-recommends ca-certificates wget && rm -rf /var/lib/apt/lists/* \
11+
&& wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \
12+
&& wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \
13+
&& export GNUPGHOME="$(mktemp -d)" \
14+
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \
15+
&& gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \
16+
&& rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc \
17+
&& chmod +x /usr/local/bin/gosu \
18+
&& gosu nobody true \
19+
&& apt-get purge -y --auto-remove ca-certificates wget
20+
21+
# make the "en_US.UTF-8" locale so postgres will be utf-8 enabled by default
22+
RUN apt-get update && apt-get install -y locales && rm -rf /var/lib/apt/lists/* \
23+
&& localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
24+
ENV LANG en_US.utf8
25+
26+
RUN mkdir /docker-entrypoint-initdb.d
27+
28+
RUN set -ex; \
29+
# pub 4096R/ACCC4CF8 2011-10-13 [expires: 2019-07-02]
30+
# Key fingerprint = B97B 0AFC AA1A 47F0 44F2 44A0 7FCC 7D46 ACCC 4CF8
31+
# uid PostgreSQL Debian Repository
32+
key='B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8'; \
33+
export GNUPGHOME="$(mktemp -d)"; \
34+
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \
35+
gpg --export "$key" > /etc/apt/trusted.gpg.d/postgres.gpg; \
36+
rm -r "$GNUPGHOME"; \
37+
apt-key list
38+
39+
ENV PG_MAJOR 10
40+
ENV PG_VERSION 10~beta1-1.pgdg90+1
41+
42+
RUN echo 'deb http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main' $PG_MAJOR > /etc/apt/sources.list.d/pgdg.list
43+
44+
RUN apt-get update \
45+
&& apt-get install -y postgresql-common \
46+
&& sed -ri 's/#(create_main_cluster) .*$/\1 = false/' /etc/postgresql-common/createcluster.conf \
47+
&& apt-get install -y \
48+
postgresql-$PG_MAJOR=$PG_VERSION \
49+
postgresql-contrib-$PG_MAJOR=$PG_VERSION \
50+
&& rm -rf /var/lib/apt/lists/*
51+
52+
# make the sample config easier to munge (and "correct by default")
53+
RUN mv -v /usr/share/postgresql/$PG_MAJOR/postgresql.conf.sample /usr/share/postgresql/ \
54+
&& ln -sv ../postgresql.conf.sample /usr/share/postgresql/$PG_MAJOR/ \
55+
&& sed -ri "s!^#?(listen_addresses)\s*=\s*\S+.*!\1 = '*'!" /usr/share/postgresql/postgresql.conf.sample
56+
57+
RUN mkdir -p /var/run/postgresql && chown -R postgres:postgres /var/run/postgresql && chmod 2777 /var/run/postgresql
58+
59+
ENV PATH /usr/lib/postgresql/$PG_MAJOR/bin:$PATH
60+
ENV PGDATA /var/lib/postgresql/data
61+
RUN mkdir -p "$PGDATA" && chown -R postgres:postgres "$PGDATA" && chmod 777 "$PGDATA" # this 777 will be replaced by 700 at runtime (allows semi-arbitrary "--user" values)
62+
VOLUME /var/lib/postgresql/data
63+
64+
COPY docker-entrypoint.sh /usr/local/bin/
65+
RUN ln -s usr/local/bin/docker-entrypoint.sh / # backwards compat
66+
ENTRYPOINT ["docker-entrypoint.sh"]
67+
68+
EXPOSE 5432
69+
CMD ["postgres"]

10/alpine/Dockerfile

+149
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
# vim:set ft=dockerfile:
2+
FROM alpine:3.6
3+
4+
# alpine includes "postgres" user/group in base install
5+
# /etc/passwd:22:postgres:x:70:70::/var/lib/postgresql:/bin/sh
6+
# /etc/group:34:postgres:x:70:
7+
# the home directory for the postgres user, however, is not created by default
8+
# see https://github.com/docker-library/postgres/issues/274
9+
RUN set -ex; \
10+
postgresHome="$(getent passwd postgres)"; \
11+
postgresHome="$(echo "$postgresHome" | cut -d: -f6)"; \
12+
[ "$postgresHome" = '/var/lib/postgresql' ]; \
13+
mkdir -p "$postgresHome"; \
14+
chown -R postgres:postgres "$postgresHome"
15+
16+
# su-exec (gosu-compatible) is installed further down
17+
18+
# make the "en_US.UTF-8" locale so postgres will be utf-8 enabled by default
19+
# alpine doesn't require explicit locale-file generation
20+
ENV LANG en_US.utf8
21+
22+
RUN mkdir /docker-entrypoint-initdb.d
23+
24+
ENV PG_MAJOR 10
25+
ENV PG_VERSION 10beta1
26+
ENV PG_SHA256 7eee02e6f6646c7d4d6e78893a4ff638cfa5f1025b706712da8c6ef2257b5e29
27+
28+
RUN set -ex \
29+
\
30+
&& apk add --no-cache --virtual .fetch-deps \
31+
ca-certificates \
32+
openssl \
33+
tar \
34+
\
35+
&& wget -O postgresql.tar.bz2 "https://ftp.postgresql.org/pub/source/v$PG_VERSION/postgresql-$PG_VERSION.tar.bz2" \
36+
&& echo "$PG_SHA256 *postgresql.tar.bz2" | sha256sum -c - \
37+
&& mkdir -p /usr/src/postgresql \
38+
&& tar \
39+
--extract \
40+
--file postgresql.tar.bz2 \
41+
--directory /usr/src/postgresql \
42+
--strip-components 1 \
43+
&& rm postgresql.tar.bz2 \
44+
\
45+
&& apk add --no-cache --virtual .build-deps \
46+
bison \
47+
coreutils \
48+
dpkg-dev dpkg \
49+
flex \
50+
gcc \
51+
# krb5-dev \
52+
libc-dev \
53+
libedit-dev \
54+
libxml2-dev \
55+
libxslt-dev \
56+
make \
57+
# openldap-dev \
58+
openssl-dev \
59+
perl \
60+
# perl-dev \
61+
# python-dev \
62+
# python3-dev \
63+
# tcl-dev \
64+
util-linux-dev \
65+
zlib-dev \
66+
\
67+
&& cd /usr/src/postgresql \
68+
# update "DEFAULT_PGSOCKET_DIR" to "/var/run/postgresql" (matching Debian)
69+
# see https://anonscm.debian.org/git/pkg-postgresql/postgresql.git/tree/debian/patches/51-default-sockets-in-var.patch?id=8b539fcb3e093a521c095e70bdfa76887217b89f
70+
&& awk '$1 == "#define" && $2 == "DEFAULT_PGSOCKET_DIR" && $3 == "\"/tmp\"" { $3 = "\"/var/run/postgresql\""; print; next } { print }' src/include/pg_config_manual.h > src/include/pg_config_manual.h.new \
71+
&& grep '/var/run/postgresql' src/include/pg_config_manual.h.new \
72+
&& mv src/include/pg_config_manual.h.new src/include/pg_config_manual.h \
73+
&& gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)" \
74+
# explicitly update autoconf config.guess and config.sub so they support more arches/libcs
75+
&& wget -O config/config.guess 'https://git.savannah.gnu.org/cgit/config.git/plain/config.guess?id=7d3d27baf8107b630586c962c057e22149653deb' \
76+
&& wget -O config/config.sub 'https://git.savannah.gnu.org/cgit/config.git/plain/config.sub?id=7d3d27baf8107b630586c962c057e22149653deb' \
77+
# configure options taken from:
78+
# https://anonscm.debian.org/cgit/pkg-postgresql/postgresql.git/tree/debian/rules?h=9.5
79+
&& ./configure \
80+
--build="$gnuArch" \
81+
# "/usr/src/postgresql/src/backend/access/common/tupconvert.c:105: undefined reference to `libintl_gettext'"
82+
# --enable-nls \
83+
--enable-integer-datetimes \
84+
--enable-thread-safety \
85+
--enable-tap-tests \
86+
# skip debugging info -- we want tiny size instead
87+
# --enable-debug \
88+
--disable-rpath \
89+
--with-uuid=e2fs \
90+
--with-gnu-ld \
91+
--with-pgport=5432 \
92+
--with-system-tzdata=/usr/share/zoneinfo \
93+
--prefix=/usr/local \
94+
--with-includes=/usr/local/include \
95+
--with-libraries=/usr/local/lib \
96+
\
97+
# these make our image abnormally large (at least 100MB larger), which seems uncouth for an "Alpine" (ie, "small") variant :)
98+
# --with-krb5 \
99+
# --with-gssapi \
100+
# --with-ldap \
101+
# --with-tcl \
102+
# --with-perl \
103+
# --with-python \
104+
# --with-pam \
105+
--with-openssl \
106+
--with-libxml \
107+
--with-libxslt \
108+
&& make -j "$(nproc)" world \
109+
&& make install-world \
110+
&& make -C contrib install \
111+
\
112+
&& runDeps="$( \
113+
scanelf --needed --nobanner --recursive /usr/local \
114+
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
115+
| sort -u \
116+
| xargs -r apk info --installed \
117+
| sort -u \
118+
)" \
119+
&& apk add --no-cache --virtual .postgresql-rundeps \
120+
$runDeps \
121+
bash \
122+
su-exec \
123+
# tzdata is optional, but only adds around 1Mb to image size and is recommended by Django documentation:
124+
# https://docs.djangoproject.com/en/1.10/ref/databases/#optimizing-postgresql-s-configuration
125+
tzdata \
126+
&& apk del .fetch-deps .build-deps \
127+
&& cd / \
128+
&& rm -rf \
129+
/usr/src/postgresql \
130+
/usr/local/share/doc \
131+
/usr/local/share/man \
132+
&& find /usr/local -name '*.a' -delete
133+
134+
# make the sample config easier to munge (and "correct by default")
135+
RUN sed -ri "s!^#?(listen_addresses)\s*=\s*\S+.*!\1 = '*'!" /usr/local/share/postgresql/postgresql.conf.sample
136+
137+
RUN mkdir -p /var/run/postgresql && chown -R postgres:postgres /var/run/postgresql && chmod 2777 /var/run/postgresql
138+
139+
ENV PATH /usr/lib/postgresql/$PG_MAJOR/bin:$PATH
140+
ENV PGDATA /var/lib/postgresql/data
141+
RUN mkdir -p "$PGDATA" && chown -R postgres:postgres "$PGDATA" && chmod 777 "$PGDATA" # this 777 will be replaced by 700 at runtime (allows semi-arbitrary "--user" values)
142+
VOLUME /var/lib/postgresql/data
143+
144+
COPY docker-entrypoint.sh /usr/local/bin/
145+
RUN ln -s usr/local/bin/docker-entrypoint.sh / # backwards compat
146+
ENTRYPOINT ["docker-entrypoint.sh"]
147+
148+
EXPOSE 5432
149+
CMD ["postgres"]

10/alpine/docker-entrypoint.sh

+145
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# usage: file_env VAR [DEFAULT]
5+
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
6+
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
7+
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
8+
file_env() {
9+
local var="$1"
10+
local fileVar="${var}_FILE"
11+
local def="${2:-}"
12+
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
13+
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
14+
exit 1
15+
fi
16+
local val="$def"
17+
if [ "${!var:-}" ]; then
18+
val="${!var}"
19+
elif [ "${!fileVar:-}" ]; then
20+
val="$(< "${!fileVar}")"
21+
fi
22+
export "$var"="$val"
23+
unset "$fileVar"
24+
}
25+
26+
if [ "${1:0:1}" = '-' ]; then
27+
set -- postgres "$@"
28+
fi
29+
30+
# allow the container to be started with `--user`
31+
if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
32+
mkdir -p "$PGDATA"
33+
chown -R postgres "$PGDATA"
34+
chmod 700 "$PGDATA"
35+
36+
mkdir -p /var/run/postgresql
37+
chown -R postgres /var/run/postgresql
38+
chmod 775 /var/run/postgresql
39+
40+
# Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user
41+
if [ "$POSTGRES_INITDB_XLOGDIR" ]; then
42+
mkdir -p "$POSTGRES_INITDB_XLOGDIR"
43+
chown -R postgres "$POSTGRES_INITDB_XLOGDIR"
44+
chmod 700 "$POSTGRES_INITDB_XLOGDIR"
45+
fi
46+
47+
exec su-exec postgres "$BASH_SOURCE" "$@"
48+
fi
49+
50+
if [ "$1" = 'postgres' ]; then
51+
mkdir -p "$PGDATA"
52+
chown -R "$(id -u)" "$PGDATA" 2>/dev/null || :
53+
chmod 700 "$PGDATA" 2>/dev/null || :
54+
55+
# look specifically for PG_VERSION, as it is expected in the DB dir
56+
if [ ! -s "$PGDATA/PG_VERSION" ]; then
57+
file_env 'POSTGRES_INITDB_ARGS'
58+
if [ "$POSTGRES_INITDB_XLOGDIR" ]; then
59+
export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR"
60+
fi
61+
eval "initdb --username=postgres $POSTGRES_INITDB_ARGS"
62+
63+
# check password first so we can output the warning before postgres
64+
# messes it up
65+
file_env 'POSTGRES_PASSWORD'
66+
if [ "$POSTGRES_PASSWORD" ]; then
67+
pass="PASSWORD '$POSTGRES_PASSWORD'"
68+
authMethod=md5
69+
else
70+
# The - option suppresses leading tabs but *not* spaces. :)
71+
cat >&2 <<-'EOWARN'
72+
****************************************************
73+
WARNING: No password has been set for the database.
74+
This will allow anyone with access to the
75+
Postgres port to access your database. In
76+
Docker's default configuration, this is
77+
effectively any other container on the same
78+
system.
79+
80+
Use "-e POSTGRES_PASSWORD=password" to set
81+
it in "docker run".
82+
****************************************************
83+
EOWARN
84+
85+
pass=
86+
authMethod=trust
87+
fi
88+
89+
{
90+
echo
91+
echo "host all all all $authMethod"
92+
} >> "$PGDATA/pg_hba.conf"
93+
94+
# internal start of server in order to allow set-up using psql-client
95+
# does not listen on external TCP/IP and waits until start finishes
96+
PGUSER="${PGUSER:-postgres}" \
97+
pg_ctl -D "$PGDATA" \
98+
-o "-c listen_addresses='localhost'" \
99+
-w start
100+
101+
file_env 'POSTGRES_USER' 'postgres'
102+
file_env 'POSTGRES_DB' "$POSTGRES_USER"
103+
104+
psql=( psql -v ON_ERROR_STOP=1 )
105+
106+
if [ "$POSTGRES_DB" != 'postgres' ]; then
107+
"${psql[@]}" --username postgres <<-EOSQL
108+
CREATE DATABASE "$POSTGRES_DB" ;
109+
EOSQL
110+
echo
111+
fi
112+
113+
if [ "$POSTGRES_USER" = 'postgres' ]; then
114+
op='ALTER'
115+
else
116+
op='CREATE'
117+
fi
118+
"${psql[@]}" --username postgres <<-EOSQL
119+
$op USER "$POSTGRES_USER" WITH SUPERUSER $pass ;
120+
EOSQL
121+
echo
122+
123+
psql+=( --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" )
124+
125+
echo
126+
for f in /docker-entrypoint-initdb.d/*; do
127+
case "$f" in
128+
*.sh) echo "$0: running $f"; . "$f" ;;
129+
*.sql) echo "$0: running $f"; "${psql[@]}" -f "$f"; echo ;;
130+
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${psql[@]}"; echo ;;
131+
*) echo "$0: ignoring $f" ;;
132+
esac
133+
echo
134+
done
135+
136+
PGUSER="${PGUSER:-postgres}" \
137+
pg_ctl -D "$PGDATA" -m fast -w stop
138+
139+
echo
140+
echo 'PostgreSQL init process complete; ready for start up.'
141+
echo
142+
fi
143+
fi
144+
145+
exec "$@"

0 commit comments

Comments
 (0)