|
1 | 1 | #!/bin/sh |
| 2 | +## depends on docker client, curl, docker-machine + docker-machine-driver-scaleway, jq |
| 3 | + |
| 4 | + |
| 5 | +# looking for existing rancher-server |
| 6 | +if docker-machine inspect rancher-server >/dev/null; then |
| 7 | + echo "[-] rancher-server already exists." |
| 8 | + echo " you need to remove your previous rancher machines from docker-machine before running this script." |
| 9 | + exit 1 |
| 10 | +fi |
| 11 | + |
| 12 | + |
| 13 | +set -xe |
| 14 | +SLAVES=3 |
| 15 | + |
2 | 16 |
|
3 | 17 | # create a machine for the Rancher server |
4 | | -docker-machine create -d scaleway --scaleway-name=rancher-server rancher-server || exit 1 |
| 18 | +docker-machine create -d scaleway --scaleway-name=rancher-server rancher-server |
| 19 | + |
5 | 20 |
|
6 | 21 | # configure shell to use rancher-server |
7 | 22 | eval $(docker-machine env rancher-server) |
8 | 23 |
|
9 | | -# create a machine for a Rancher host |
10 | | -docker-machine create -d scaleway --scaleway-name=rancher-host-1 rancher-host-1 || exit 1 & |
| 24 | + |
| 25 | +# create machines for a Rancher host (slaves) |
| 26 | +for i in $(seq 1 ${SLAVES}); do |
| 27 | + docker-machine create -d scaleway --scaleway-name=rancher-host-$i rancher-host-$i & |
| 28 | +done |
| 29 | + |
11 | 30 |
|
12 | 31 | # start a Rancher Server on rancher-server |
13 | | -docker run -d --restart=always -p 8080:8080 rancher/server || exit 1 |
| 32 | +docker run -d --restart=always -p 8080:8080 rancher/server |
| 33 | +( |
| 34 | + set +xe |
| 35 | + false |
| 36 | + while [ "$?" != "0" ] |
| 37 | + do |
| 38 | + # wait for Rancher Server installation |
| 39 | + docker logs $(docker ps -q) | grep "Startup Succeeded" |
| 40 | + done |
| 41 | +) |
14 | 42 |
|
15 | | -false |
16 | | -while [ "$?" != "0" ] |
17 | | -do |
18 | | - # wait for Rancher Server installation |
19 | | - docker logs $(docker ps -q) | grep "Startup Succeeded" |
20 | | -done |
21 | 43 |
|
22 | 44 | # wait for background tasks |
23 | | -wait `jobs -p` || true |
| 45 | +wait `jobs -p`; sleep 10 |
24 | 46 |
|
25 | | -IP=$(docker-machine ip rancher-server) |
26 | 47 |
|
27 | | -sleep 10 |
28 | 48 |
|
29 | 49 | # generate a token |
30 | | -curl 'http://'$IP':8080/v1/registrationtoken' -H 'x-api-project-id: 1a5' -H 'Accept: application/json' --data-binary '{"type":"registrationToken"}' --compressed > /dev/null |
| 50 | +RANCHER_IP=$(docker-machine ip rancher-server) |
| 51 | +curl "http://${RANCHER_IP}:8080/v1/registrationtoken" \ |
| 52 | + -H 'x-api-project-id: 1a5' \ |
| 53 | + -H 'Accept: application/json' \ |
| 54 | + --data-binary '{"type":"registrationToken"}' \ |
| 55 | + --compressed > /dev/null |
31 | 56 | sleep 5 |
32 | | -CMD=$(curl 'http://'$IP':8080/v1/registrationtokens?state=active&limit=-1' -H 'x-api-project-id: 1a5' -H 'Accept: application/json' --compressed | jq '.data[0].command' | sed 's/sudo//g' | tr -d '"') |
| 57 | + |
33 | 58 |
|
34 | 59 | # start a Rancher Agent on rancher-server |
35 | | -$CMD || exit 1 |
| 60 | +AGENT_CMD=$( |
| 61 | + curl "http://${RANCHER_IP}:8080/v1/registrationtokens?state=active&limit=-1" -H 'x-api-project-id: 1a5' -H 'Accept: application/json' --compressed \ |
| 62 | + | jq -r '.data[0].command' \ |
| 63 | + | sed 's/sudo//g' |
| 64 | + ) |
| 65 | +${AGENT_CMD} |
| 66 | + |
36 | 67 |
|
37 | | -# configure shell to use rancher-host-1 |
38 | | -eval $(docker-machine env rancher-host-1) |
| 68 | +# start a Rancher Agent on rancher-host-X (slaves) |
| 69 | +for i in $(seq 1 ${SLAVES}); do |
| 70 | + eval $(docker-machine env rancher-host-$i) |
| 71 | + ${AGENT_CMD} |
| 72 | +done |
39 | 73 |
|
40 | | -# start a Rancher Agent on rancher-host-1 |
41 | | -$CMD || exit 1 |
42 | 74 |
|
43 | | -echo "Open your browser at http://"$IP":8080" |
| 75 | +echo "Open your browser at http://${RANCHER_IP}:8080" |
0 commit comments