Skip to content

Commit c1fb961

Browse files
Postgres 18 alpine
1 parent b1f35be commit c1fb961

3 files changed

Lines changed: 5 additions & 178 deletions

File tree

.github/workflows/build-and-push-images.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ jobs:
1515
strategy:
1616
matrix:
1717
include:
18-
- { postgres: '18.0', alpine: 'edge' }
18+
- { postgres: '17', alpine: '3.21' }
19+
- { postgres: '18', alpine: '3.22' }
1920

2021
steps:
2122
- name: Checkout repository

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
ARG ALPINE_VERSION='edge'
2-
FROM alpine:${ALPINE_VERSION}
1+
ARG ALPINE_VERSION='3.22'
2+
ARG PG_VERSION='18'
3+
FROM postgres:${PG_VERSION}-alpine${ALPINE_VERSION}
34
ARG TARGETARCH
4-
ARG PG_VERSION='18.0'
55
ENV PG_VERSION=$PG_VERSION
66
ADD src/install.sh install.sh
77
RUN sh install.sh && rm install.sh

src/install.sh

Lines changed: 0 additions & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -3,180 +3,6 @@
33
set -eux
44
set -o pipefail
55

6-
apk update
7-
set -eux; \
8-
addgroup -g 70 -S postgres; \
9-
adduser -u 70 -S -D -G postgres -H -h /var/lib/postgresql -s /bin/sh postgres; \
10-
# also create the postgres user's home directory with appropriate permissions
11-
# see https://github.com/docker-library/postgres/issues/274
12-
install --verbose --directory --owner postgres --group postgres --mode 1777 /var/lib/postgresql
13-
14-
# grab gosu for easy step-down from root
15-
# https://github.com/tianon/gosu/releases
16-
export GOSU_VERSION=1.19
17-
set -eux; \
18-
\
19-
apk add --no-cache --virtual .gosu-deps \
20-
ca-certificates \
21-
dpkg \
22-
gnupg \
23-
; \
24-
\
25-
dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \
26-
wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch"; \
27-
wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc"; \
28-
\
29-
# verify the signature
30-
export GNUPGHOME="$(mktemp -d)"; \
31-
gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \
32-
gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
33-
gpgconf --kill all; \
34-
rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \
35-
\
36-
# clean up fetch dependencies
37-
apk del --no-network .gosu-deps; \
38-
\
39-
chmod +x /usr/local/bin/gosu; \
40-
# verify that the binary works
41-
gosu --version; \
42-
gosu nobody true
43-
44-
# make the "en_US.UTF-8" locale so postgres will be utf-8 enabled by default
45-
# alpine doesn't require explicit locale-file generation
46-
export LANG=en_US.utf8
47-
48-
mkdir /docker-entrypoint-initdb.d
49-
50-
set -eux; \
51-
\
52-
wget -O postgresql.tar.bz2 "https://ftp.postgresql.org/pub/source/v$PG_VERSION/postgresql-$PG_VERSION.tar.bz2"; \
53-
mkdir -p /usr/src/postgresql; \
54-
tar \
55-
--extract \
56-
--file postgresql.tar.bz2 \
57-
--directory /usr/src/postgresql \
58-
--strip-components 1 \
59-
; \
60-
rm postgresql.tar.bz2; \
61-
\
62-
apk add --no-cache --virtual .build-deps \
63-
llvm19-dev \
64-
clang19 \
65-
bison \
66-
coreutils \
67-
dpkg-dev dpkg \
68-
flex \
69-
g++ \
70-
gcc \
71-
krb5-dev \
72-
libc-dev \
73-
libedit-dev \
74-
libxml2-dev \
75-
libxslt-dev \
76-
linux-headers \
77-
make \
78-
openldap-dev \
79-
openssl-dev \
80-
perl-dev \
81-
perl-ipc-run \
82-
perl-utils \
83-
python3-dev \
84-
tcl-dev \
85-
util-linux-dev \
86-
zlib-dev \
87-
icu-dev \
88-
lz4-dev \
89-
zstd-dev \
90-
liburing-dev \
91-
; \
92-
\
93-
cd /usr/src/postgresql; \
94-
# update "DEFAULT_PGSOCKET_DIR" to "/var/run/postgresql" (matching Debian)
95-
# see https://anonscm.debian.org/git/pkg-postgresql/postgresql.git/tree/debian/patches/51-default-sockets-in-var.patch?id=8b539fcb3e093a521c095e70bdfa76887217b89f
96-
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; \
97-
grep '/var/run/postgresql' src/include/pg_config_manual.h.new; \
98-
mv src/include/pg_config_manual.h.new src/include/pg_config_manual.h; \
99-
gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \
100-
\
101-
# https://git.alpinelinux.org/aports/tree/community/postgresql15/APKBUILD?h=3.22-stable#n176 ("export LLVM_CONFIG")
102-
export LLVM_CONFIG="/usr/lib/llvm19/bin/llvm-config"; \
103-
# https://git.alpinelinux.org/aports/tree/community/postgresql15/APKBUILD?h=3.22-stable#n180 ("older clang versions don't have a 'clang' exe anymore.")
104-
export CLANG=clang-19; \
105-
\
106-
# configure options mostly copying Debian:
107-
# https://salsa.debian.org/postgresql/postgresql-common/-/blob/6e26b5107295170cc8731a3acbf13228ea15941e/server/postgresql.mk#L32
108-
./configure \
109-
--enable-option-checking=fatal \
110-
--build="$gnuArch" \
111-
--enable-integer-datetimes \
112-
--enable-tap-tests \
113-
--disable-rpath \
114-
--with-uuid=e2fs \
115-
--with-pgport=5432 \
116-
--with-system-tzdata=/usr/share/zoneinfo \
117-
--prefix=/usr/local \
118-
--with-includes=/usr/local/include \
119-
--with-libraries=/usr/local/lib \
120-
--with-gssapi \
121-
--with-icu \
122-
--with-ldap \
123-
--with-liburing \
124-
--with-libxml \
125-
--with-libxslt \
126-
--with-llvm \
127-
--with-lz4 \
128-
--with-openssl \
129-
--with-perl \
130-
--with-python \
131-
--with-tcl \
132-
--with-zstd \
133-
; \
134-
make -j "$(nproc)" world-bin; \
135-
make install-world-bin; \
136-
make -C contrib install; \
137-
\
138-
runDeps="$( \
139-
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local \
140-
| tr ',' '\n' \
141-
| sort -u \
142-
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
143-
| grep -v -e perl -e python -e tcl \
144-
)"; \
145-
apk add --no-cache --virtual .postgresql-rundeps \
146-
$runDeps \
147-
bash \
148-
tzdata \
149-
zstd \
150-
icu-data-full \
151-
$([ "$(apk --print-arch)" != 'ppc64le' ] && echo 'nss_wrapper') \
152-
; \
153-
apk del --no-network .build-deps; \
154-
cd /; \
155-
rm -rf \
156-
/usr/src/postgresql \
157-
/usr/local/share/doc \
158-
/usr/local/share/man \
159-
; \
160-
\
161-
postgres --version
162-
163-
# make the sample config easier to munge (and "correct by default")
164-
set -eux; \
165-
cp -v /usr/local/share/postgresql/postgresql.conf.sample /usr/local/share/postgresql/postgresql.conf.sample.orig; \
166-
sed -ri "s!^#?(listen_addresses)\s*=\s*\S+.*!\1 = '*'!" /usr/local/share/postgresql/postgresql.conf.sample; \
167-
grep -F "listen_addresses = '*'" /usr/local/share/postgresql/postgresql.conf.sample
168-
169-
install --verbose --directory --owner postgres --group postgres --mode 3777 /var/run/postgresql
170-
171-
#
172-
# NOTE: in 18+, PGDATA has changed to match the pg_ctlcluster standard directory structure, and the VOLUME has moved from /var/lib/postgresql/data to /var/lib/postgresql
173-
#
174-
export PGDATA=/var/lib/postgresql/18/docker
175-
ln -svT . /var/lib/postgresql/data # https://github.com/docker-library/postgres/pull/1259#issuecomment-2215477494
176-
# ("/var/lib/postgresql" is already pre-created with suitably usable permissions above)
177-
178-
apk add aws-cli
179-
1806
# install go-cron
1817
apk add curl
1828
curl -L https://github.com/ivoronin/go-cron/releases/download/v0.0.5/go-cron_0.0.5_linux_${TARGETARCH}.tar.gz -O

0 commit comments

Comments
 (0)