Skip to content

Commit 0b33c80

Browse files
DimCitusJelteF
andauthored
Implement make compose, using docker-compose for local interactive testing. (#825)
* Implement make compose. Similar to `make cluster`, this allows to start a local cluster to play with multiple Postgres nodes registered in a pg_auto_failover monitor. This time the command uses docker-compose to run all the nodes in the background, and each node has its own pre-created external docker volume. * Use --build-arg PGVERSION=... in make compose. * Introduce another needed wait point in the tmux script. * Clean-up: we don't need both --name and PG_AUTOCTL_NODE_NAME. * Ignore some files for docker Co-authored-by: Jelte Fennema <github-tech@jeltef.nl>
1 parent 676bb45 commit 0b33c80

9 files changed

Lines changed: 848 additions & 4 deletions

File tree

.dockerignore

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,60 @@
22
src/bin/pg_autoctl/pg_autoctl
33
docs
44
Dockerfile
5+
6+
# Global excludes across all subdirectories
7+
*.o
8+
*.bc
9+
*.so
10+
*.so.[0-9]
11+
*.so.[0-9].[0-9]
12+
*.sl
13+
*.sl.[0-9]
14+
*.sl.[0-9].[0-9]
15+
*.dylib
16+
*.dll
17+
*.a
18+
*.mo
19+
*.pot
20+
objfiles.txt
21+
.deps/
22+
*.gcno
23+
*.gcda
24+
*.gcov
25+
*.gcov.out
26+
lcov.info
27+
coverage/
28+
*.vcproj
29+
*.vcxproj
30+
win32ver.rc
31+
*.exe
32+
lib*dll.def
33+
lib*.pc
34+
*.log
35+
36+
# Local excludes in root directory
37+
/config.log
38+
/config.status
39+
/pgsql.sln
40+
/pgsql.sln.cache
41+
/Debug/
42+
/Release/
43+
/autom4te.cache
44+
/Makefile.global
45+
/src/Makefile.custom
46+
/tests/__pycache__/
47+
/env/
48+
49+
# Exclude generated SQL files
50+
pgautofailover--?.?.sql
51+
!pgautofailover--1.0.sql
52+
53+
# Exclude generated PDF and PNG files for the graphics
54+
docs/tikz/*.pdf
55+
docs/tikz/*.png
56+
57+
# Exclude our demo/test tmux directory
58+
tmux/
59+
valgrind/*
60+
61+
.ccls-cache/

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ win32ver.rc
2626
*.exe
2727
lib*dll.def
2828
lib*.pc
29+
*.log
2930

3031
# Local excludes in root directory
3132
/config.log

Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ RUN apt-get update \
5050
postgresql-common \
5151
&& rm -rf /var/lib/apt/lists/*
5252

53-
RUN pip3 install pyroute2>=0.5.17
54-
5553
RUN curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
5654
RUN echo "deb http://apt.postgresql.org/pub/repos/apt buster-pgdg main" > /etc/apt/sources.list.d/pgdg.list
5755

@@ -72,6 +70,7 @@ RUN apt-get update \
7270
&& rm -rf /var/lib/apt/lists/*
7371

7472
RUN pip3 install pyroute2>=0.5.17
73+
7574
RUN adduser --disabled-password --gecos '' docker
7675
RUN adduser docker sudo
7776
RUN adduser docker postgres

Makefile

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,27 @@ tmux-session: bin
261261
--binpath $(BINPATH) \
262262
--layout $(TMUX_LAYOUT)
263263

264+
tmux-compose-session:
265+
$(PG_AUTOCTL) do tmux compose session \
266+
--root $(TMUX_TOP_DIR) \
267+
--first-pgport $(FIRST_PGPORT) \
268+
--nodes $(NODES) \
269+
--async-nodes $(NODES_ASYNC) \
270+
--node-priorities $(NODES_PRIOS) \
271+
--sync-standbys $(NODES_SYNC_SB) \
272+
$(CLUSTER_OPTS) \
273+
--binpath $(BINPATH) \
274+
--layout $(TMUX_LAYOUT)
275+
264276
cluster: install tmux-clean
265277
# This is explicitly not a target, otherwise when make uses multiple jobs
266278
# tmux-clean and tmux-session can have a race condidition where tmux-clean
267279
# removes the files that are just created by tmux-session.
268280
$(MAKE) tmux-session
269281

282+
compose:
283+
$(MAKE) tmux-compose-session
284+
270285
valgrind-session: build-test
271286
docker run \
272287
--name $(TEST_CONTAINER_NAME) \
@@ -302,7 +317,7 @@ azdrop: all
302317
.PHONY: monitor clean-monitor check-monitor install-monitor
303318
.PHONY: bin clean-bin install-bin
304319
.PHONY: build-test run-test
305-
.PHONY: tmux-clean cluster
320+
.PHONY: tmux-clean cluster compose
306321
.PHONY: azcluster azdrop az
307322
.PHONY: build-image
308323
.PHONY: build-test-pg10 build-test-pg11 build-test-pg142

src/bin/pg_autoctl/cli_do_root.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,66 @@ CommandLine do_pgsetup_commands =
221221
"Manage a local Postgres setup", NULL, NULL,
222222
NULL, do_pgsetup);
223223

224+
CommandLine do_tmux_compose_config =
225+
make_command("config",
226+
"Produce a docker-compose configuration file for a demo",
227+
"[option ...]",
228+
" --root path where to create a cluster\n"
229+
" --first-pgport first Postgres port to use (5500)\n"
230+
" --nodes number of Postgres nodes to create (2)\n"
231+
" --async-nodes number of async nodes within nodes (0)\n"
232+
" --node-priorities list of nodes priorities (50)\n"
233+
" --sync-standbys number-sync-standbys to set (0 or 1)\n"
234+
" --skip-pg-hba use --skip-pg-hba when creating nodes\n"
235+
" --layout tmux layout to use (even-vertical)\n"
236+
" --binpath path to the pg_autoctl binary (current binary path)",
237+
cli_do_tmux_script_getopts,
238+
cli_do_tmux_compose_config);
239+
240+
CommandLine do_tmux_compose_script =
241+
make_command("script",
242+
"Produce a tmux script for a demo or a test case (debug only)",
243+
"[option ...]",
244+
" --root path where to create a cluster\n"
245+
" --first-pgport first Postgres port to use (5500)\n"
246+
" --nodes number of Postgres nodes to create (2)\n"
247+
" --async-nodes number of async nodes within nodes (0)\n"
248+
" --node-priorities list of nodes priorities (50)\n"
249+
" --sync-standbys number-sync-standbys to set (0 or 1)\n"
250+
" --skip-pg-hba use --skip-pg-hba when creating nodes\n"
251+
" --layout tmux layout to use (even-vertical)\n"
252+
" --binpath path to the pg_autoctl binary (current binary path)",
253+
cli_do_tmux_script_getopts,
254+
cli_do_tmux_compose_script);
255+
256+
CommandLine do_tmux_compose_session =
257+
make_command("session",
258+
"Run a tmux session for a demo or a test case",
259+
"[option ...]",
260+
" --root path where to create a cluster\n"
261+
" --first-pgport first Postgres port to use (5500)\n"
262+
" --nodes number of Postgres nodes to create (2)\n"
263+
" --async-nodes number of async nodes within nodes (0)\n"
264+
" --node-priorities list of nodes priorities (50)\n"
265+
" --sync-standbys number-sync-standbys to set (0 or 1)\n"
266+
" --skip-pg-hba use --skip-pg-hba when creating nodes\n"
267+
" --layout tmux layout to use (even-vertical)\n"
268+
" --binpath path to the pg_autoctl binary (current binary path)",
269+
cli_do_tmux_script_getopts,
270+
cli_do_tmux_compose_session);
271+
272+
CommandLine *do_tmux_compose[] = {
273+
&do_tmux_compose_config,
274+
&do_tmux_compose_script,
275+
&do_tmux_compose_session,
276+
NULL
277+
};
278+
279+
CommandLine do_tmux_compose_commands =
280+
make_command_set("compose",
281+
"Set of facilities to handle docker-compose sessions",
282+
NULL, NULL, NULL, do_tmux_compose);
283+
224284
CommandLine do_tmux_script =
225285
make_command("script",
226286
"Produce a tmux script for a demo or a test case (debug only)",
@@ -290,6 +350,7 @@ CommandLine do_tmux_wait =
290350
cli_do_tmux_wait);
291351

292352
CommandLine *do_tmux[] = {
353+
&do_tmux_compose_commands,
293354
&do_tmux_script,
294355
&do_tmux_session,
295356
&do_tmux_stop,

src/bin/pg_autoctl/cli_do_root.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ void cli_do_tmux_stop(int argc, char **argv);
109109
void cli_do_tmux_clean(int argc, char **argv);
110110
void cli_do_tmux_wait(int argc, char **argv);
111111

112+
/* src/bin/pg_autoctl/cli_do_tmux_compose.c */
113+
void cli_do_tmux_compose_config(int argc, char **argv);
114+
void cli_do_tmux_compose_script(int argc, char **argv);
115+
void cli_do_tmux_compose_session(int argc, char **argv);
116+
112117
/* src/bin/pg_autoctl/cli_do_azure.c */
113118
int cli_do_azure_getopts(int argc, char **argv);
114119
void cli_do_azure_create_environment(int argc, char **argv);

src/bin/pg_autoctl/cli_do_tmux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* src/bin/pg_autoctl/cli_do_misc.c
2+
* src/bin/pg_autoctl/cli_do_tmux.c
33
* Implementation of a CLI which lets you run operations on the local
44
* postgres server directly.
55
*

src/bin/pg_autoctl/cli_do_tmux.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ typedef struct TmuxNodeArray
5656
TmuxNode nodes[MAX_NODES];
5757
} TmuxNodeArray;
5858

59+
extern char *tmux_banner[];
5960
extern TmuxOptions tmuxOptions;
6061
extern TmuxNodeArray tmuxNodeArray;
6162

0 commit comments

Comments
 (0)