Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Docker secrets support and fixes 'DETAIL: bind socket failed with error: "Address already in use"' on pgpool restart #237

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added docker-compose-stack.yml
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@

##########################################################################
## AUTO-GENERATED FILE ##
## BUILD_NUMBER=jue jul 4 12:31:21 -03 2019 ##
##########################################################################

version: '3.3'
networks:
cluster:

volumes:
pgmaster:
pgslave1:
pgslave2:
pgslave3:
pgslave4:
backup:

secrets:
db_users_file:
file: ../src/secrets/db_users
pcp_user_pass:
file: ../src/secrets/pcp_pass
check_user_pass:
file: ../src/secrets/check_pass
mokey_user_pass:
file: ../src/secrets/monkey_pass
replication_user_pass:
file: ../src/secrets/replication_pass

services:
pgmaster:
container_name: pgmaster
hostname: pgmaster
build:
context: ../src
dockerfile: Postgres-10-Repmgr-3.2.Dockerfile
environment:
NODE_ID: 1 # Integer number of node (not required if can be extracted from NODE_NAME var, e.g. node-45 => 1045)
NODE_NAME: node1 # Node name
CLUSTER_NODE_NETWORK_NAME: pgmaster # (default: hostname of the node)

PARTNER_NODES: "pgmaster,pgslave1,pgslave3"
REPLICATION_PRIMARY_HOST: pgmaster # That should be ignored on the same node

NODE_PRIORITY: 100 # (default: 100)
SSH_ENABLE: 1
#database we want to use for application
POSTGRES_PASSWORD_FILE: /run/secrets/mokey_user_pass
POSTGRES_USER: monkey_user
POSTGRES_DB: monkey_db
CLEAN_OVER_REWIND: 0
CONFIGS_DELIMITER_SYMBOL: ;
CONFIGS: "listen_addresses:'*';max_replication_slots:5"
# in format variable1:value1[,variable2:value2[,...]] if CONFIGS_DELIMITER_SYMBOL=, and CONFIGS_ASSIGNMENT_SYMBOL=:
# used for pgpool.conf file
#defaults:
CLUSTER_NAME: pg_cluster # default is pg_cluster
REPLICATION_DB: replication_db # default is replication_db
REPLICATION_USER: replication_user # default is replication_user
REPLICATION_PASSWORD_FILE: /run/secrets/replication_user_pass # default is replication_pass

secrets:
- mokey_user_pass
- replication_user_pass
ports:
- 5422:5432
volumes:
- pgmaster:/var/lib/postgresql/data
- ./ssh/:/tmp/.ssh/keys
networks:
- cluster
#<<< Branch 1
pgslave1:
container_name: pgslave1
hostname: pgslave1
build:
context: ../src
dockerfile: Postgres-10-Repmgr-3.2.Dockerfile
environment:
NODE_ID: 2
NODE_NAME: node2
CLUSTER_NODE_NETWORK_NAME: pgslave1 # (default: hostname of the node)
SSH_ENABLE: 1
PARTNER_NODES: "pgmaster,pgslave1,pgslave3"
REPLICATION_PRIMARY_HOST: pgmaster
CLEAN_OVER_REWIND: 1
CONFIGS_DELIMITER_SYMBOL: ;
CONFIGS: "max_replication_slots:10" #some overrides
REPLICATION_DB: replication_db # default is replication_db
REPLICATION_USER: replication_user # default is replication_user
REPLICATION_PASSWORD_FILE: /run/secrets/replication_user_pass # default is replication_pass
secrets:
- replication_user_pass
ports:
- 5441:5432
volumes:
- pgslave1:/var/lib/postgresql/data
- ./ssh:/tmp/.ssh/keys
networks:
- cluster


# Add more slaves if required
pgslave2:
container_name: pgslave2
hostname: pgslave2
build:
context: ../src
dockerfile: Postgres-10-Repmgr-3.2.Dockerfile
environment:
NODE_ID: 3
NODE_NAME: node3
CLUSTER_NODE_NETWORK_NAME: pgslave2 # (default: hostname of the node)

REPLICATION_PRIMARY_HOST: pgslave1 # I want to have cascade Streeming replication
#USE_REPLICATION_SLOTS: 0
CONFIGS_DELIMITER_SYMBOL: ;
CONFIGS: "listen_addresses:'*'"
REPLICATION_DB: replication_db # default is replication_db
REPLICATION_USER: replication_user # default is replication_user
REPLICATION_PASSWORD_FILE: /run/secrets/replication_user_pass # default is replication_pass
secrets:
- replication_user_pass
volumes:
- pgslave2:/var/lib/postgresql/data
- ./ssh:/tmp/.ssh/keys
ports:
- 5442:5432
networks:
- cluster


#>>> Branch 1
#<<< Branch 2
pgslave3:
container_name: pgslave3
hostname: pgslave3
build:
context: ../src
dockerfile: Postgres-10-Repmgr-3.2.Dockerfile
environment:
NODE_ID: 4
NODE_NAME: node4
CLUSTER_NODE_NETWORK_NAME: pgslave3 # (default: hostname of the node)
SSH_ENABLE: 1
PARTNER_NODES: "pgmaster,pgslave1,pgslave3"
REPLICATION_PRIMARY_HOST: pgmaster
NODE_PRIORITY: 200 # (default: 100)
CLEAN_OVER_REWIND: 1
CONFIGS_DELIMITER_SYMBOL: ;
CONFIGS: "listen_addresses:'*'"
REPLICATION_DB: replication_db # default is replication_db
REPLICATION_USER: replication_user # default is replication_user
REPLICATION_PASSWORD_FILE: /run/secrets/replication_user_pass # default is replication_pass
secrets:
- replication_user_pass
ports:
- 5443:5432
volumes:
- pgslave3:/var/lib/postgresql/data
- ./ssh:/tmp/.ssh/keys
networks:
- cluster


pgslave4:
container_name: pgslave4
hostname: pgslave4
build:
context: ../src
dockerfile: Postgres-10-Repmgr-3.2.Dockerfile
environment:
NODE_ID: 5
NODE_NAME: node5
CLUSTER_NODE_NETWORK_NAME: pgslave4 # (default: hostname of the node)

REPLICATION_PRIMARY_HOST: pgslave3
#USE_REPLICATION_SLOTS: 0
CONFIGS_DELIMITER_SYMBOL: ;
CONFIGS: "listen_addresses:'*'"
REPLICATION_DB: replication_db # default is replication_db
REPLICATION_USER: replication_user # default is replication_user
REPLICATION_PASSWORD_FILE: /run/secrets/replication_user_pass # default is replication_pass
secrets:
- replication_user_pass
ports:
- 5444:5432
volumes:
- pgslave4:/var/lib/postgresql/data
- ./ssh:/tmp/.ssh/keys
networks:
- cluster



#>>> Branch 2
backup:
container_name: backup
hostname: backup
build:
context: ../src
dockerfile: Barman-2.3-Postgres-10.Dockerfile
environment:
REPLICATION_USER: replication_user # default is replication_user
REPLICATION_PASSWORD_FILE: /run/secrets/replication_user_pass # default is replication_pass
REPLICATION_HOST: pgmaster
POSTGRES_PASSWORD_FILE: /run/secrets/mokey_user_pass
POSTGRES_USER: monkey_user
POSTGRES_DB: monkey_db
SSH_ENABLE: 1
BACKUP_SCHEDULE: "*/30 */5 * * *"
secrets:
- mokey_user_pass
- replication_user_pass
volumes:
- backup:/var/lib/postgresql/data
- ./ssh:/tmp/.ssh/keys

pgpool:
container_name: pgpool
hostname: pgpool
build:
context: ../src
dockerfile: Pgpool-3.3-Postgres-10.Dockerfile
environment:
PCP_USER: pcp_user
PCP_PASSWORD_FILE: /run/secrets/pcp_user_pass
WAIT_BACKEND_TIMEOUT: 60

CHECK_USER: monkey_user
CHECK_PASSWORD_FILE: /run/secrets/check_user_pass
CHECK_PGCONNECT_TIMEOUT: 3 #timout for checking if primary node is healthy
SSH_ENABLE: 1
DB_USERS_FILE: /run/secrets/db_users_file # in format user:password[,user:password[...]]
BACKENDS: "0:pgmaster:5432:1:/var/lib/postgresql/data:ALLOW_TO_FAILOVER,1:pgslave1::::,3:pgslave3::::,2:pgslave2::::" #,4:pgslaveDOES_NOT_EXIST::::
# in format num:host:port:weight:data_directory:flag[,...]
# defaults:
# port: 5432
# weight: 1
# data_directory: /var/lib/postgresql/data
# flag: ALLOW_TO_FAILOVER
REQUIRE_MIN_BACKENDS: 3 # minimal number of backends to start pgpool (some might be unreachable)
CONFIGS: "num_init_children:250,max_pool:4"
# in format variable1:value1[,variable2:value2[,...]] if CONFIGS_DELIMITER_SYMBOL=, and CONFIGS_ASSIGNMENT_SYMBOL=:
# used for pgpool.conf file
secrets:
- db_users_file
- pcp_user_pass
- check_user_pass
ports:
- 5430:5432
- 9898:9898 # PCP
volumes:
- ./ssh:/tmp/.ssh/keys
networks:
- cluster

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

##########################################################################
## AUTO-GENERATED FILE ##
## BUILD_NUMBER=Sat 27 Apr 2019 12:29:35 +08 ##
## BUILD_NUMBER=jue jul 4 12:31:21 -03 2019 ##
##########################################################################

version: '2'
Expand Down
Loading