Skip to content

Commit cd3f3b1

Browse files
committed
Use "apt-get source --compile" to build for Debian architectures upstream doesn't
1 parent 58ed939 commit cd3f3b1

10 files changed

+496
-95
lines changed

.travis.yml

+19-2
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,22 @@ services: docker
33

44
env:
55
- VERSION=9.6
6+
- VERSION=9.6 FORCE_DEB_BUILD=1
67
- VERSION=9.6 VARIANT=alpine
78
- VERSION=9.5
9+
- VERSION=9.5 FORCE_DEB_BUILD=1
810
- VERSION=9.5 VARIANT=alpine
911
- VERSION=9.4
12+
- VERSION=9.4 FORCE_DEB_BUILD=1
1013
- VERSION=9.4 VARIANT=alpine
1114
- VERSION=9.3
15+
- VERSION=9.3 FORCE_DEB_BUILD=1
1216
- VERSION=9.3 VARIANT=alpine
1317
- VERSION=9.2
18+
- VERSION=9.2 FORCE_DEB_BUILD=1
1419
- VERSION=9.2 VARIANT=alpine
1520
- VERSION=10
21+
- VERSION=10 FORCE_DEB_BUILD=1
1622
- VERSION=10 VARIANT=alpine
1723

1824
install:
@@ -24,8 +30,19 @@ before_script:
2430
- image="postgres:${VERSION}${VARIANT:+-${VARIANT}}"
2531

2632
script:
27-
- travis_retry docker build -t "$image" .
28-
- ~/official-images/test/run.sh "$image"
33+
- |
34+
(
35+
set -Eeuo pipefail
36+
set -x
37+
if [ -n "${FORCE_DEB_BUILD:+x}" ]; then
38+
[ "$(dpkg --print-architecture)" = 'amd64' ]
39+
grep -qE 'amd64[|]' Dockerfile
40+
sed -ri -e 's/amd64[|]//g' Dockerfile
41+
! grep -qE 'amd64[|]' Dockerfile
42+
fi
43+
travis_retry docker build -t "$image" .
44+
~/official-images/test/run.sh "$image"
45+
)
2946
3047
after_script:
3148
- docker images

10/Dockerfile

+66-11
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ RUN set -ex; \
1515
RUN groupadd -r postgres --gid=999 && useradd -r -g postgres --uid=999 postgres
1616

1717
# grab gosu for easy step-down from root
18-
ENV GOSU_VERSION 1.7
18+
ENV GOSU_VERSION 1.10
1919
RUN set -x \
2020
&& apt-get update && apt-get install -y --no-install-recommends ca-certificates wget && rm -rf /var/lib/apt/lists/* \
2121
&& wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \
@@ -49,18 +49,73 @@ RUN set -ex; \
4949
ENV PG_MAJOR 10
5050
ENV PG_VERSION 10~beta3-1.pgdg90+1
5151

52-
RUN echo 'deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main' $PG_MAJOR > /etc/apt/sources.list.d/pgdg.list
53-
54-
RUN apt-get update \
55-
&& apt-get install -y postgresql-common \
56-
&& sed -ri 's/#(create_main_cluster) .*$/\1 = false/' /etc/postgresql-common/createcluster.conf \
57-
&& apt-get install -y \
58-
postgresql-$PG_MAJOR=$PG_VERSION \
59-
&& rm -rf /var/lib/apt/lists/*
52+
RUN set -ex; \
53+
\
54+
dpkgArch="$(dpkg --print-architecture)"; \
55+
case "$dpkgArch" in \
56+
amd64|i386|ppc64el) \
57+
# arches officialy built by upstream
58+
echo "deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main $PG_MAJOR" > /etc/apt/sources.list.d/pgdg.list; \
59+
apt-get update; \
60+
;; \
61+
*) \
62+
# we're on an architecture upstream doesn't officially build for
63+
# let's build binaries from their published source packages
64+
echo "deb-src http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main $PG_MAJOR" > /etc/apt/sources.list.d/pgdg.list; \
65+
\
66+
tempDir="$(mktemp -d)"; \
67+
cd "$tempDir"; \
68+
\
69+
savedAptMark="$(apt-mark showmanual)"; \
70+
\
71+
# build .deb files from upstream's source packages (which are verified by apt-get)
72+
apt-get update; \
73+
apt-get build-dep -y \
74+
postgresql-common pgdg-keyring \
75+
"postgresql-$PG_MAJOR=$PG_VERSION" \
76+
; \
77+
DEB_BUILD_OPTIONS="nocheck parallel=$(nproc)" \
78+
apt-get source --compile \
79+
postgresql-common pgdg-keyring \
80+
"postgresql-$PG_MAJOR=$PG_VERSION" \
81+
; \
82+
# we don't remove APT lists here because they get re-downloaded and removed later
83+
\
84+
# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies
85+
# (which is done after we install the built packages so we don't have to redownload any overlapping dependencies)
86+
apt-mark showmanual | xargs apt-mark auto > /dev/null; \
87+
apt-mark manual $savedAptMark; \
88+
\
89+
# create a temporary local APT repo to install from (so that dependency resolution can be handled by APT, as it should be)
90+
ls -lAFh; \
91+
dpkg-scanpackages . > Packages; \
92+
grep '^Package: ' Packages; \
93+
echo "deb [ trusted=yes ] file://$tempDir ./" > /etc/apt/sources.list.d/temp.list; \
94+
# work around the following APT issue by using "Acquire::GzipIndexes=false" (overriding "/etc/apt/apt.conf.d/docker-gzip-indexes")
95+
# Could not open file /var/lib/apt/lists/partial/_tmp_tmp.ODWljpQfkE_._Packages - open (13: Permission denied)
96+
# ...
97+
# 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)
98+
apt-get -o Acquire::GzipIndexes=false update; \
99+
;; \
100+
esac; \
101+
\
102+
apt-get install -y postgresql-common; \
103+
sed -ri 's/#(create_main_cluster) .*$/\1 = false/' /etc/postgresql-common/createcluster.conf; \
104+
apt-get install -y \
105+
"postgresql-$PG_MAJOR=$PG_VERSION" \
106+
; \
107+
\
108+
rm -rf /var/lib/apt/lists/*; \
109+
\
110+
if [ -n "$tempDir" ]; then \
111+
# if we have leftovers from building, let's purge them (including extra, unnecessary build deps)
112+
apt-get purge -y --auto-remove; \
113+
rm -rf "$tempDir" /etc/apt/sources.list.d/temp.list; \
114+
fi
60115

61116
# make the sample config easier to munge (and "correct by default")
62-
RUN mv -v /usr/share/postgresql/$PG_MAJOR/postgresql.conf.sample /usr/share/postgresql/ \
63-
&& ln -sv ../postgresql.conf.sample /usr/share/postgresql/$PG_MAJOR/ \
117+
RUN mv -v "/usr/share/postgresql/$PG_MAJOR/postgresql.conf.sample" /usr/share/postgresql/ \
118+
&& ln -sv ../postgresql.conf.sample "/usr/share/postgresql/$PG_MAJOR/" \
64119
&& sed -ri "s!^#?(listen_addresses)\s*=\s*\S+.*!\1 = '*'!" /usr/share/postgresql/postgresql.conf.sample
65120

66121
RUN mkdir -p /var/run/postgresql && chown -R postgres:postgres /var/run/postgresql && chmod 2777 /var/run/postgresql

9.2/Dockerfile

+67-12
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ RUN set -ex; \
1515
RUN groupadd -r postgres --gid=999 && useradd -r -g postgres --uid=999 postgres
1616

1717
# grab gosu for easy step-down from root
18-
ENV GOSU_VERSION 1.7
18+
ENV GOSU_VERSION 1.10
1919
RUN set -x \
2020
&& apt-get update && apt-get install -y --no-install-recommends ca-certificates wget && rm -rf /var/lib/apt/lists/* \
2121
&& wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \
@@ -49,19 +49,74 @@ RUN set -ex; \
4949
ENV PG_MAJOR 9.2
5050
ENV PG_VERSION 9.2.22-1.pgdg80+1
5151

52-
RUN echo 'deb http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main' $PG_MAJOR > /etc/apt/sources.list.d/pgdg.list
53-
54-
RUN apt-get update \
55-
&& apt-get install -y postgresql-common \
56-
&& sed -ri 's/#(create_main_cluster) .*$/\1 = false/' /etc/postgresql-common/createcluster.conf \
57-
&& apt-get install -y \
58-
postgresql-$PG_MAJOR=$PG_VERSION \
59-
postgresql-contrib-$PG_MAJOR=$PG_VERSION \
60-
&& rm -rf /var/lib/apt/lists/*
52+
RUN set -ex; \
53+
\
54+
dpkgArch="$(dpkg --print-architecture)"; \
55+
case "$dpkgArch" in \
56+
amd64|i386|ppc64el) \
57+
# arches officialy built by upstream
58+
echo "deb http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main $PG_MAJOR" > /etc/apt/sources.list.d/pgdg.list; \
59+
apt-get update; \
60+
;; \
61+
*) \
62+
# we're on an architecture upstream doesn't officially build for
63+
# let's build binaries from their published source packages
64+
echo "deb-src http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main $PG_MAJOR" > /etc/apt/sources.list.d/pgdg.list; \
65+
\
66+
tempDir="$(mktemp -d)"; \
67+
cd "$tempDir"; \
68+
\
69+
savedAptMark="$(apt-mark showmanual)"; \
70+
\
71+
# build .deb files from upstream's source packages (which are verified by apt-get)
72+
apt-get update; \
73+
apt-get build-dep -y \
74+
postgresql-common pgdg-keyring \
75+
"postgresql-$PG_MAJOR=$PG_VERSION" \
76+
; \
77+
DEB_BUILD_OPTIONS="nocheck parallel=$(nproc)" \
78+
apt-get source --compile \
79+
postgresql-common pgdg-keyring \
80+
"postgresql-$PG_MAJOR=$PG_VERSION" \
81+
; \
82+
# we don't remove APT lists here because they get re-downloaded and removed later
83+
\
84+
# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies
85+
# (which is done after we install the built packages so we don't have to redownload any overlapping dependencies)
86+
apt-mark showmanual | xargs apt-mark auto > /dev/null; \
87+
apt-mark manual $savedAptMark; \
88+
\
89+
# create a temporary local APT repo to install from (so that dependency resolution can be handled by APT, as it should be)
90+
ls -lAFh; \
91+
dpkg-scanpackages . > Packages; \
92+
grep '^Package: ' Packages; \
93+
echo "deb [ trusted=yes ] file://$tempDir ./" > /etc/apt/sources.list.d/temp.list; \
94+
# work around the following APT issue by using "Acquire::GzipIndexes=false" (overriding "/etc/apt/apt.conf.d/docker-gzip-indexes")
95+
# Could not open file /var/lib/apt/lists/partial/_tmp_tmp.ODWljpQfkE_._Packages - open (13: Permission denied)
96+
# ...
97+
# 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)
98+
apt-get -o Acquire::GzipIndexes=false update; \
99+
;; \
100+
esac; \
101+
\
102+
apt-get install -y postgresql-common; \
103+
sed -ri 's/#(create_main_cluster) .*$/\1 = false/' /etc/postgresql-common/createcluster.conf; \
104+
apt-get install -y \
105+
"postgresql-$PG_MAJOR=$PG_VERSION" \
106+
"postgresql-contrib-$PG_MAJOR=$PG_VERSION" \
107+
; \
108+
\
109+
rm -rf /var/lib/apt/lists/*; \
110+
\
111+
if [ -n "$tempDir" ]; then \
112+
# if we have leftovers from building, let's purge them (including extra, unnecessary build deps)
113+
apt-get purge -y --auto-remove; \
114+
rm -rf "$tempDir" /etc/apt/sources.list.d/temp.list; \
115+
fi
61116

62117
# make the sample config easier to munge (and "correct by default")
63-
RUN mv -v /usr/share/postgresql/$PG_MAJOR/postgresql.conf.sample /usr/share/postgresql/ \
64-
&& ln -sv ../postgresql.conf.sample /usr/share/postgresql/$PG_MAJOR/ \
118+
RUN mv -v "/usr/share/postgresql/$PG_MAJOR/postgresql.conf.sample" /usr/share/postgresql/ \
119+
&& ln -sv ../postgresql.conf.sample "/usr/share/postgresql/$PG_MAJOR/" \
65120
&& sed -ri "s!^#?(listen_addresses)\s*=\s*\S+.*!\1 = '*'!" /usr/share/postgresql/postgresql.conf.sample
66121

67122
RUN mkdir -p /var/run/postgresql && chown -R postgres:postgres /var/run/postgresql && chmod 2777 /var/run/postgresql

9.3/Dockerfile

+67-12
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ RUN set -ex; \
1515
RUN groupadd -r postgres --gid=999 && useradd -r -g postgres --uid=999 postgres
1616

1717
# grab gosu for easy step-down from root
18-
ENV GOSU_VERSION 1.7
18+
ENV GOSU_VERSION 1.10
1919
RUN set -x \
2020
&& apt-get update && apt-get install -y --no-install-recommends ca-certificates wget && rm -rf /var/lib/apt/lists/* \
2121
&& wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \
@@ -49,19 +49,74 @@ RUN set -ex; \
4949
ENV PG_MAJOR 9.3
5050
ENV PG_VERSION 9.3.18-1.pgdg80+1
5151

52-
RUN echo 'deb http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main' $PG_MAJOR > /etc/apt/sources.list.d/pgdg.list
53-
54-
RUN apt-get update \
55-
&& apt-get install -y postgresql-common \
56-
&& sed -ri 's/#(create_main_cluster) .*$/\1 = false/' /etc/postgresql-common/createcluster.conf \
57-
&& apt-get install -y \
58-
postgresql-$PG_MAJOR=$PG_VERSION \
59-
postgresql-contrib-$PG_MAJOR=$PG_VERSION \
60-
&& rm -rf /var/lib/apt/lists/*
52+
RUN set -ex; \
53+
\
54+
dpkgArch="$(dpkg --print-architecture)"; \
55+
case "$dpkgArch" in \
56+
amd64|i386|ppc64el) \
57+
# arches officialy built by upstream
58+
echo "deb http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main $PG_MAJOR" > /etc/apt/sources.list.d/pgdg.list; \
59+
apt-get update; \
60+
;; \
61+
*) \
62+
# we're on an architecture upstream doesn't officially build for
63+
# let's build binaries from their published source packages
64+
echo "deb-src http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main $PG_MAJOR" > /etc/apt/sources.list.d/pgdg.list; \
65+
\
66+
tempDir="$(mktemp -d)"; \
67+
cd "$tempDir"; \
68+
\
69+
savedAptMark="$(apt-mark showmanual)"; \
70+
\
71+
# build .deb files from upstream's source packages (which are verified by apt-get)
72+
apt-get update; \
73+
apt-get build-dep -y \
74+
postgresql-common pgdg-keyring \
75+
"postgresql-$PG_MAJOR=$PG_VERSION" \
76+
; \
77+
DEB_BUILD_OPTIONS="nocheck parallel=$(nproc)" \
78+
apt-get source --compile \
79+
postgresql-common pgdg-keyring \
80+
"postgresql-$PG_MAJOR=$PG_VERSION" \
81+
; \
82+
# we don't remove APT lists here because they get re-downloaded and removed later
83+
\
84+
# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies
85+
# (which is done after we install the built packages so we don't have to redownload any overlapping dependencies)
86+
apt-mark showmanual | xargs apt-mark auto > /dev/null; \
87+
apt-mark manual $savedAptMark; \
88+
\
89+
# create a temporary local APT repo to install from (so that dependency resolution can be handled by APT, as it should be)
90+
ls -lAFh; \
91+
dpkg-scanpackages . > Packages; \
92+
grep '^Package: ' Packages; \
93+
echo "deb [ trusted=yes ] file://$tempDir ./" > /etc/apt/sources.list.d/temp.list; \
94+
# work around the following APT issue by using "Acquire::GzipIndexes=false" (overriding "/etc/apt/apt.conf.d/docker-gzip-indexes")
95+
# Could not open file /var/lib/apt/lists/partial/_tmp_tmp.ODWljpQfkE_._Packages - open (13: Permission denied)
96+
# ...
97+
# 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)
98+
apt-get -o Acquire::GzipIndexes=false update; \
99+
;; \
100+
esac; \
101+
\
102+
apt-get install -y postgresql-common; \
103+
sed -ri 's/#(create_main_cluster) .*$/\1 = false/' /etc/postgresql-common/createcluster.conf; \
104+
apt-get install -y \
105+
"postgresql-$PG_MAJOR=$PG_VERSION" \
106+
"postgresql-contrib-$PG_MAJOR=$PG_VERSION" \
107+
; \
108+
\
109+
rm -rf /var/lib/apt/lists/*; \
110+
\
111+
if [ -n "$tempDir" ]; then \
112+
# if we have leftovers from building, let's purge them (including extra, unnecessary build deps)
113+
apt-get purge -y --auto-remove; \
114+
rm -rf "$tempDir" /etc/apt/sources.list.d/temp.list; \
115+
fi
61116

62117
# make the sample config easier to munge (and "correct by default")
63-
RUN mv -v /usr/share/postgresql/$PG_MAJOR/postgresql.conf.sample /usr/share/postgresql/ \
64-
&& ln -sv ../postgresql.conf.sample /usr/share/postgresql/$PG_MAJOR/ \
118+
RUN mv -v "/usr/share/postgresql/$PG_MAJOR/postgresql.conf.sample" /usr/share/postgresql/ \
119+
&& ln -sv ../postgresql.conf.sample "/usr/share/postgresql/$PG_MAJOR/" \
65120
&& sed -ri "s!^#?(listen_addresses)\s*=\s*\S+.*!\1 = '*'!" /usr/share/postgresql/postgresql.conf.sample
66121

67122
RUN mkdir -p /var/run/postgresql && chown -R postgres:postgres /var/run/postgresql && chmod 2777 /var/run/postgresql

0 commit comments

Comments
 (0)