|
| 1 | +# multi-stage builder |
| 2 | +FROM debian:{{ .debian }} AS builder |
| 3 | + |
| 4 | +RUN sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list; \ |
| 5 | + sed -i 's/security.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list; \ |
| 6 | + apt update; \ |
| 7 | + mkdir -p /usr/src/postgresql |
| 8 | + |
| 9 | +ADD postgresql /usr/src/postgresql/ |
| 10 | + |
| 11 | +RUN apt install -y --no-install-recommends \ |
| 12 | + git \ |
| 13 | + pax-utils \ |
| 14 | + gosu \ |
| 15 | + bison \ |
| 16 | + flex \ |
| 17 | + gcc \ |
| 18 | + g++ \ |
| 19 | + llvm-dev \ |
| 20 | + clang \ |
| 21 | + libicu-dev \ |
| 22 | + dpkg \ |
| 23 | + dpkg-dev \ |
| 24 | + pkg-config \ |
| 25 | + python3-dev \ |
| 26 | + libreadline-dev \ |
| 27 | + libldap2-dev \ |
| 28 | + libxml2-dev \ |
| 29 | + libgss-dev \ |
| 30 | + openssl \ |
| 31 | + libssl-dev \ |
| 32 | + libxslt-dev \ |
| 33 | + uuid-dev \ |
| 34 | + tcl-dev \ |
| 35 | +{{ if .major >= 14 then ( -}} |
| 36 | + liblz4-dev \ |
| 37 | +{{ ) else "" end -}} |
| 38 | + libperl-dev \ |
| 39 | + libkrb5-dev |
| 40 | +#{{ if env.arch == "aarch64" then ( -}} |
| 41 | +# "" |
| 42 | +#{{ ) else "" end -}} |
| 43 | + |
| 44 | +RUN cd /usr/src/postgresql; \ |
| 45 | +# git reset --hard; \ |
| 46 | + git checkout {{ .tag }}; \ |
| 47 | +# git clean -fqdx; \ |
| 48 | + 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; \ |
| 49 | + grep '/var/run/postgresql' src/include/pg_config_manual.h.new; \ |
| 50 | + mv src/include/pg_config_manual.h.new src/include/pg_config_manual.h; \ |
| 51 | + ./configure \ |
| 52 | + --prefix=/var/lib/postgresql/ \ |
| 53 | + --with-icu \ |
| 54 | + --with-tcl \ |
| 55 | + --with-perl \ |
| 56 | + --with-python \ |
| 57 | + --with-gssapi \ |
| 58 | + --with-ldap \ |
| 59 | + --with-openssl \ |
| 60 | + --with-libxml \ |
| 61 | + --with-libxslt \ |
| 62 | + --with-readline \ |
| 63 | + --with-uuid=e2fs \ |
| 64 | + --with-llvm \ |
| 65 | + --with-libraries=/usr/local/lib \ |
| 66 | + --with-krb5 \ |
| 67 | +{{ if .major >= 14 then ( -}} |
| 68 | + --with-lz4 \ |
| 69 | +{{ ) else "" end -}} |
| 70 | + >/dev/null; \ |
| 71 | + make -j `expr $(nproc) - 2` >/dev/null; \ |
| 72 | + make install; \ |
| 73 | + make -C contrib install; |
| 74 | + |
| 75 | +ADD pg_auto_failover /usr/src/pg_auto_failover |
| 76 | +RUN cd /usr/src/pg_auto_failover; \ |
| 77 | + git checkout {{ .failover }}; \ |
| 78 | + make PG_CONFIG=/var/lib/postgresql/bin/pg_config -j `expr $(nproc) - 2` >/dev/null; \ |
| 79 | + make install PG_CONFIG=/var/lib/postgresql/bin/pg_config; |
| 80 | + |
| 81 | +RUN cd /var/lib/postgresql; \ |
| 82 | + tar czhvf lib.tar.gz `find . -type f | xargs ldd 2>/dev/null | grep "=>" | cut -d ">" -f 2 | cut -d "(" -f 1 | sort -u` |
| 83 | + |
| 84 | +# real image |
| 85 | +FROM debian:{{ .debian }} |
| 86 | + |
| 87 | +ENV LANG en_US.utf8 |
| 88 | +ENV DATA /var/lib/postgresql/data |
| 89 | +ENV XDG_CONFIG_HOME /var/lib/postgresql/data/auto_failover |
| 90 | +ENV XDG_DATA_HOME /var/lib/postgresql/data/auto_failover |
| 91 | +ENV ASSIST /var/lib/postgresql/data/assist |
| 92 | +ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/var/lib/postgresql/bin |
| 93 | +ENV PGHOME /var/lib/postgresql |
| 94 | +VOLUME /var/lib/postgresql/data |
| 95 | + |
| 96 | +COPY --from=builder /var/lib/postgresql/ /var/lib/postgresql |
| 97 | +COPY docker-entrypoint.sh /usr/local/bin/ |
| 98 | +COPY pgtools /usr/local/bin/ |
| 99 | + |
| 100 | +RUN set -eux; \ |
| 101 | + groupadd -r postgres --gid=999; \ |
| 102 | + useradd -r -g postgres --uid=999 --home-dir=/var/lib/postgresql --shell=/bin/bash postgres; \ |
| 103 | + echo 'export PATH=$PATH:/var/lib/postgresql/bin' >> /etc/profile; \ |
| 104 | + tar --skip-old-files -xzf /var/lib/postgresql/lib.tar.gz -C /; \ |
| 105 | + rm -rf /var/lib/postgresql/lib.tar.gz; \ |
| 106 | + mkdir -p "$DATA" && mkdir -p "$ASSIST" && chown -R postgres:postgres /var/lib/postgresql && chmod 777 "$DATA"; \ |
| 107 | + mkdir -p /var/run/postgresql && chown -R postgres:postgres /var/run/postgresql && chmod 775 /var/run/postgresql ; \ |
| 108 | + sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list; \ |
| 109 | + sed -i 's/security.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list; \ |
| 110 | + apt update; \ |
| 111 | + apt install -y --no-install-recommends vim sysstat inetutils-ping procps net-tools ssh sshpass ; \ |
| 112 | + apt install -y --no-install-recommends gosu locales ; \ |
| 113 | + localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 ; \ |
| 114 | + apt-get clean; \ |
| 115 | + rm -rf /var/lib/apt/lists/*; \ |
| 116 | + apt-get purge -y --auto-remove ; \ |
| 117 | + echo "* soft nofile 1024000" >> /etc/security/limits.conf; \ |
| 118 | + echo "* hard nofile 1024000" >> /etc/security/limits.conf; \ |
| 119 | + echo "* soft nproc unlimited" >> /etc/security/limits.conf; \ |
| 120 | + echo "* hard nproc unlimited" >> /etc/security/limits.conf; \ |
| 121 | + echo "* soft core unlimited" >> /etc/security/limits.conf; \ |
| 122 | + echo "* hard core unlimited" >> /etc/security/limits.conf; \ |
| 123 | + echo "* soft memlock unlimited" >> /etc/security/limits.conf; \ |
| 124 | + echo "* hard memlock unlimited" >> /etc/security/limits.conf; \ |
| 125 | + /var/lib/postgresql/bin/postgres --version |
| 126 | + |
| 127 | +ENTRYPOINT ["docker-entrypoint.sh"] |
| 128 | +STOPSIGNAL SIGINT |
| 129 | +EXPOSE 5432 |
| 130 | +CMD ["postgres"] |
0 commit comments