From dbe6f62fa21cd4d0871e5573d2fda9582c86b5bb Mon Sep 17 00:00:00 2001 From: root Date: Sat, 13 Jun 2020 00:54:27 +0000 Subject: [PATCH] Stack file inclusion --- roles/lxc_swarm/tasks/deploy.yml | 3 +- stack.yaml | 102 +++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 stack.yaml diff --git a/roles/lxc_swarm/tasks/deploy.yml b/roles/lxc_swarm/tasks/deploy.yml index 5c48194..dacef53 100644 --- a/roles/lxc_swarm/tasks/deploy.yml +++ b/roles/lxc_swarm/tasks/deploy.yml @@ -15,8 +15,9 @@ unset MASTER_ADDR mcontainer_addr=`ssh root@10.0.3.100 "docker ps|xargs -n1|grep -i NAMES -A 1|tail -1"` MASTER_ADDR=`ssh -t root@10.0.3.100 "docker exec -it $mcontainer_addr ip a s|grep -i 10.0|head -1 2>/dev/null" 2>&1 |grep inet|awk '{print $2}'|cut -d "/" -f 1|tr -d ' '` + [ -z $MASTER_ADDR ] && echo "Node 1 hasn't yet been initialized" && exit 1 env MASTER_ADDR="${MASTER_ADDR}" docker stack deploy -c stack.yaml stack - docker service scale stack_bnode=1 + env MASTER_ADDR="${MASTER_ADDR}" docker service scale stack_bnode=1 # sleep 30 args: executable: /bin/bash diff --git a/stack.yaml b/stack.yaml new file mode 100644 index 0000000..270922b --- /dev/null +++ b/stack.yaml @@ -0,0 +1,102 @@ +version: '3.4' + +services: +# seed: +# image: colinmollenhour/mariadb-galera-swarm +# environment: +# - XTRABACKUP_PASSWORD_FILE=/run/secrets/xtrabackup_password +# - MYSQL_USER=user +# - MYSQL_PASSWORD_FILE=/run/secrets/mysql_password +# - MYSQL_DATABASE=database +# - MYSQL_ROOT_PASSWORD_FILE=/run/secrets/mysql_root_password +# - NODE_ADDRESS=^10.0.*.* +# networks: +# - galera_network +# command: seed +# deploy: +# placement: +# # Services must run only on workers with one service per container +# constraints: +# - node.labels.node1 == true +# - node.role == worker +# volumes: +# - /var/lib/mysql:/var/lib/mysql +# secrets: +# - xtrabackup_password +# - mysql_password +# - mysql_root_password + anode: + image: colinmollenhour/mariadb-galera-swarm +# hostname: + environment: + - XTRABACKUP_PASSWORD_FILE=/run/secrets/xtrabackup_password + - NODE_ADDRESS=^10.0.*.* + - HEALTHY_WHILE_BOOTING=1 + networks: + - galera_network + command: node tasks.anode,tasks.bnode + volumes: + - /var/lib/mysql:/var/lib/mysql + deploy: + # Replicated mode + mode: replicated + replicas: 1 +# restart_policy: +# delay: 10s +# max_attempts: 10 +# window: 60s + placement: + # Services must run only on workers with one service per container + #max_replicas_per_node: 1 + constraints: + - node.labels.node1 == true + - node.role == worker + secrets: + - xtrabackup_password + bnode: + image: colinmollenhour/mariadb-galera-swarm + #hostname: bnode + environment: + - XTRABACKUP_PASSWORD_FILE=/run/secrets/xtrabackup_password + - NODE_ADDRESS=^10.0.*.* + - HEALTHY_WHILE_BOOTING=1 + - MASTER_ADDR + networks: + - galera_network + command: node $MASTER_ADDR,tasks.bnode + volumes: + - /var/lib/mysql:/var/lib/mysql + deploy: + # Replicated mode + mode: replicated + replicas: 0 + # restart_policy: + # delay: 10s + # max_attempts: 10 + # window: 60s + placement: + # Services must run only on workers with one service per container + #max_replicas_per_node: 1 + constraints: + - node.labels.node2 == true + - node.role == worker + depends_on: + - bnode + secrets: + - xtrabackup_password + +#volumes: +# mysql-data: +# name: '{{.Service.Name}}-{{.Task.Slot}}-data' +# driver: local + +networks: + galera_network: + +secrets: + xtrabackup_password: + file: .secrets/xtrabackup_password + mysql_password: + file: .secrets/mysql_password + mysql_root_password: + file: .secrets/mysql_root_password