Skip to content

Commit 6274e4c

Browse files
authored
Merge pull request #586 from piotrbrzuska/master
Add 12~beta1
2 parents 2035bd0 + 966d1ba commit 6274e4c

12 files changed

+697
-2
lines changed

.travis.yml

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ language: bash
22
services: docker
33

44
env:
5+
- VERSION=12
6+
- VERSION=12 FORCE_DEB_BUILD=1
7+
- VERSION=12 VARIANT=alpine
58
- VERSION=11
69
- VERSION=11 FORCE_DEB_BUILD=1
710
- VERSION=11 VARIANT=alpine

10/alpine/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ RUN set -ex \
5353
libedit-dev \
5454
libxml2-dev \
5555
libxslt-dev \
56+
linux-headers \
5657
make \
5758
# openldap-dev \
5859
openssl-dev \

11/alpine/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ RUN set -ex \
5353
libedit-dev \
5454
libxml2-dev \
5555
libxslt-dev \
56+
linux-headers \
5657
make \
5758
# openldap-dev \
5859
openssl-dev \

12/Dockerfile

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

12/alpine/Dockerfile

+153
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# vim:set ft=dockerfile:
2+
FROM alpine:3.9
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 12
25+
ENV PG_VERSION 12beta1
26+
ENV PG_SHA256 203e2d0151d75e3328a6b6b85eae88e50168ae27423b39787cea595365da9fad
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+
linux-headers \
57+
make \
58+
# openldap-dev \
59+
openssl-dev \
60+
# configure: error: prove not found
61+
perl-utils \
62+
# configure: error: Perl module IPC::Run is required to run TAP tests
63+
perl-ipc-run \
64+
# perl-dev \
65+
# python-dev \
66+
# python3-dev \
67+
# tcl-dev \
68+
util-linux-dev \
69+
zlib-dev \
70+
icu-dev \
71+
\
72+
&& cd /usr/src/postgresql \
73+
# update "DEFAULT_PGSOCKET_DIR" to "/var/run/postgresql" (matching Debian)
74+
# see https://anonscm.debian.org/git/pkg-postgresql/postgresql.git/tree/debian/patches/51-default-sockets-in-var.patch?id=8b539fcb3e093a521c095e70bdfa76887217b89f
75+
&& 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 \
76+
&& grep '/var/run/postgresql' src/include/pg_config_manual.h.new \
77+
&& mv src/include/pg_config_manual.h.new src/include/pg_config_manual.h \
78+
&& gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)" \
79+
# explicitly update autoconf config.guess and config.sub so they support more arches/libcs
80+
&& wget -O config/config.guess 'https://git.savannah.gnu.org/cgit/config.git/plain/config.guess?id=7d3d27baf8107b630586c962c057e22149653deb' \
81+
&& wget -O config/config.sub 'https://git.savannah.gnu.org/cgit/config.git/plain/config.sub?id=7d3d27baf8107b630586c962c057e22149653deb' \
82+
# configure options taken from:
83+
# https://anonscm.debian.org/cgit/pkg-postgresql/postgresql.git/tree/debian/rules?h=9.5
84+
&& ./configure \
85+
--build="$gnuArch" \
86+
# "/usr/src/postgresql/src/backend/access/common/tupconvert.c:105: undefined reference to `libintl_gettext'"
87+
# --enable-nls \
88+
--enable-integer-datetimes \
89+
--enable-thread-safety \
90+
--enable-tap-tests \
91+
# skip debugging info -- we want tiny size instead
92+
# --enable-debug \
93+
--disable-rpath \
94+
--with-uuid=e2fs \
95+
--with-gnu-ld \
96+
--with-pgport=5432 \
97+
--with-system-tzdata=/usr/share/zoneinfo \
98+
--prefix=/usr/local \
99+
--with-includes=/usr/local/include \
100+
--with-libraries=/usr/local/lib \
101+
\
102+
# these make our image abnormally large (at least 100MB larger), which seems uncouth for an "Alpine" (ie, "small") variant :)
103+
# --with-krb5 \
104+
# --with-gssapi \
105+
# --with-ldap \
106+
# --with-tcl \
107+
# --with-perl \
108+
# --with-python \
109+
# --with-pam \
110+
--with-openssl \
111+
--with-libxml \
112+
--with-libxslt \
113+
--with-icu \
114+
&& make -j "$(nproc)" world \
115+
&& make install-world \
116+
&& make -C contrib install \
117+
\
118+
&& runDeps="$( \
119+
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local \
120+
| tr ',' '\n' \
121+
| sort -u \
122+
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
123+
)" \
124+
&& apk add --no-cache --virtual .postgresql-rundeps \
125+
$runDeps \
126+
bash \
127+
su-exec \
128+
# tzdata is optional, but only adds around 1Mb to image size and is recommended by Django documentation:
129+
# https://docs.djangoproject.com/en/1.10/ref/databases/#optimizing-postgresql-s-configuration
130+
tzdata \
131+
&& apk del .fetch-deps .build-deps \
132+
&& cd / \
133+
&& rm -rf \
134+
/usr/src/postgresql \
135+
/usr/local/share/doc \
136+
/usr/local/share/man \
137+
&& find /usr/local -name '*.a' -delete
138+
139+
# make the sample config easier to munge (and "correct by default")
140+
RUN sed -ri "s!^#?(listen_addresses)\s*=\s*\S+.*!\1 = '*'!" /usr/local/share/postgresql/postgresql.conf.sample
141+
142+
RUN mkdir -p /var/run/postgresql && chown -R postgres:postgres /var/run/postgresql && chmod 2777 /var/run/postgresql
143+
144+
ENV PGDATA /var/lib/postgresql/data
145+
# this 777 will be replaced by 700 at runtime (allows semi-arbitrary "--user" values)
146+
RUN mkdir -p "$PGDATA" && chown -R postgres:postgres "$PGDATA" && chmod 777 "$PGDATA"
147+
VOLUME /var/lib/postgresql/data
148+
149+
COPY docker-entrypoint.sh /usr/local/bin/
150+
ENTRYPOINT ["docker-entrypoint.sh"]
151+
152+
EXPOSE 5432
153+
CMD ["postgres"]

0 commit comments

Comments
 (0)