-
Notifications
You must be signed in to change notification settings - Fork 115
/
Dockerfile
199 lines (164 loc) · 5.32 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
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
#
# Using --build-arg PGVERSION=11 we can build pg_auto_failover for any
# target version of Postgres. In the Makefile, we use that to our advantage
# and tag test images such as pg_auto_failover_test:pg14.
#
ARG PGVERSION=14
#
# Define a base image with all our build dependencies.
#
# This base image contains all our target Postgres versions.
#
FROM debian:bullseye-slim as base
ARG PGVERSION
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
build-essential \
ca-certificates \
curl \
gnupg \
git \
gawk \
flex \
bison \
iproute2 \
libcurl4-gnutls-dev \
libicu-dev \
libncurses-dev \
libxml2-dev \
zlib1g-dev \
libedit-dev \
libkrb5-dev \
liblz4-dev \
libncurses6 \
libpam-dev \
libreadline-dev \
libselinux1-dev \
libssl-dev \
libxslt1-dev \
libzstd-dev \
uuid-dev \
make \
autoconf \
openssl \
pipenv \
python3-nose \
python3 \
python3-setuptools \
python3-psycopg2 \
python3-pip \
sudo \
tmux \
watch \
lsof \
psutils \
psmisc \
htop \
less \
mg \
valgrind \
postgresql-common \
&& rm -rf /var/lib/apt/lists/*
RUN curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
RUN echo "deb http://apt.postgresql.org/pub/repos/apt bullseye-pgdg main ${PGVERSION}" > /etc/apt/sources.list.d/pgdg.list
# bypass initdb of a "main" cluster
RUN echo 'create_main_cluster = false' | sudo tee -a /etc/postgresql-common/createcluster.conf
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
postgresql-server-dev-${PGVERSION} \
postgresql-${PGVERSION} \
&& rm -rf /var/lib/apt/lists/*
RUN pip3 install pyroute2>=0.5.17
RUN adduser --disabled-password --gecos '' docker
RUN adduser docker sudo
RUN adduser docker postgres
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
FROM base as citus
ARG PGVERSION
ARG CITUSTAG=v11.1.2
ENV PG_CONFIG /usr/lib/postgresql/${PGVERSION}/bin/pg_config
RUN git clone -b ${CITUSTAG} --depth 1 https://github.com/citusdata/citus.git /usr/src/citus
WORKDIR /usr/src/citus
RUN ./configure
RUN make -s clean && make -s -j8 install
#
# On-top of the base build-dependencies image, now we can build
# pg_auto_failover for a given --build-arg PGVERSION target version of
# Postgres.
#
FROM citus as build
ARG PGVERSION
ENV PG_CONFIG /usr/lib/postgresql/${PGVERSION}/bin/pg_config
WORKDIR /usr/src/pg_auto_failover
COPY Makefile ./
COPY Makefile.azure ./
COPY Makefile.citus ./
COPY ./src/ ./src
COPY ./src/bin/pg_autoctl/git-version.h ./src/bin/pg_autoctl/git-version.h
RUN make -s clean && make -s install -j8
#
# Given the build image above, we can now run our test suite targetting a
# given version of Postgres.
#
FROM build as test
ARG PGVERSION
COPY ./tests/ ./tests
COPY ./valgrind ./valgrind
RUN chmod a+w ./valgrind
USER docker
ENV PG_AUTOCTL_DEBUG 1
ENV PATH /usr/lib/postgresql/${PGVERSION}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
#
# And finally our "run" images with the bare minimum for run-time.
#
FROM debian:bullseye-slim as run
ARG PGVERSION
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
ca-certificates \
curl \
gnupg \
make \
sudo \
tmux \
watch \
libncurses6 \
lsof \
psutils \
dnsutils \
bind9-host \
libcurl4-gnutls-dev \
libzstd-dev \
postgresql-common \
libpq-dev \
&& rm -rf /var/lib/apt/lists/*
RUN curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
RUN echo "deb http://apt.postgresql.org/pub/repos/apt bullseye-pgdg main ${PGVERSION}" > /etc/apt/sources.list.d/pgdg.list
# bypass initdb of a "main" cluster
RUN echo 'create_main_cluster = false' | sudo tee -a /etc/postgresql-common/createcluster.conf
RUN apt-get update\
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends postgresql-${PGVERSION} \
&& rm -rf /var/lib/apt/lists/*
RUN adduser --disabled-password --gecos '' --home /var/lib/postgres docker
RUN adduser docker sudo
RUN adduser docker postgres
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
COPY --from=build /usr/lib/postgresql/${PGVERSION}/lib/citus*.so /usr/lib/postgresql/${PGVERSION}/lib
COPY --from=build /usr/share/postgresql/${PGVERSION}/extension/citus* /usr/share/postgresql/${PGVERSION}/extension/
COPY --from=build /usr/lib/postgresql/${PGVERSION}/lib/pgautofailover.so /usr/lib/postgresql/${PGVERSION}/lib
COPY --from=build /usr/share/postgresql/${PGVERSION}/extension/pgautofailover* /usr/share/postgresql/${PGVERSION}/extension/
COPY --from=build /usr/lib/postgresql/${PGVERSION}/bin/pg_autoctl /usr/local/bin
#
# In tests/upgrade/docker-compose.yml we use internal docker volumes in
# order to be able to restart the nodes and keep the data around. For that
# to work, we must prepare a mount-point that is owned by our target user
# (docker), so that once the volume in mounted there by docker compose,
# pg_autoctl has the necessary set of privileges.
#
RUN mkdir -p /var/lib/postgres \
&& chown -R docker /var/lib/postgres
USER docker
ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/postgresql/${PGVERSION}/bin
ENV PG_AUTOCTL_DEBUG 1
ENV PGDATA /var/lib/postgres/pgaf
CMD pg_autoctl do tmux session --nodes 3 --binpath /usr/local/bin/pg_autoctl