-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathDockerfile
More file actions
253 lines (236 loc) · 7.44 KB
/
Dockerfile
File metadata and controls
253 lines (236 loc) · 7.44 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
ARG PG_VERSION
ARG PREV_IMAGE
ARG TS_VERSION
############################
# Build tools binaries in separate image
############################
ARG GO_VERSION=1.19.1
FROM golang:${GO_VERSION}-alpine AS tools
ENV TOOLS_VERSION 0.8.1
RUN apk update && apk add --no-cache git gcc \
&& go install github.com/timescale/timescaledb-tune/cmd/timescaledb-tune@latest \
&& go install github.com/timescale/timescaledb-parallel-copy/cmd/timescaledb-parallel-copy@latest
############################
# Grab old versions from previous version
############################
ARG PG_VERSION
ARG PREV_IMAGE
FROM ${PREV_IMAGE} AS oldversions
# Remove update files, mock files, and all but the last 5 .so/.sql files.
# There are three types of SQL files, initialization, upgrade, and downgrade,
# which we have to count separately, but it's hard to match with globs, and
# there are also many upgrade/downgrade files per version, so just keep more of
# them.
USER 0
# Docker COPY needs at least one file to copy. If no source is specified, the
# command fails. Create two '.emptyfile' files here to prevent the
# 'COPY --from=oldversions' command below from failing. The files are removed
# after the copy operation is performed.
#
# When the first image for a PG version is created, PREV_IMAGE is set to the
# bitnami upstream image. Therefore, no TimescaleDB files exist and the
# copy commands would fail.
RUN set +o pipefail \
&& rm -vf $(pg_config --sharedir)/extension/timescaledb*mock*.sql \
&& rm -vf $(ls -1tr $(pg_config --pkglibdir)/timescaledb-tsl-*.so | head -n -5) \
&& rm -vf $(ls -1tr $(pg_config --pkglibdir)/timescaledb-[0-9]*.so | head -n -5) \
&& rm -vf $(ls -1tr $(pg_config --sharedir)/extension/timescaledb--*.sql | head -n -20) \
&& { ls $(pg_config --sharedir)/extension/timescaledb--*.sql \
; ls $(pg_config --pkglibdir)/timescaledb-*.so \
; : ; } \
&& touch $(pg_config --sharedir)/extension/.emptyfile \
&& touch $(pg_config --pkglibdir)/.emptyfile
############################
# Now build image and copy in tools
############################
ARG PG_VERSION
FROM bitnami/postgresql:${PG_VERSION}
ARG PG_VERSION
LABEL maintainer="Timescale https://www.timescale.com"
COPY docker-entrypoint-initdb.d/* /docker-entrypoint-initdb.d/
COPY --from=tools /go/bin/* /usr/local/bin/
COPY --from=oldversions /opt/bitnami/postgresql/lib/.emptyfile /opt/bitnami/postgresql/lib/timescaledb-*.so /opt/bitnami/postgresql/lib/
COPY --from=oldversions /opt/bitnami/postgresql/share/extension/.emptyfile /opt/bitnami/postgresql/share/extension/timescaledb--*.sql /opt/bitnami/postgresql/share/extension/
COPY bitnami/timescaledb-bitnami-entrypoint.sh /opt/bitnami/scripts/postgresql/
USER 0
ARG TS_VERSION
RUN set -ex \
&& rm -v /opt/bitnami/postgresql/lib/.emptyfile \
&& rm -v /opt/bitnami/postgresql/share/extension/.emptyfile \
&& mkdir -p /var/lib/apt/lists/partial \
&& apt-get update \
&& apt-get -y install \
\
build-essential \
libssl-dev \
git \
\
dpkg-dev \
gcc \
libc-dev \
make \
cmake \
wget \
&& mkdir -p /build/ \
&& git clone https://github.com/timescale/timescaledb /build/timescaledb \
\
# Build current version \
&& cd /build/timescaledb && rm -fr build \
&& git checkout ${TS_VERSION} \
&& ./bootstrap -DCMAKE_BUILD_TYPE=RelWithDebInfo -DREGRESS_CHECKS=OFF -DTAP_CHECKS=OFF -DGENERATE_DOWNGRADE_SCRIPT=ON -DWARNINGS_AS_ERRORS=OFF -DPROJECT_INSTALL_METHOD="docker-bitnami" \
&& cd build && make install \
&& cd ~ \
\
&& apt-get autoremove --purge -y \
\
build-essential \
libssl-dev \
\
dpkg-dev \
gcc \
libc-dev \
make \
cmake \
&& apt-get clean -y \
&& rm -rf \
/build \
"${HOME}/.cache" \
/var/lib/apt/lists/* \
/tmp/* \
/var/tmp/*
# Adding pg_cron
ARG PG_CRON_VERSION
RUN set -e \
&& cd /tmp\
&& apt-get update \
&& apt-get install -y \
ca-certificates \
openssl \
tar \
autoconf \
automake \
g++ \
clang \
llvm \
libtool \
libxml2-dev \
make \
perl \
wget \
&& wget -O pg_cron.tar.gz "https://github.com/citusdata/pg_cron/archive/refs/tags/$PG_CRON_VERSION.tar.gz" \
&& mkdir -p /tmp/pg_cron \
&& tar \
--extract \
--file pg_cron.tar.gz \
--directory /tmp/pg_cron \
--strip-components 1 \
&& cd /tmp/pg_cron \
&& make \
&& make install \
# clean
&& cd / \
&& rm /tmp/pg_cron.tar.gz \
&& rm -rf /tmp/pg_cron \
&& apt-get autoremove --purge -y \
autoconf \
automake \
g++ \
clang \
llvm \
make \
perl \
wget \
&& apt-get clean -y \
&& rm -rf \
/var/lib/apt/lists/* \
/tmp/* \
/var/tmp/*
# Add PostGIS Extension
ARG POSTGIS_VERSION
RUN set -eux \
&& apt update \
&& apt install -y \
ca-certificates \
openssl \
tar \
wget \
gettext \
automake \
libltdl-dev \
libxml2-dev \
libgeos-dev \
libproj-dev \
libprotobuf-c-dev \
protobuf-c-compiler \
g++\
gcc \
make \
&& wget -O postgis.tar.gz "https://github.com/postgis/postgis/archive/${POSTGIS_VERSION}.tar.gz" \
&& mkdir -p /usr/src/postgis \
&& tar \
--extract \
--file postgis.tar.gz \
--directory /usr/src/postgis \
--strip-components 1 \
&& rm postgis.tar.gz \
\
# build PostGIS
\
&& cd /usr/src/postgis \
&& gettextize \
&& ./autogen.sh \
&& ./configure \
--with-pcredir="$(pcre-config --prefix)" --with-geosconfig="/usr/bin/geos-config"\
&& make -j$(nproc) \
&& make install \
&& cd / \
# clean
&& apt-get autoremove --purge -y \
wget \
g++\
gcc \
make \
&& apt-get clean -y \
&& rm -rf \
/var/lib/apt/lists/* \
/tmp/* \
/var/tmp/*
ARG PLV8_VERSION
RUN buildDependencies="build-essential \
ca-certificates \
curl \
git-core \
gpp \
cpp \
gnupg dirmngr \
pkg-config \
apt-transport-https \
cmake \
libc++-dev \
libncurses5 \
libc++abi-dev \
libstdc++-12-dev \
wget \
zlib1g-dev \
postgresql-server-dev-15 \
libtinfo5" \
runtimeDependencies="libc++1" \
&& set -ex \
&& apt-get update && apt-get install -y --no-install-recommends ${buildDependencies} ${runtimeDependencies} \
&& mkdir -p /tmp/build \
&& curl -o /tmp/build/v$PLV8_VERSION.tar.gz -SL "https://github.com/plv8/plv8/archive/refs/tags/v${PLV8_VERSION}.tar.gz" \
&& cd /tmp/build \
&& tar -xzf /tmp/build/v$PLV8_VERSION.tar.gz -C /tmp/build/ \
&& cd /tmp/build/plv8-$PLV8_VERSION \
&& git clone --depth 1 https://github.com/bnoordhuis/v8-cmake.git ./deps/v8-cmake \
&& git init \
&& make \
&& make install \
&& strip /opt/bitnami/postgresql/lib/plv8-${PLV8_VERSION}.so \
&& apt-get clean \
&& apt-get remove -y ${buildDependencies} \
&& apt-get autoremove -y \
&& rm -rf tmp/build /var/lib/apt/lists/*
USER 1001
ENTRYPOINT [ "/opt/bitnami/scripts/postgresql/timescaledb-bitnami-entrypoint.sh" ]
CMD [ "/opt/bitnami/scripts/postgresql/run.sh" ]