forked from pgautoupgrade/docker-pgautoupgrade
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
127 lines (110 loc) · 5.71 KB
/
Dockerfile
File metadata and controls
127 lines (110 loc) · 5.71 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# The version of PostgreSQL this container migrates data to
ARG PGTARGET=16
# We use Alpine as a base image to compile older
# PostgreSQL versions in, then copy the binaries
# into the PG 15 Alpine image
FROM alpine:3.18 AS build
# We need to define this here, to make the above PGTARGET available after the FROM
ARG PGTARGET
# Where we'll do all our compiling and similar
ENV BUILD_ROOT /buildroot
# Make the directory for building, and set it as the default for the following Docker commands
RUN mkdir ${BUILD_ROOT}
WORKDIR ${BUILD_ROOT}
# Download the source code for previous PG releases
RUN wget https://ftp.postgresql.org/pub/source/v9.5.25/postgresql-9.5.25.tar.bz2 && \
wget https://ftp.postgresql.org/pub/source/v9.6.24/postgresql-9.6.24.tar.bz2 && \
wget https://ftp.postgresql.org/pub/source/v10.23/postgresql-10.23.tar.bz2 && \
wget https://ftp.postgresql.org/pub/source/v11.22/postgresql-11.22.tar.bz2 && \
wget https://ftp.postgresql.org/pub/source/v12.17/postgresql-12.17.tar.bz2
RUN if [ "${PGTARGET}" -gt 13 ]; then wget https://ftp.postgresql.org/pub/source/v13.13/postgresql-13.13.tar.bz2; fi
RUN if [ "${PGTARGET}" -gt 14 ]; then wget https://ftp.postgresql.org/pub/source/v14.10/postgresql-14.10.tar.bz2; fi
RUN if [ "${PGTARGET}" -gt 15 ]; then wget https://ftp.postgresql.org/pub/source/v15.5/postgresql-15.5.tar.bz2; fi
# Extract the source code
RUN tar -xf postgresql-9.5*.tar.bz2 && \
tar -xf postgresql-9.6*.tar.bz2 && \
tar -xf postgresql-10*.tar.bz2 && \
tar -xf postgresql-11*.tar.bz2 && \
tar -xf postgresql-12*.tar.bz2
RUN if [ "${PGTARGET}" -gt 13 ]; then tar -xf postgresql-13*.tar.bz2; fi
RUN if [ "${PGTARGET}" -gt 14 ]; then tar -xf postgresql-14*.tar.bz2; fi
RUN if [ "${PGTARGET}" -gt 15 ]; then tar -xf postgresql-15*.tar.bz2; fi
# Install things needed for development
# We might want to install "alpine-sdk" instead of "build-base", if build-base
# doesn't have everything we need
RUN apk update && \
apk upgrade && \
apk add --update build-base icu-data-full icu-dev linux-headers lz4-dev musl musl-locales musl-utils tzdata zlib-dev && \
apk cache clean
# Compile PG releases with fairly minimal options
# Note that given some time, we could likely remove the pieces of the older PG installs which aren't needed by pg_upgrade
RUN cd postgresql-9.5.* && \
./configure --prefix=/usr/local-pg9.5 --with-openssl=no --without-readline --enable-debug=no CFLAGS="-Os" && \
make -j12 && \
make install && \
rm -rf /usr/local-pg9.5/include
RUN cd postgresql-9.6.* && \
./configure --prefix=/usr/local-pg9.6 --with-openssl=no --without-readline --enable-debug=no CFLAGS="-Os" && \
make -j12 && \
make install && \
rm -rf /usr/local-pg9.6/include
RUN cd postgresql-10.* && \
./configure --prefix=/usr/local-pg10 --with-openssl=no --without-readline --with-icu --enable-debug=no CFLAGS="-Os" && \
make -j12 && \
make install && \
rm -rf /usr/local-pg10/include
RUN cd postgresql-11.* && \
./configure --prefix=/usr/local-pg11 --with-openssl=no --without-readline --with-icu --enable-debug=no CFLAGS="-Os" && \
make -j12 && \
make install && \
rm -rf /usr/local-pg11/include
RUN cd postgresql-12.* && \
./configure --prefix=/usr/local-pg12 --with-openssl=no --without-readline --with-icu --enable-debug=no CFLAGS="-Os" && \
make -j12 && \
make install && \
rm -rf /usr/local-pg12/include
RUN if [ "${PGTARGET}" -gt 13 ]; then cd postgresql-13.* && \
./configure --prefix=/usr/local-pg13 --with-openssl=no --without-readline --with-icu --enable-debug=no CFLAGS="-Os" && \
make -j12 && \
make install && \
rm -rf /usr/local-pg13/include; else mkdir /usr/local-pg13; fi
RUN if [ "${PGTARGET}" -gt 14 ]; then cd postgresql-14.* && \
./configure --prefix=/usr/local-pg14 --with-openssl=no --without-readline --with-icu --with-lz4 --enable-debug=no CFLAGS="-Os" && \
make -j12 && \
make install && \
rm -rf /usr/local-pg14/include; else mkdir /usr/local-pg14; fi
RUN if [ "${PGTARGET}" -gt 15 ]; then cd postgresql-15.* && \
./configure --prefix=/usr/local-pg15 --with-openssl=no --without-readline --with-icu --with-lz4 --enable-debug=no CFLAGS="-Os" && \
make -j12 && \
make install && \
rm -rf /usr/local-pg15/include; else mkdir /usr/local-pg15; fi
# Use the PostgreSQL Alpine image as our output image base
FROM postgres:${PGTARGET}-alpine3.18
# We need to define this here, to make the above PGTARGET available after the FROM
ARG PGTARGET
# Copy across our compiled files
COPY --from=build /usr/local-pg9.5 /usr/local-pg9.5
COPY --from=build /usr/local-pg9.6 /usr/local-pg9.6
COPY --from=build /usr/local-pg10 /usr/local-pg10
COPY --from=build /usr/local-pg11 /usr/local-pg11
COPY --from=build /usr/local-pg12 /usr/local-pg12
COPY --from=build /usr/local-pg13 /usr/local-pg13
COPY --from=build /usr/local-pg14 /usr/local-pg14
COPY --from=build /usr/local-pg15 /usr/local-pg15
# Remove any left over PG directory stubs. Doesn't help with image size, just with clarity on what's in the image.
RUN if [ "${PGTARGET}" -eq 13 ]; then rmdir /usr/local-pg13 /usr/local-pg14 /usr/local-pg15; fi
RUN if [ "${PGTARGET}" -eq 14 ]; then rmdir /usr/local-pg14 /usr/local-pg15; fi
RUN if [ "${PGTARGET}" -eq 15 ]; then rmdir /usr/local-pg15; fi
# Install locale
RUN apk update && \
apk add --update icu-data-full musl musl-utils musl-locales tzdata && \
apk cache clean
## FIXME: Only useful while developing this Dockerfile
##RUN apk add man-db man-pages-posix
# Pass the PG build target through to the running image
ENV PGTARGET=${PGTARGET}
# Set up the script run by the container when it starts
WORKDIR /var/lib/postgresql
COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
CMD ["postgres"]