10000 Revert "chore: remove pgbouncer from docker aio image [GEN-8039]" (#912) · cepro/postgres@794eed7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 794eed7

Browse files
bmpandradedarora
andauthored
Revert "chore: remove pgbouncer from docker aio image [GEN-8039]" (supabase#912)
* Revert "chore: remove pgbouncer from docker aio image (supabase#907)" This reverts commit d0bca07. * fix: bump version to 15.1.1.27 as .26 was disabled due to Fly issues with docker aio * Update common.vars.pkr.hcl --------- Co-authored-by: Div Arora <darora@users.noreply.github.com>
1 parent f6426cc commit 794eed7

File tree

21 files changed

+547
-28
lines changed

21 files changed

+547
-28
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,7 @@ RUN sed -i \
927927

928928
# Include schema migrations
929929
COPY migrations/db /docker-entrypoint-initdb.d/
930+
COPY ansible/files/pgbouncer_config/pgbouncer_auth_schema.sql /docker-entrypoint-initdb.d/init-scripts/00-schema.sql
930931
COPY ansible/files/stat_extension.sql /docker-entrypoint-initdb.d/migrations/00-extension.sql
931932

932933
# Add upstream entrypoint script

common.vars.pkr.hcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
postgres-version = "15.1.1.27"
1+
postgres-version = "15.1.1.28"

docker/all-in-one/Dockerfile

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
ARG postgres_version=15.1.1.24
22

3+
ARG pgbouncer_release=1.18.0
34
ARG postgrest_release=10.1.2
45
ARG gotrue_release=2.130.0
56
ARG adminapi_release=0.62.0
@@ -25,6 +26,33 @@ RUN apt-get update && apt-get install -y \
2526
cmake \
2627
&& rm -rf /var/lib/apt/lists/*
2728

29+
####################
30+
# Install pgbouncer
31+
####################
32+
FROM builder as pgbouncer-source
33+
# Download and extract
34+
ARG pgbouncer_release
35+
ADD "https://www.pgbouncer.org/downloads/files/${pgbouncer_release}/pgbouncer-${pgbouncer_release}.tar.gz" /tmp/pgbouncer.tar.gz
36+
RUN tar -xvf /tmp/pgbouncer.tar.gz -C /tmp && \
37+
rm -rf /tmp/pgbouncer.tar.gz
38+
# Install build dependencies
39+
RUN apt-get update && apt-get install -y \
40+
libevent-dev \
41+
&& rm -rf /var/lib/apt/lists/*
42+
# Build from source
43+
WORKDIR /tmp/pgbouncer-${pgbouncer_release}
44+
RUN ./configure --prefix=/usr/local
45+
RUN make -j$(nproc)
46+
# Create debian package
47+
RUN checkinstall -D --install=no --fstrans=no --backup=no --pakdir=/tmp --requires=libevent-2.1-7 --nodoc
48+
49+
FROM base as pgbouncer
50+
# Download pre-built packages
51+
RUN apt-get update && apt-get install -y --no-install-recommends --download-only \
52+
pgbouncer \
53+
&& rm -rf /var/lib/apt/lists/*
54+
RUN mv /var/cache/apt/archives/*.deb /tmp/
55+
2856
####################
2957
# Install PostgREST
3058
####################
@@ -98,6 +126,7 @@ RUN mv /var/cache/apt/archives/*.deb /tmp/
98126
FROM base as production
99127

100128
# Copy dependencies from previous build stages
129+
COPY --from=pgbouncer /tmp/*.deb /tmp/
101130
COPY --from=vector /tmp/*.deb /tmp/
102131
COPY --from=kong /tmp/*.deb /tmp/
103132
COPY --from=supervisor /tmp/*.deb /tmp/
@@ -148,6 +177,11 @@ COPY docker/all-in-one/etc/sudoers.d /etc/sudoers.d/
148177
# Script for pg_egress_collect
149178
COPY --chown=adminapi:adminapi docker/all-in-one/opt/pg_egress_collect /opt/pg_egress_collect
150179

180+
# Customizations for pgbouncer
181+
COPY docker/all-in-one/etc/pgbouncer /etc/pgbouncer
182+
COPY docker/all-in-one/etc/pgbouncer-custom /etc/pgbouncer-custom
183+
COPY docker/all-in-one/etc/tmpfiles.d /etc/tmpfiles.d
184+
151185
# Customizations for postgres
152186
COPY --chown=postgres:postgres docker/all-in-one/etc/postgresql/pg_hba.conf /etc/postgresql/
153187
COPY --chown=postgres:postgres docker/all-in-one/etc/postgresql/logging.conf /etc/postgresql/
@@ -216,6 +250,9 @@ ENV ADMIN_API_CERT_DIR=/etc/ssl/adminapi
216250
ENV ADMIN_API_PORT=8085
217251
EXPOSE ${ADMIN_API_PORT}
218252

253+
ENV PGBOUNCER_PORT=6543
254+
EXPOSE ${PGBOUNCER_PORT}
255+
219256
ENV PGEXPORTER_PORT=9187
220257
EXPOSE ${PGEXPORTER_PORT}
221258

@@ -225,7 +262,8 @@ ENV VECTOR_API_PORT=9001
225262
RUN useradd --create-home --shell /bin/bash postgrest && \
226263
useradd --create-home --shell /bin/bash gotrue && \
227264
useradd --create-home --shell /bin/bash envoy && \
228-
useradd --create-home --shell /bin/bash adminapi -G root,envoy,kong,postgres,postgrest,wal-g && \
265+
useradd --create-home --shell /bin/bash pgbouncer -G postgres,ssl-cert && \
266+
useradd --create-home --shell /bin/bash adminapi -G root,envoy,kong,pgbouncer,postgres,postgrest,wal-g && \
229267
usermod --append --shell /bin/bash -G postgres vector
230268
RUN mkdir -p /etc/wal-g && \
231269
chown -R adminapi:adminapi /etc/wal-g && \

docker/all-in-one/entrypoint.sh

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,6 @@ function disable_fail2ban {
8484
sed -i "s/autorestart=.*/autorestart=false/" /etc/supervisor/services/fail2ban.conf
8585
}
8686

87-
function disable_gotrue {
88-
sed -i "s/autostart=.*/autostart=false/" /etc/supervisor/services/gotrue.conf
89-
sed -i "s/autorestart=.*/autorestart=false/" /etc/supervisor/services/gotrue.conf
90-
}
91-
92-
function replace_kong_envoy {
93-
sed -i "s/autostart=.*/autostart=true/" /etc/supervisor/services/envoy.conf
94-
sed -i "s/autostart=.*/autostart=false/" /etc/supervisor/services/kong.conf
95-
sed -i "s/kong/envoy/" /etc/supervisor/services/group.conf
96-
}
97-
9887
function setup_postgres {
9988
tar -xzvf "$INIT_PAYLOAD_PATH" -C / ./etc/postgresql.schema.sql
10089
mv /etc/postgresql.schema.sql /docker-entrypoint-initdb.d/migrations/99-schema.sql
@@ -285,18 +274,19 @@ if [ "${AUTOSHUTDOWN_ENABLED:-}" == "true" ]; then
285274
enable_autoshutdown
286275
fi
287276

288-
289277
if [ "${ENVOY_ENABLED:-}" == "true" ]; then
290-
replace_kong_envoy
278+
sed -i "s/autostart=.*/autostart=true/" /etc/supervisor/services/envoy.conf
279+
sed -i "s/autostart=.*/autostart=false/" /etc/supervisor/services/kong.conf
280+
sed -i "s/kong/envoy/" /etc/supervisor/services/group.conf
291281
fi
292282

293283
if [ "${FAIL2BAN_DISABLED:-}" == "true" ]; then
294284
disable_fail2ban
295285
fi
296286

297-
298287
if [ "${GOTRUE_DISABLED:-}" == "true" ]; then
299-
disable_gotrue
288+
sed -i "s/autostart=.*/autostart=false/" /etc/supervisor/services/gotrue.conf
289+
sed -i "s/autorestart=.*/autorestart=false/" /etc/supervisor/services/gotrue.conf
300290
fi
301291

302292
if [ "${PLATFORM_DEPLOYMENT:-}" == "true" ]; then

docker/all-in-one/etc/adminapi/adminapi.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ node_exporter_additional_args:
1616
# cert_path: /etc/ssl/adminapi/server.crt
1717
# key_path: /etc/ssl/adminapi/server.key
1818
upstream_metrics_refresh_duration: 60s
19+
pgbouncer_endpoints:
20+
- "postgres://pgbouncer:{{ .PgbouncerPassword }}@localhost:6543/pgbouncer"
1921
fail2ban_socket: /var/run/fail2ban/fail2ban.sock
2022
upstream_metrics_sources:
2123
- name: system
@@ -60,6 +62,7 @@ firewall:
6062
- 0.0.0.0/0
6163
filtered_ports:
6264
- 5432
65+
- 6543
6366
unfiltered_ports:
6467
- 80
6568
- 443

docker/all-in-one/etc/fail2ban/filter.d/postgresql.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ ignoreregex = ^.*,.*,.*,.*,"127\.0\.0\.1.*password authentication failed for use
55
^.*,.*,.*,.*,"<HOST>:.*password authentication failed for user ""supabase_auth_admin".*$
66
^.*,.*,.*,.*,"<HOST>:.*password authentication failed for user ""supabase_storage_admin".*$
77
^.*,.*,.*,.*,"<HOST>:.*password authentication failed for user ""authenticator".*$
8+
^.*,.*,.*,.*,"<HOST>:.*password authentication failed for user ""pgbouncer".*$
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[pgbouncer]
2+
enabled = true
3+
port = 6543
4+
protocol = tcp
5+
filter = pgbouncer
6+
logpath = /var/log/services/pgbouncer.log
7+
maxretry = 3

0 commit comments

Comments
 (0)
0