be318804 by Adam Heath

Major update.

1 parent 75c860fd
1 version: '2.4' 1 version: '3.4'
2
3 x-extra-hosts: &_x_extra_hosts
4 extra_hosts:
5 - "${APP_REGISTRY_NAME}:${APP_REGISTRY_ADDRESS}"
2 6
3 x-etcd-environment: &_x-etcd-environment 7 x-etcd-environment: &_x-etcd-environment
4 ALLOW_NONE_AUTHENTICATION: "yes" 8 ALLOW_NONE_AUTHENTICATION: "yes"
...@@ -16,7 +20,35 @@ x-etcd-base: &_x-etcd-base ...@@ -16,7 +20,35 @@ x-etcd-base: &_x-etcd-base
16 command: ["/opt/bitnami/scripts/etcd/run.sh"] 20 command: ["/opt/bitnami/scripts/etcd/run.sh"]
17 user: root 21 user: root
18 22
23 x-root-cert-volume: &_x-root-cert-volume
24 type: bind
25 source: ${CONTEXT_DIR}/certs/root.crt
26 target: /etc/ssl/certs/root.crt
27 read_only: true
28 bind:
29 create_host_path: false
30
31 x-kubelet-volume: &_x-kubelet-volume
32 type: volume
33 target: /var/lib/kubelet
34 # volume:
35 # propagation: shared
36
37 x-registries-yaml-volume: &_x-registries-yaml-volume
38 type: bind
39 source: ${APISERVER_DIR}/etc/registries.yaml
40 target: /etc/rancher/k3s/registries.yaml
41 read_only: true
42 bind:
43 create_host_path: false
44
45 x-k3s-master-env: &_x-k3s-master-env
46 K3S_KUBECONFIG_OUTPUT: /output/kubeconfig.yaml
47 K3S_KUBECONFIG_MODE: "666"
48 K3S_NODE_NAME: master
49
19 x-k3s-master-base: &_x-k3s-master-base 50 x-k3s-master-base: &_x-k3s-master-base
51 <<: *_x_extra_hosts
20 image: "docker.io/rancher/k3s:${K3S_VERSION:-latest}" 52 image: "docker.io/rancher/k3s:${K3S_VERSION:-latest}"
21 networks: 53 networks:
22 default: 54 default:
...@@ -35,18 +67,27 @@ x-k3s-master-base: &_x-k3s-master-base ...@@ -35,18 +67,27 @@ x-k3s-master-base: &_x-k3s-master-base
35 ports: 67 ports:
36 - 6443 68 - 6443
37 environment: 69 environment:
38 - K3S_KUBECONFIG_OUTPUT=/output/kubeconfig.yaml 70 <<: *_x-k3s-master-env
39 - K3S_KUBECONFIG_MODE=666
40 - K3S_NODE_NAME=master
41 volumes: 71 volumes:
42 - server:/var/lib/rancher/k3s/server 72 - server:/var/lib/rancher/k3s/server
43 - output:/output 73 - output:/output
44 - ./etc/registries.yaml:/etc/rancher/k3s/registries.yaml:ro 74 - ${APP_ROOT_DIR?Please set APP_ROOT_DIR}:${APP_ROOT_MOUNT?Please set APP_ROOT_MOUNT(where to mount $PWD)}
45 - ./certs/root.crt:/etc/ssl/certs/root.crt:ro 75 # - *_x-registries-yaml-volume
46 - ./certs/registry.crt:/etc/ssl/certs/registry.crt:ro 76 - *_x-root-cert-volume
47 - .:${APP_ROOT_MOUNT?Please set APP_ROOT_MOUNT(where to mount $PWD)} 77 - *_x-kubelet-volume
78
79 x-k3s-agent-env: &_x-k3s-agent-env
80 K3S_URL: https://k3s-master:6443
81 K3S_TOKEN_FILE: /var/lib/rancher/k3s/server/node-token
82 K3S_NODE_NAME: k3s-agent
83 VIRTUAL_HOST: ${VHOST_STUB},*${VHOST_SUFFIX},${APP_REGISTRY_NAME}
84 VIRTUAL_PROTO: https
85 VIRTUAL_PORT: "443"
86 SELF_SIGNED_HOST: ${VHOST_STUB},*${VHOST_SUFFIX}
87 HTTPS_METHOD: noredirect
48 88
49 x-k3s-agent-base: &_x-k3s-agent-base 89 x-k3s-agent-base: &_x-k3s-agent-base
90 <<: *_x_extra_hosts
50 image: "docker.io/rancher/k3s:${K3S_VERSION:-latest}" 91 image: "docker.io/rancher/k3s:${K3S_VERSION:-latest}"
51 tmpfs: 92 tmpfs:
52 - /run 93 - /run
...@@ -57,10 +98,10 @@ x-k3s-agent-base: &_x-k3s-agent-base ...@@ -57,10 +98,10 @@ x-k3s-agent-base: &_x-k3s-agent-base
57 soft: 65535 98 soft: 65535
58 hard: 65535 99 hard: 65535
59 volumes: 100 volumes:
60 - .:${APP_ROOT_MOUNT?Please specify where to mount $PWD} 101 - ${APP_ROOT_DIR?Please set APP_ROOT_DIR}:${APP_ROOT_MOUNT?Please specify where to mount $PWD}
61 - ./etc/registries.yaml:/etc/rancher/k3s/registries.yaml:ro 102 # - *_x-registries-yaml-volume
62 - ./certs/root.crt:/etc/ssl/certs/root.crt:ro 103 - *_x-root-cert-volume
63 - ./certs/registry.crt:/etc/ssl/certs/registry.crt:ro 104 - *_x-kubelet-volume
64 - server:/var/lib/rancher/k3s/server:ro 105 - server:/var/lib/rancher/k3s/server:ro
65 privileged: true 106 privileged: true
66 restart: always 107 restart: always
...@@ -70,14 +111,7 @@ x-k3s-agent-base: &_x-k3s-agent-base ...@@ -70,14 +111,7 @@ x-k3s-agent-base: &_x-k3s-agent-base
70 ports: 111 ports:
71 - 443 112 - 443
72 environment: 113 environment:
73 - K3S_URL=https://k3s-master:6443 114 <<: *_x-k3s-agent-env
74 - K3S_TOKEN_FILE=/var/lib/rancher/k3s/server/node-token
75 - K3S_NODE_NAME=k3s-agent
76 - VIRTUAL_HOST=${VHOST_STUB},*${VHOST_SUFFIX}
77 - VIRTUAL_PROTO=https
78 - VIRTUAL_PORT=443
79 - SELF_SIGNED_HOST=${VHOST_STUB},*${VHOST_SUFFIX}
80 - HTTPS_METHOD=noredirect
81 115
82 x-coredns-base: &_x-coredns-base 116 x-coredns-base: &_x-coredns-base
83 image: docker.io/coredns/coredns 117 image: docker.io/coredns/coredns
...@@ -86,13 +120,13 @@ x-coredns-base: &_x-coredns-base ...@@ -86,13 +120,13 @@ x-coredns-base: &_x-coredns-base
86 volumes: 120 volumes:
87 - server:/var/lib/rancher/k3s/server 121 - server:/var/lib/rancher/k3s/server
88 - output:/output 122 - output:/output
89 - ./etc/coredns:/etc/coredns:ro 123 - ${APISERVER_DIR}/etc/coredns:/etc/coredns:ro
90 124
91 networks: 125 networks:
92 default: 126 default:
93 nginx: 127 nginx:
94 external: 128 name: nginx
95 name: nginx 129 external: true
96 130
97 services: 131 services:
98 etcd1: 132 etcd1:
...@@ -103,7 +137,7 @@ services: ...@@ -103,7 +137,7 @@ services:
103 ETCD_INITIAL_ADVERTISE_PEER_URLS: http://etcd1:2380 137 ETCD_INITIAL_ADVERTISE_PEER_URLS: http://etcd1:2380
104 ETCD_ADVERTISE_CLIENT_URLS: http://etcd1:2379 138 ETCD_ADVERTISE_CLIENT_URLS: http://etcd1:2379
105 volumes: 139 volumes:
106 - ./scripts/etcd-entrypoint.sh:/etcd-entrypoint.sh:ro 140 - ${APISERVER_DIR}/scripts/etcd-entrypoint.sh:/etcd-entrypoint.sh:ro
107 - etcd1-data:/bitnami/etcd/data 141 - etcd1-data:/bitnami/etcd/data
108 142
109 etcd2: 143 etcd2:
...@@ -114,7 +148,7 @@ services: ...@@ -114,7 +148,7 @@ services:
114 ETCD_INITIAL_ADVERTISE_PEER_URLS: http://etcd2:2380 148 ETCD_INITIAL_ADVERTISE_PEER_URLS: http://etcd2:2380
115 ETCD_ADVERTISE_CLIENT_URLS: http://etcd2:2379 149 ETCD_ADVERTISE_CLIENT_URLS: http://etcd2:2379
116 volumes: 150 volumes:
117 - ./scripts/etcd-entrypoint.sh:/etcd-entrypoint.sh:ro 151 - ${APISERVER_DIR}/scripts/etcd-entrypoint.sh:/etcd-entrypoint.sh:ro
118 - etcd2-data:/bitnami/etcd/data 152 - etcd2-data:/bitnami/etcd/data
119 153
120 etcd3: 154 etcd3:
...@@ -125,41 +159,47 @@ services: ...@@ -125,41 +159,47 @@ services:
125 ETCD_INITIAL_ADVERTISE_PEER_URLS: http://etcd3:2380 159 ETCD_INITIAL_ADVERTISE_PEER_URLS: http://etcd3:2380
126 ETCD_ADVERTISE_CLIENT_URLS: http://etcd3:2379 160 ETCD_ADVERTISE_CLIENT_URLS: http://etcd3:2379
127 volumes: 161 volumes:
128 - ./scripts/etcd-entrypoint.sh:/etcd-entrypoint.sh:ro 162 - ${APISERVER_DIR}/scripts/etcd-entrypoint.sh:/etcd-entrypoint.sh:ro
129 - etcd3-data:/bitnami/etcd/data 163 - etcd3-data:/bitnami/etcd/data
130 164
131 k3s-master-1: 165 k3s-master-1:
132 <<: *_x-k3s-master-base 166 <<: *_x-k3s-master-base
133 command: [ 167 command: [
134 "server", 168 "server",
135 "--with-node-id", 169 "--disable=traefik,coredns,local-storage",
136 "--disable=traefik,coredns",
137 "--node-taint", "node-role.kubernetes.io/master=true:NoSchedule", 170 "--node-taint", "node-role.kubernetes.io/master=true:NoSchedule",
138 "--datastore-endpoint=http://etcd1:2379", 171 "--datastore-endpoint=http://etcd1:2379",
139 "--cluster-init", 172 "--cluster-init",
140 ] 173 ]
174 environment:
175 <<: *_x-k3s-agent-env
176 K3S_NODE_NAME: master-1
141 177
142 k3s-master-2: 178 k3s-master-2:
143 <<: *_x-k3s-master-base 179 <<: *_x-k3s-master-base
144 command: [ 180 command: [
145 "server", 181 "server",
146 "--with-node-id", 182 "--disable=traefik,coredns,local-storage",
147 "--disable=traefik,coredns",
148 "--node-taint", "node-role.kubernetes.io/master=true:NoSchedule", 183 "--node-taint", "node-role.kubernetes.io/master=true:NoSchedule",
149 "--datastore-endpoint=http://etcd2:2379", 184 "--datastore-endpoint=http://etcd2:2379",
150 "--server=http://k3s-master-1:6443", 185 "--server=http://k3s-master-1:6443",
151 ] 186 ]
187 environment:
188 <<: *_x-k3s-agent-env
189 K3S_NODE_NAME: master-2
152 190
153 k3s-master-3: 191 k3s-master-3:
154 <<: *_x-k3s-master-base 192 <<: *_x-k3s-master-base
155 command: [ 193 command: [
156 "server", 194 "server",
157 "--with-node-id", 195 "--disable=traefik,coredns,local-storage",
158 "--disable=traefik,coredns",
159 "--node-taint", "node-role.kubernetes.io/master=true:NoSchedule", 196 "--node-taint", "node-role.kubernetes.io/master=true:NoSchedule",
160 "--datastore-endpoint=http://etcd3:2379", 197 "--datastore-endpoint=http://etcd3:2379",
161 "--server=http://k3s-master-1:6443", 198 "--server=http://k3s-master-1:6443",
162 ] 199 ]
200 environment:
201 <<: *_x-k3s-agent-env
202 K3S_NODE_NAME: master-3
163 203
164 k3s-coredns-1: 204 k3s-coredns-1:
165 <<: *_x-coredns-base 205 <<: *_x-coredns-base
...@@ -174,15 +214,19 @@ services: ...@@ -174,15 +214,19 @@ services:
174 <<: *_x-k3s-agent-base 214 <<: *_x-k3s-agent-base
175 command: [ 215 command: [
176 "agent", 216 "agent",
177 "--with-node-id",
178 ] 217 ]
218 environment:
219 <<: *_x-k3s-agent-env
220 K3S_NODE_NAME: agent-1
179 221
180 k3s-agent-2: 222 k3s-agent-2:
181 <<: *_x-k3s-agent-base 223 <<: *_x-k3s-agent-base
182 command: [ 224 command: [
183 "agent", 225 "agent",
184 "--with-node-id",
185 ] 226 ]
227 environment:
228 <<: *_x-k3s-agent-env
229 K3S_NODE_NAME: agent-2
186 230
187 volumes: 231 volumes:
188 etcd1-data: 232 etcd1-data:
......
1 mirrors: 1 mirrors:
2 "registry.uniquely-me.local": 2 "registry.local":
3 endpoint: 3 endpoint:
4 - https://registry.uniquely-me.local 4 - https://registry.local
5 5
6 configs: 6 configs:
7 registry.uniquely-me.local: 7 registry.local:
8 tls: 8 tls:
9 ca_file: "/etc/ssl/certs/registry.crt" 9 ca_file: "/etc/ssl/certs/registry.crt"
......
1 #!/bin/bash 1 #!/bin/bash
2 2
3 CONTEXT_DIR="$TOP_DIR" 3 CONTEXT_DIR="$APISERVER_DIR"
4 4
5 declare -a args 5 declare -a args
6 declare -A features=( 6 declare -A features=(
7 [cert-manager]=1 7 [cert-manager]=1
8 [istio]=1 8 [istio]=1
9 ) 9 )
10 declare -a compose_files=(-f "$APISERVER_DIR/docker-compose.yaml")
11 declare -a k8s_nodes=()
10 12
11 while [[ $# -gt 0 ]]; do 13 while [[ $# -gt 0 ]]; do
12 arg="$1" 14 arg="$1"
...@@ -24,6 +26,14 @@ while [[ $# -gt 0 ]]; do ...@@ -24,6 +26,14 @@ while [[ $# -gt 0 ]]; do
24 features[$1]= 26 features[$1]=
25 shift 27 shift
26 ;; 28 ;;
29 (-f)
30 compose_files+=(-f "$1")
31 shift
32 ;;
33 (-n)
34 k8s_nodes+=("$1")
35 shift
36 ;;
27 (*) 37 (*)
28 args+=("$arg") 38 args+=("$arg")
29 ;; 39 ;;
...@@ -41,3 +51,7 @@ for feature in "${!features[@]}"; do ...@@ -41,3 +51,7 @@ for feature in "${!features[@]}"; do
41 done 51 done
42 52
43 export CONTEXT_DIR 53 export CONTEXT_DIR
54
55 _compose() {
56 docker-compose --project-directory "$CONTEXT_DIR" "${compose_files[@]}" "$@"
57 }
......
...@@ -4,9 +4,14 @@ set -e ...@@ -4,9 +4,14 @@ set -e
4 TOP_DIR="$(cd "$(dirname "$0")/.."; echo "$PWD")" 4 TOP_DIR="$(cd "$(dirname "$0")/.."; echo "$PWD")"
5 export TOP_DIR 5 export TOP_DIR
6 6
7 COREDNS_IP_1=$(docker-compose -f "$TOP_DIR/docker-compose.yaml" exec -T k3s-master-1 ping -c 1 -q k3s-coredns-1 | sed -n 's/^PING.*(\(.*\)).*/\1/p') 7 CONTEXT_DIR="$1"
8 COREDNS_IP_2=$(docker-compose -f "$TOP_DIR/docker-compose.yaml" exec -T k3s-master-1 ping -c 1 -q k3s-coredns-2 | sed -n 's/^PING.*(\(.*\)).*/\1/p') 8 _compose() {
9 COREDNS_IP_3=$(docker-compose -f "$TOP_DIR/docker-compose.yaml" exec -T k3s-master-1 ping -c 1 -q k3s-coredns-3 | sed -n 's/^PING.*(\(.*\)).*/\1/p') 9 docker-compose --project-directory "$CONTEXT_DIR" -f "$TOP_DIR/docker-compose.yaml" "$@"
10 }
11
12 COREDNS_IP_1=$(_compose exec -T k3s-master-1 ping -c 1 -q k3s-coredns-1 | sed -n 's/^PING.*(\(.*\)).*/\1/p')
13 COREDNS_IP_2=$(_compose exec -T k3s-master-1 ping -c 1 -q k3s-coredns-2 | sed -n 's/^PING.*(\(.*\)).*/\1/p')
14 COREDNS_IP_3=$(_compose exec -T k3s-master-1 ping -c 1 -q k3s-coredns-3 | sed -n 's/^PING.*(\(.*\)).*/\1/p')
10 15
11 kubectl apply -f /dev/stdin << _EOF_ 16 kubectl apply -f /dev/stdin << _EOF_
12 apiVersion: v1 17 apiVersion: v1
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
2 2
3 set -e 3 set -e
4 4
5 TOP_DIR="$(cd "$(dirname "$0")/.."; echo "$PWD")" 5 APISERVER_DIR="$(cd "$(dirname "$0")/.."; echo "$PWD")"
6 export TOP_DIR 6 export APISERVER_DIR
7 7
8 . "$TOP_DIR/scripts/_parse_args.bash" 8 . "$APISERVER_DIR/scripts/_parse_args.bash"
9 9
10 case "$1" in 10 case "$1" in
11 (switch-to) 11 (switch-to)
12 "$TOP_DIR/scripts/update-docker-kubeconfig.sh" "$CONTEXT_DIR" 12 "$APISERVER_DIR/scripts/update-docker-kubeconfig.sh" "$CONTEXT_DIR"
13 exit 13 exit
14 ;; 14 ;;
15 ("") 15 ("")
...@@ -20,23 +20,22 @@ case "$1" in ...@@ -20,23 +20,22 @@ case "$1" in
20 ;; 20 ;;
21 esac 21 esac
22 22
23 "$TOP_DIR/scripts/ensure-certs.sh" 23 "$APISERVER_DIR/scripts/ensure-certs.sh"
24 "$TOP_DIR/scripts/wait-for-etcd.sh" 24 "$APISERVER_DIR/scripts/wait-for-etcd.sh" "$CONTEXT_DIR"
25 25
26 docker-compose -f "$TOP_DIR/docker-compose.yaml" up -d k3s-master-1 26 _compose up -d k3s-master-1
27 "$TOP_DIR/scripts/update-docker-kubeconfig.sh" "$CONTEXT_DIR" 27 "$APISERVER_DIR/scripts/update-docker-kubeconfig.sh" "$CONTEXT_DIR"
28 "$TOP_DIR/scripts/wait-for-master-1.sh" 28 "$APISERVER_DIR/scripts/wait-for-master-1.sh"
29 29
30 docker-compose -f "$TOP_DIR/docker-compose.yaml" up -d k3s-coredns-1 k3s-coredns-2 k3s-coredns-3 30 _compose up -d k3s-coredns-1 k3s-coredns-2 k3s-coredns-3
31 "$TOP_DIR/scripts/install-cluster-dns.sh" 31 "$APISERVER_DIR/scripts/install-cluster-dns.sh" "$CONTEXT_DIR"
32 docker-compose -f "$TOP_DIR/docker-compose.yaml" up -d k3s-agent-1 k3s-agent-2 32 _compose up -d k3s-agent-1 k3s-agent-2 k3s-storage-1 "${k8s_nodes[@]}"
33 docker-compose -f "$TOP_DIR/docker-compose.yaml" up -d k3s-master-2 k3s-master-3 33 _compose up -d k3s-master-2 k3s-master-3
34 "$TOP_DIR/scripts/wait-for-system-pods.sh" 2 34 "$APISERVER_DIR/scripts/wait-for-system-pods.sh" 1
35 #_compose up -d k3s-proxy
35 36
36 #docker-compose -f "$TOP_DIR/docker-compose.yaml" up -d k3s-proxy 37 #[[ ${features[istio]} ]] && istioctl install -yf "$APISERVER_DIR/istio-minimal-operator.yaml"
37 38
38 #[[ ${features[istio]} ]] && istioctl install -yf "$TOP_DIR/istio-minimal-operator.yaml" 39 cd "$APISERVER_DIR"
39
40 cd "$TOP_DIR"
41 40
42 #helmfile apply 41 #helmfile apply
......
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
2 2
3 set -e 3 set -e
4 4
5 TOP_DIR="$(cd "$(dirname "$0")/.."; echo "$PWD")" 5 APISERVER_DIR="$(cd "$(dirname "$0")/.."; echo "$PWD")"
6 export TOP_DIR 6 export APISERVER_DIR
7 7
8 . "$TOP_DIR/scripts/_parse_args.bash" 8 . "$APISERVER_DIR/scripts/_parse_args.bash"
9 9
10 docker-compose -f "$TOP_DIR/docker-compose.yaml" down "$@" 10 _compose down "$@"
11 11
......
...@@ -7,6 +7,12 @@ CONTEXT_DIR="$1" ...@@ -7,6 +7,12 @@ CONTEXT_DIR="$1"
7 TOP_DIR="$(cd "$(dirname "$0")/.."; echo "$PWD")" 7 TOP_DIR="$(cd "$(dirname "$0")/.."; echo "$PWD")"
8 export TOP_DIR 8 export TOP_DIR
9 9
10 CONTEXT_DIR="$1"
11
12 _compose() {
13 docker-compose --project-directory "$CONTEXT_DIR" -f "$TOP_DIR/docker-compose.yaml" "$@"
14 }
15
10 tmpd="$(mktemp -d)" 16 tmpd="$(mktemp -d)"
11 onexit() { 17 onexit() {
12 [[ $tmpd ]] && rm -rf "$tmpd" 18 [[ $tmpd ]] && rm -rf "$tmpd"
...@@ -18,7 +24,7 @@ trap onexit EXIT ...@@ -18,7 +24,7 @@ trap onexit EXIT
18 24
19 declare -i count=10 25 declare -i count=10
20 while [[ $count > 0 ]]; do 26 while [[ $count > 0 ]]; do
21 if docker-compose -f "$TOP_DIR/docker-compose.yaml" exec -T k3s-master-1 cat /output/kubeconfig.yaml > "$tmpd/config.docker" 2>/dev/null; then 27 if _compose exec -T k3s-master-1 cat /output/kubeconfig.yaml > "$tmpd/config.docker" 2>/dev/null; then
22 break 28 break
23 fi 29 fi
24 sleep 1 30 sleep 1
...@@ -26,7 +32,7 @@ while [[ $count > 0 ]]; do ...@@ -26,7 +32,7 @@ while [[ $count > 0 ]]; do
26 done 32 done
27 chmod 600 "$tmpd/config.docker" 33 chmod 600 "$tmpd/config.docker"
28 34
29 MASTER_IP=$(docker-compose -f "$TOP_DIR/docker-compose.yaml" exec -T k3s-master-1 ping -c 1 -q k3s-master-1 | sed -n 's/^PING.*(\(.*\)).*/\1/p') 35 MASTER_IP=$(_compose exec -T k3s-master-1 ping -c 1 -q k3s-master-1 | sed -n 's/^PING.*(\(.*\)).*/\1/p')
30 36
31 kubectl config --kubeconfig="$tmpd/config.docker" view --raw=true -o jsonpath='{.clusters[].cluster.certificate-authority-data}' | base64 -d > "$tmpd/cluster-certificate-authority" 37 kubectl config --kubeconfig="$tmpd/config.docker" view --raw=true -o jsonpath='{.clusters[].cluster.certificate-authority-data}' | base64 -d > "$tmpd/cluster-certificate-authority"
32 kubectl config --kubeconfig="$tmpd/config.docker" view --raw=true -o jsonpath='{.users[].user.client-certificate-data}' | base64 -d > "$tmpd/client-certificate" 38 kubectl config --kubeconfig="$tmpd/config.docker" view --raw=true -o jsonpath='{.users[].user.client-certificate-data}' | base64 -d > "$tmpd/client-certificate"
......
...@@ -5,21 +5,22 @@ set -e ...@@ -5,21 +5,22 @@ set -e
5 TOP_DIR="$(cd "$(dirname "$0")/.."; echo "$PWD")" 5 TOP_DIR="$(cd "$(dirname "$0")/.."; echo "$PWD")"
6 export TOP_DIR 6 export TOP_DIR
7 7
8 CONTEXT_DIR="$1"
8 ETCD_ENDPOINTS="http://etcd1:2380,http://etcd2:2380,http://etcd3:2380" 9 ETCD_ENDPOINTS="http://etcd1:2380,http://etcd2:2380,http://etcd3:2380"
9 10
10 docker_compose() { 11 _compose() {
11 docker-compose -f "$TOP_DIR/docker-compose.yaml" "$@" 12 docker-compose --project-directory "$CONTEXT_DIR" -f "$TOP_DIR/docker-compose.yaml" "$@"
12 } 13 }
13 14
14 etcdctl() { 15 etcdctl() {
15 docker_compose exec etcd1 etcdctl "$@" 16 _compose exec etcd1 etcdctl "$@"
16 } 17 }
17 18
18 cnt=5 19 cnt=5
19 printf 'Waiting for etcd cluster: ' 20 printf 'Waiting for etcd cluster: '
20 21
21 while [ $cnt -ne 0 ]; do 22 while [ $cnt -ne 0 ]; do
22 docker_compose up -d etcd1 etcd2 etcd3 1>/dev/null 2>/dev/null 23 _compose up -d etcd1 etcd2 etcd3 1>/dev/null 2>/dev/null
23 if etcdctl --endpoints "$ETCD_ENDPOINTS" endpoint health 1>/dev/null 2>/dev/null; then 24 if etcdctl --endpoints "$ETCD_ENDPOINTS" endpoint health 1>/dev/null 2>/dev/null; then
24 if [ $cnt -ne 5 ]; then 25 if [ $cnt -ne 5 ]; then
25 printf ' ' 26 printf ' '
......