Skip to content
This repository was archived by the owner on Nov 7, 2022. It is now read-only.

Commit 9c5ca99

Browse files
authored
Merge pull request docker-library#736 from simi/13beta1
Add PostgreSQL 13 beta 1.
2 parents 5104b38 + 682ff83 commit 9c5ca99

File tree

6 files changed

+1029
-13
lines changed

6 files changed

+1029
-13
lines changed

13/Dockerfile

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
# vim:set ft=dockerfile:
2+
FROM debian:buster-slim
3+
4+
RUN set -ex; \
5+
if ! command -v gpg > /dev/null; then \
6+
apt-get update; \
7+
apt-get install -y --no-install-recommends \
8+
gnupg \
9+
dirmngr \
10+
; \
11+
rm -rf /var/lib/apt/lists/*; \
12+
fi
13+
14+
# explicitly set user/group IDs
15+
RUN set -eux; \
16+
groupadd -r postgres --gid=999; \
17+
# https://salsa.debian.org/postgresql/postgresql-common/blob/997d842ee744687d99a2b2d95c1083a2615c79e8/debian/postgresql-common.postinst#L32-35
18+
useradd -r -g postgres --uid=999 --home-dir=/var/lib/postgresql --shell=/bin/bash postgres; \
19+
# also create the postgres user's home directory with appropriate permissions
20+
# see https://github.com/docker-library/postgres/issues/274
21+
mkdir -p /var/lib/postgresql; \
22+
chown -R postgres:postgres /var/lib/postgresql
23+
24+
# grab gosu for easy step-down from root
25+
# https://github.com/tianon/gosu/releases
26+
ENV GOSU_VERSION 1.12
27+
RUN set -eux; \
28+
savedAptMark="$(apt-mark showmanual)"; \
29+
apt-get update; \
30+
apt-get install -y --no-install-recommends ca-certificates wget; \
31+
rm -rf /var/lib/apt/lists/*; \
32+
dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \
33+
wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch"; \
34+
wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc"; \
35+
export GNUPGHOME="$(mktemp -d)"; \
36+
gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \
37+
gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
38+
gpgconf --kill all; \
39+
rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \
40+
apt-mark auto '.*' > /dev/null; \
41+
[ -z "$savedAptMark" ] || apt-mark manual $savedAptMark > /dev/null; \
42+
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
43+
chmod +x /usr/local/bin/gosu; \
44+
gosu --version; \
45+
gosu nobody true
46+
47+
# make the "en_US.UTF-8" locale so postgres will be utf-8 enabled by default
48+
RUN set -eux; \
49+
if [ -f /etc/dpkg/dpkg.cfg.d/docker ]; then \
50+
# if this file exists, we're likely in "debian:xxx-slim", and locales are thus being excluded so we need to remove that exclusion (since we need locales)
51+
grep -q '/usr/share/locale' /etc/dpkg/dpkg.cfg.d/docker; \
52+
sed -ri '/\/usr\/share\/locale/d' /etc/dpkg/dpkg.cfg.d/docker; \
53+
! grep -q '/usr/share/locale' /etc/dpkg/dpkg.cfg.d/docker; \
54+
fi; \
55+
apt-get update; apt-get install -y --no-install-recommends locales; rm -rf /var/lib/apt/lists/*; \
56+
localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
57+
ENV LANG en_US.utf8
58+
59+
RUN set -eux; \
60+
apt-get update; \
61+
apt-get install -y --no-install-recommends \
62+
# install "nss_wrapper" in case we need to fake "/etc/passwd" and "/etc/group" (especially for OpenShift)
63+
# https://github.com/docker-library/postgres/issues/359
64+
# https://cwrap.org/nss_wrapper.html
65+
libnss-wrapper \
66+
# install "xz-utils" for .sql.xz docker-entrypoint-initdb.d files
67+
xz-utils \
68+
; \
69+
rm -rf /var/lib/apt/lists/*
70+
71+
RUN mkdir /docker-entrypoint-initdb.d
72+
73+
RUN set -ex; \
74+
# pub 4096R/ACCC4CF8 2011-10-13 [expires: 2019-07-02]
75+
# Key fingerprint = B97B 0AFC AA1A 47F0 44F2 44A0 7FCC 7D46 ACCC 4CF8
76+
# uid PostgreSQL Debian Repository
77+
key='B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8'; \
78+
export GNUPGHOME="$(mktemp -d)"; \
79+
gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \
80+
gpg --batch --export "$key" > /etc/apt/trusted.gpg.d/postgres.gpg; \
81+
command -v gpgconf > /dev/null && gpgconf --kill all; \
82+
rm -rf "$GNUPGHOME"; \
83+
apt-key list
84+
85+
ENV PG_MAJOR 13
86+
ENV PG_VERSION 13~beta1-1.pgdg100+1
87+
88+
RUN set -ex; \
89+
\
90+
# see note below about "*.pyc" files
91+
export PYTHONDONTWRITEBYTECODE=1; \
92+
\
93+
dpkgArch="$(dpkg --print-architecture)"; \
94+
case "$dpkgArch" in \
95+
amd64 | arm64 | i386 | ppc64el) \
96+
# arches officialy built by upstream
97+
echo "deb http://apt.postgresql.org/pub/repos/apt/ buster-pgdg main $PG_MAJOR" > /etc/apt/sources.list.d/pgdg.list; \
98+
apt-get update; \
99+
;; \
100+
*) \
101+
# we're on an architecture upstream doesn't officially build for
102+
# let's build binaries from their published source packages
103+
echo "deb-src http://apt.postgresql.org/pub/repos/apt/ buster-pgdg main $PG_MAJOR" > /etc/apt/sources.list.d/pgdg.list; \
104+
\
105+
case "$PG_MAJOR" in \
106+
9.* | 10 ) ;; \
107+
*) \
108+
# https://github.com/docker-library/postgres/issues/484 (clang-6.0 required, only available in stretch-backports)
109+
# TODO remove this once we hit buster+
110+
echo 'deb http://deb.debian.org/debian buster-backports main' >> /etc/apt/sources.list.d/pgdg.list; \
111+
;; \
112+
esac; \
113+
\
114+
tempDir="$(mktemp -d)"; \
115+
cd "$tempDir"; \
116+
\
117+
savedAptMark="$(apt-mark showmanual)"; \
118+
\
119+
# build .deb files from upstream's source packages (which are verified by apt-get)
120+
apt-get update; \
121+
# we need DEBIAN_FRONTEND on postgresql-13 for slapd ("Please enter the password for the admin entry in your LDAP directory."); see https://bugs.debian.org/929417
122+
DEBIAN_FRONTEND=noninteractive \
123+
apt-get build-dep -y \
124+
postgresql-common pgdg-keyring \
125+
"postgresql-$PG_MAJOR=$PG_VERSION" \
126+
; \
127+
DEB_BUILD_OPTIONS="nocheck parallel=$(nproc)" \
128+
apt-get source --compile \
129+
postgresql-common pgdg-keyring \
130+
"postgresql-$PG_MAJOR=$PG_VERSION" \
131+
; \
132+
# we don't remove APT lists here because they get re-downloaded and removed later
133+
\
134+
# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies
135+
# (which is done after we install the built packages so we don't have to redownload any overlapping dependencies)
136+
apt-mark showmanual | xargs apt-mark auto > /dev/null; \
137+
apt-mark manual $savedAptMark; \
138+
\
139+
# create a temporary local APT repo to install from (so that dependency resolution can be handled by APT, as it should be)
140+
ls -lAFh; \
141+
dpkg-scanpackages . > Packages; \
142+
grep '^Package: ' Packages; \
143+
echo "deb [ trusted=yes ] file://$tempDir ./" > /etc/apt/sources.list.d/temp.list; \
144+
# work around the following APT issue by using "Acquire::GzipIndexes=false" (overriding "/etc/apt/apt.conf.d/docker-gzip-indexes")
145+
# Could not open file /var/lib/apt/lists/partial/_tmp_tmp.ODWljpQfkE_._Packages - open (13: Permission denied)
146+
# ...
147+
# E: Failed to fetch store:/var/lib/apt/lists/partial/_tmp_tmp.ODWljpQfkE_._Packages Could not open file /var/lib/apt/lists/partial/_tmp_tmp.ODWljpQfkE_._Packages - open (13: Permission denied)
148+
apt-get -o Acquire::GzipIndexes=false update; \
149+
;; \
150+
esac; \
151+
\
152+
apt-get install -y --no-install-recommends postgresql-common; \
153+
sed -ri 's/#(create_main_cluster) .*$/\1 = false/' /etc/postgresql-common/createcluster.conf; \
154+
apt-get install -y --no-install-recommends \
155+
"postgresql-$PG_MAJOR=$PG_VERSION" \
156+
; \
157+
\
158+
rm -rf /var/lib/apt/lists/*; \
159+
\
160+
if [ -n "$tempDir" ]; then \
161+
# if we have leftovers from building, let's purge them (including extra, unnecessary build deps)
162+
apt-get purge -y --auto-remove; \
163+
rm -rf "$tempDir" /etc/apt/sources.list.d/temp.list; \
164+
fi; \
165+
\
166+
# some of the steps above generate a lot of "*.pyc" files (and setting "PYTHONDONTWRITEBYTECODE" beforehand doesn't propagate properly for some reason), so we clean them up manually (as long as they aren't owned by a package)
167+
find /usr -name '*.pyc' -type f -exec bash -c 'for pyc; do dpkg -S "$pyc" &> /dev/null || rm -vf "$pyc"; done' -- '{}' +
168+
169+
# make the sample config easier to munge (and "correct by default")
170+
RUN set -eux; \
171+
dpkg-divert --add --rename --divert "/usr/share/postgresql/postgresql.conf.sample.dpkg" "/usr/share/postgresql/$PG_MAJOR/postgresql.conf.sample"; \
172+
cp -v /usr/share/postgresql/postgresql.conf.sample.dpkg /usr/share/postgresql/postgresql.conf.sample; \
173+
ln -sv ../postgresql.conf.sample "/usr/share/postgresql/$PG_MAJOR/"; \
174+
sed -ri "s!^#?(listen_addresses)\s*=\s*\S+.*!\1 = '*'!" /usr/share/postgresql/postgresql.conf.sample; \
175+
grep -F "listen_addresses = '*'" /usr/share/postgresql/postgresql.conf.sample
176+
177+
RUN mkdir -p /var/run/postgresql && chown -R postgres:postgres /var/run/postgresql && chmod 2777 /var/run/postgresql
178+
179+
ENV PATH $PATH:/usr/lib/postgresql/$PG_MAJOR/bin
180+
ENV PGDATA /var/lib/postgresql/data
181+
# this 777 will be replaced by 700 at runtime (allows semi-arbitrary "--user" values)
182+
RUN mkdir -p "$PGDATA" && chown -R postgres:postgres "$PGDATA" && chmod 777 "$PGDATA"
183+
VOLUME /var/lib/postgresql/data
184+
185+
COPY docker-entrypoint.sh /usr/local/bin/
186+
RUN ln -s usr/local/bin/docker-entrypoint.sh / # backwards compat
187+
ENTRYPOINT ["docker-entrypoint.sh"]
188+
189+
EXPOSE 5432
190+
CMD ["postgres"]

13/alpine/Dockerfile

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

0 commit comments

Comments
 (0)