Skip to content

Commit 8754aab

Browse files
authored
Improve our docker compose file a little. (#724)
* Improve our docker compose file a little. Use environment variables rather than very long command lines where it makes sense, making it easier to see that we're doing the same thing in the three Postgres nodes. * Add support for env variables for pg_autoctl do demo run.
1 parent 7d351de commit 8754aab

6 files changed

Lines changed: 111 additions & 42 deletions

File tree

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ build-check:
207207
build-i386:
208208
docker build -t i386:latest -f Dockerfile.i386 .
209209

210+
build-demo:
211+
docker build -t citusdata/pg_auto_failover:demo .
212+
210213
# expected to be run from within the i386 docker container
211214
installcheck-i386:
212215
pg_autoctl run &

docker-compose.yml

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -12,60 +12,41 @@ services:
1212
image: citusdata/pg_auto_failover:demo
1313
environment:
1414
PGDATA: /tmp/pgaf
15-
PG_AUTOCTL_DEBUG: 1
16-
command: [
17-
"pg_autoctl", "create", "postgres",
18-
"--ssl-self-signed",
19-
"--auth", "trust",
20-
"--pg-hba-lan",
21-
"--username", "ad",
22-
"--dbname", "analytics",
23-
"--monitor", "postgresql://autoctl_node@monitor/pg_auto_failover",
24-
"--run"]
15+
PGUSER: ad
16+
PGDATABASE: analytics
17+
PG_AUTOCTL_MONITOR: "postgresql://autoctl_node@monitor/pg_auto_failover"
18+
command: pg_autoctl create postgres --ssl-self-signed --auth trust --pg-hba-lan --run
2519
expose:
2620
- 5432
2721
node2:
2822
image: citusdata/pg_auto_failover:demo
2923
environment:
3024
PGDATA: /tmp/pgaf
31-
PG_AUTOCTL_DEBUG: 1
32-
command: [
33-
"pg_autoctl", "create", "postgres",
34-
"--ssl-self-signed",
35-
"--auth", "trust",
36-
"--pg-hba-lan",
37-
"--username", "ad",
38-
"--dbname", "analytics",
39-
"--monitor", "postgresql://autoctl_node@monitor/pg_auto_failover",
40-
"--run"]
25+
PGUSER: ad
26+
PGDATABASE: analytics
27+
PG_AUTOCTL_MONITOR: "postgresql://autoctl_node@monitor/pg_auto_failover"
28+
command: pg_autoctl create postgres --ssl-self-signed --auth trust --pg-hba-lan --run
4129
expose:
4230
- 5432
4331
node3:
4432
image: citusdata/pg_auto_failover:demo
4533
environment:
4634
PGDATA: /tmp/pgaf
47-
PG_AUTOCTL_DEBUG: 1
48-
command: [
49-
"pg_autoctl", "create", "postgres",
50-
"--ssl-self-signed",
51-
"--auth", "trust",
52-
"--pg-hba-lan",
53-
"--username", "ad",
54-
"--dbname", "analytics",
55-
"--monitor", "postgresql://autoctl_node@monitor/pg_auto_failover",
56-
"--run"]
35+
PGUSER: ad
36+
PGDATABASE: analytics
37+
PG_AUTOCTL_MONITOR: "postgresql://autoctl_node@monitor/pg_auto_failover"
38+
command: pg_autoctl create postgres --ssl-self-signed --auth trust --pg-hba-lan --run
5739
expose:
5840
- 5432
5941
demo-app:
6042
image: citusdata/pg_auto_failover:demo
6143
environment:
6244
PGDATA: /tmp/pgaf
63-
PG_AUTOCTL_DEBUG: 1
64-
command: [
65-
"pg_autoctl", "do", "demo", "run",
66-
"--username", "ad",
67-
"--clients", "10",
68-
"--duration", "125",
69-
"--first-failover", "45",
70-
"--failover-freq", "30",
71-
"--monitor", "postgresql://autoctl_node@monitor/pg_auto_failover"]
45+
PGUSER: ad
46+
PGDATABASE: analytics
47+
PG_AUTOCTL_MONITOR: "postgresql://autoctl_node@monitor/pg_auto_failover"
48+
PG_AUTOCTL_DEMO_CLIENTS: 10
49+
PG_AUTOCTL_DEMO_DURATION: 125
50+
PG_AUTOCTL_DEMO_FAILOVER_FREQ: 30
51+
PG_AUTOCTL_DEMO_FAILOVER_FIRST: 45
52+
command: pg_autoctl do demo run

src/bin/pg_autoctl/cli_do_demoapp.c

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,85 @@ cli_do_demoapp_getopts(int argc, char **argv)
143143
options.doFailover = true;
144144
strlcpy(options.formation, "default", sizeof(options.formation));
145145

146+
/*
147+
* Add support for environment variables for some of those options.
148+
*/
149+
if (env_exists(PG_AUTOCTL_DEMO_CLIENTS))
150+
{
151+
char clients[BUFSIZE] = { 0 };
152+
153+
if (!get_env_copy(PG_AUTOCTL_DEMO_CLIENTS, clients, sizeof(clients)))
154+
{
155+
/* errors have already been logged */
156+
exit(EXIT_CODE_BAD_ARGS);
157+
}
158+
159+
if (!stringToInt(clients, &(options.clientsCount)))
160+
{
161+
log_fatal("Failed to parse \"%s\" integer value \"%s\"",
162+
PG_AUTOCTL_DEMO_CLIENTS,
163+
clients);
164+
exit(EXIT_CODE_BAD_ARGS);
165+
}
166+
}
167+
168+
if (env_exists(PG_AUTOCTL_DEMO_DURATION))
169+
{
170+
char duration[BUFSIZE] = { 0 };
171+
172+
if (!get_env_copy(PG_AUTOCTL_DEMO_DURATION, duration, sizeof(duration)))
173+
{
174+
/* errors have already been logged */
175+
exit(EXIT_CODE_BAD_ARGS);
176+
}
177+
178+
if (!stringToInt(duration, &(options.duration)))
179+
{
180+
log_fatal("Failed to parse \"%s\" integer value \"%s\"",
181+
PG_AUTOCTL_DEMO_DURATION,
182+
duration);
183+
exit(EXIT_CODE_BAD_ARGS);
184+
}
185+
}
186+
187+
if (env_exists(PG_AUTOCTL_DEMO_FAILOVER_FIRST))
188+
{
189+
char first[BUFSIZE] = { 0 };
190+
191+
if (!get_env_copy(PG_AUTOCTL_DEMO_FAILOVER_FIRST, first, sizeof(first)))
192+
{
193+
/* errors have already been logged */
194+
exit(EXIT_CODE_BAD_ARGS);
195+
}
196+
197+
if (!stringToInt(first, &(options.firstFailover)))
198+
{
199+
log_fatal("Failed to parse \"%s\" integer value \"%s\"",
200+
PG_AUTOCTL_DEMO_FAILOVER_FIRST,
201+
first);
202+
exit(EXIT_CODE_BAD_ARGS);
203+
}
204+
}
205+
206+
if (env_exists(PG_AUTOCTL_DEMO_FAILOVER_FREQ))
207+
{
208+
char freq[BUFSIZE] = { 0 };
209+
210+
if (!get_env_copy(PG_AUTOCTL_DEMO_FAILOVER_FREQ, freq, sizeof(freq)))
211+
{
212+
/* errors have already been logged */
213+
exit(EXIT_CODE_BAD_ARGS);
214+
}
215+
216+
if (!stringToInt(freq, &(options.failoverFreq)))
217+
{
218+
log_fatal("Failed to parse \"%s\" integer value \"%s\"",
219+
PG_AUTOCTL_DEMO_FAILOVER_FREQ,
220+
freq);
221+
exit(EXIT_CODE_BAD_ARGS);
222+
}
223+
}
224+
146225
/*
147226
* The only command lines that are using cli_do_demoapp_getopts are
148227
* terminal ones: they don't accept subcommands. In that case our option

src/bin/pg_autoctl/defaults.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434
#define PG_AUTOCTL_CANDIDATE_PRIORITY "PG_AUTOCTL_CANDIDATE_PRIORITY"
3535
#define PG_AUTOCTL_REPLICATION_QUORUM "PG_AUTOCTL_REPLICATION_QUORUM"
3636

37+
/* environment variables for `pg_autoctl do demo run` */
38+
#define PG_AUTOCTL_DEMO_CLIENTS "PG_AUTOCTL_DEMO_CLIENTS"
39+
#define PG_AUTOCTL_DEMO_DURATION "PG_AUTOCTL_DEMO_DURATION"
40+
#define PG_AUTOCTL_DEMO_FAILOVER_FREQ "PG_AUTOCTL_DEMO_FAILOVER_FREQ"
41+
#define PG_AUTOCTL_DEMO_FAILOVER_FIRST "PG_AUTOCTL_DEMO_FAILOVER_FIRST"
42+
3743
/* default values for the pg_autoctl settings */
3844
#define POSTGRES_PORT 5432
3945
#define POSTGRES_DEFAULT_LISTEN_ADDRESSES "*"

src/bin/pg_autoctl/keeper_pg_init.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,12 +1016,12 @@ create_database_and_extension(Keeper *keeper)
10161016
*/
10171017
if (!IS_EMPTY_STRING_BUFFER(pgSetup->username))
10181018
{
1019+
char pguser[NAMEDATALEN] = { 0 };
1020+
10191021
/*
10201022
* Remove PGUSER from the environment when we want to create that very
10211023
* user at bootstrap.
10221024
*/
1023-
char pguser[NAMEDATALEN] = { 0 };
1024-
10251025
if (!get_env_copy_with_fallback("PGUSER", pguser, NAMEDATALEN, ""))
10261026
{
10271027
/* errors have already been logged */

src/bin/pg_autoctl/pgsetup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ pg_setup_init(PostgresSetup *pgSetup,
199199
}
200200

201201
/* check or find dbname */
202-
if (options->dbname[0] != '\0')
202+
if (!IS_EMPTY_STRING_BUFFER(options->dbname))
203203
{
204204
strlcpy(pgSetup->dbname, options->dbname, NAMEDATALEN);
205205
}

0 commit comments

Comments
 (0)