This repository has been archived by the owner on Jan 21, 2020. It is now read-only.
/
templates.go
65 lines (49 loc) · 1.67 KB
/
templates.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
const (
// DefaultManagerInitScriptTemplate is the default template for the init script which
// the flavor injects into the user data of the instance to configure Docker Swarm Managers
DefaultManagerInitScriptTemplate = `
#!/bin/sh
set -o errexit
set -o nounset
set -o xtrace
mkdir -p /etc/docker
cat << EOF > /etc/docker/daemon.json
{
"labels": {{ INFRAKIT_LABELS | to_json }}
}
EOF
{{/* Reload the engine labels */}}
kill -s HUP $(cat /var/run/docker.pid)
sleep 5
{{ if and ( eq INSTANCE_LOGICAL_ID SPEC.SwarmJoinIP ) (not SWARM_INITIALIZED) }}
{{/* The first node of the special allocations will initialize the swarm. */}}
docker swarm init --advertise-addr {{ INSTANCE_LOGICAL_ID }}
# Tell Docker to listen on port 4243 for remote API access. This is optional.
echo DOCKER_OPTS="\"-H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock\"" >> /etc/default/docker
# Restart Docker to let port listening take effect.
service docker restart
{{ else }}
{{/* The rest of the nodes will join as followers in the manager group. */}}
docker swarm join --token {{ SWARM_JOIN_TOKENS.Manager }} {{ SWARM_MANAGER_ADDR }}
{{ end }}
`
// DefaultWorkerInitScriptTemplate is the default template for the init script which
// the flavor injects into the user data of the instance to configure Docker Swarm.
DefaultWorkerInitScriptTemplate = `
#!/bin/sh
set -o errexit
set -o nounset
set -o xtrace
mkdir -p /etc/docker
cat << EOF > /etc/docker/daemon.json
{
"labels": {{ INFRAKIT_LABELS | to_json }}
}
EOF
# Tell engine to reload labels
kill -s HUP $(cat /var/run/docker.pid)
sleep 5
docker swarm join --token {{ SWARM_JOIN_TOKENS.Worker }} {{ SWARM_MANAGER_ADDR }}
`
)