-
-
Notifications
You must be signed in to change notification settings - Fork 160
/
Copy pathDockerfile
78 lines (61 loc) · 3.05 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
ARG ubuntu_release=focal
FROM ubuntu:${ubuntu_release} as base
ARG ubuntu_release=flocal
ARG ubuntu_release_no=20.04
ARG postgresql_major=15
ARG postgresql_release=${postgresql_major}.1
FROM base as pg-source
# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
gnupg \
dpkg-dev \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Add Postgres PPA
# In the off-chance that the key in the repository expires, it can be replaced by running the following in the repository's root:
# gpg --keyserver hkps://keyserver.ubuntu.com --recv-keys $NEW_POSTGRESQL_GPG_KEY
# gpg --export --armor $NEW_POSTGRESQL_GPG_KEY > postgresql.gpg.key
COPY postgresql.gpg.key /tmp/postgresql.gpg.key
RUN apt-key add /tmp/postgresql.gpg.key && \
echo "deb https://apt-archive.postgresql.org/pub/repos/apt ${ubuntu_release}-pgdg-archive main" > /etc/apt/sources.list.d/pgdg.list && \
echo "deb-src https://apt-archive.postgresql.org/pub/repos/apt ${ubuntu_release}-pgdg-archive main" > /etc/apt/sources.list.d/pgdg.list
# Create local PPA
WORKDIR /tmp/build
RUN echo "deb [ trusted=yes ] file:///tmp/build ./" > /etc/apt/sources.list.d/temp.list && \
dpkg-scanpackages . > Packages && \
apt-get -o Acquire::GzipIndexes=false update
ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONDONTWRITEBYTECODE=1
ENV DEB_BUILD_OPTIONS="nocheck parallel=$(nproc)"
# Configure processor optimised build
ARG CPPFLAGS=""
ENV DEB_CPPFLAGS_APPEND="${CPPFLAGS} -fsigned-char"
ENV DEB_CFLAGS_APPEND="-g3"
ARG DEB_BUILD_PROFILES="pkg.postgresql.nozstd"
ENV DEB_BUILD_PROFILES="${DEB_BUILD_PROFILES}"
RUN apt-get -o Acquire::GzipIndexes=false update && apt-get build-dep -y postgresql-common pgdg-keyring && \
apt-get source --compile postgresql-common pgdg-keyring && \
dpkg-scanpackages . > Packages && \
apt-get -o Acquire::GzipIndexes=false update
RUN apt-get build-dep -y "postgresql-${postgresql_major}=${postgresql_release}-1.pgdg${ubuntu_release_no}+1" && \
apt-get source --compile "postgresql-${postgresql_major}=${postgresql_release}-1.pgdg${ubuntu_release_no}+1" && \
dpkg-scanpackages . > Packages && \
apt-get -o Acquire::GzipIndexes=false update
# Remove source directories
RUN rm -rf /tmp/build/*/
FROM base as pg
# Inherit args from base stage
ARG postgresql_major
ARG postgresql_release
COPY --from=pg-source /tmp/build /tmp/build
ENV DEBIAN_FRONTEND=noninteractive
RUN echo "deb [ trusted=yes ] file:///tmp/build ./" > /etc/apt/sources.list.d/temp.list && \
apt-get -o Acquire::GzipIndexes=false update && \
apt-get install -y --no-install-recommends postgresql-common && \
sed -ri 's/#(create_main_cluster) .*$/\1 = false/' /etc/postgresql-common/createcluster.conf && \
apt-get install -y --no-install-recommends "postgresql-${postgresql_major}=${postgresql_release}-1.pgdg${ubuntu_release_no}+1" && \
rm -rf /var/lib/apt/lists/* && \
rm -rf /tmp/build /etc/apt/sources.list.d/temp.list
ENV PATH $PATH:/usr/lib/postgresql/${postgresql_major}/bin
FROM scratch as pg-deb
COPY --from=pg-source /tmp/build /tmp