-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathprovision-digitalocean-controller.sh
More file actions
executable file
·117 lines (98 loc) · 3.16 KB
/
provision-digitalocean-controller.sh
File metadata and controls
executable file
·117 lines (98 loc) · 3.16 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env bash
#
# Usage: ./provision-digitalocean-controller.sh <region-id>
#
# Retrieve the region-id by using `knife digital_ocean region list`
#
if [[ -z $1 ]]; then
echo usage: $0 [region]
exit 1
fi
function echo_color {
echo -e "\033[1m$1\033[0m"
}
THIS_DIR=$(cd $(dirname $0); pwd) # absolute path
CONTRIB_DIR=$(dirname $THIS_DIR)
# check for Deis' general dependencies
if ! $CONTRIB_DIR/check-deis-deps.sh; then
echo 'Deis is missing some dependencies.'
exit 1
fi
# connection details for using digital ocean's API
client_id=$DIGITALOCEAN_CLIENT_ID
api_key=$DIGITALOCEAN_API_KEY
# Check that client ID and API key was set
if test -z $client_id; then
echo "Please add your client id to ${knife_file}."
fi
if test -z $api_key; then
echo "Please add your api key to ${knife_file}."
fi
#################
# chef settings #
#################
node_name=deis-controller
run_list="recipe[deis::controller]"
chef_version=11.6.2
#########################
# digitalocean settings #
#########################
# the name of the location we want to work with
region_id=$1
# The snapshot that we want to use (deis-base)
image_id=$(knife digital_ocean image list | grep "deis-base" | awk '{print $1}')
# the ID of the size (1GB)
size_id=$(knife digital_ocean size list | grep "2GB" | awk '{print $1}')
if [[ -z $image_id ]]; then
echo "Can't find saved image \"deis-base\" in region $region_id. Please follow the"
echo "instructions in prepare-digitalocean-snapshot.sh before provisioning a Deis controller."
exit 1
fi
if [[ -z $size_id ]]; then
echo "Cannot find a droplet with the size '2GB' in region $region_id."
exit 1
fi
################
# SSH settings #
################
key_name=deis-controller
ssh_key_path=~/.ssh/$key_name
# create ssh keypair and store it
if ! test -e $ssh_key_path; then
echo_color "Creating new SSH key: $key_name"
set -x
ssh-keygen -f $ssh_key_path -t rsa -N '' -C "deis-controller" >/dev/null
curl -X GET \
--data-urlencode "name=$node_name" \
--data-urlencode "ssh_pub_key=$(cat $ssh_key_path.pub)" \
--data-urlencode "client_id=$client_id" \
--data-urlencode "api_key=$api_key" \
https://api.digitalocean.com/ssh_keys/new
ssh-add $ssh_key_path
set +x
echo_color "Saved to $ssh_key_path"
else
echo_color "WARNING: SSH key $ssh_key_path exists, skipping upload"
fi
# get the id of the SSH key that we just uploaded
ssh_key_id=$(knife digital_ocean sshkey list | grep "$key_name" | awk '{print $1}')
# create data bags
knife data bag create deis-users 2>/dev/null
knife data bag create deis-formations 2>/dev/null
knife data bag create deis-apps 2>/dev/null
# trigger digital ocean instance bootstrap
echo_color "Provisioning $node_name with knife digital_ocean..."
set -x
knife digital_ocean droplet create \
--bootstrap-version $chef_version \
--server-name $node_name \
--image $image_id \
--location $region_id \
--size $size_id \
--ssh-keys $ssh_key_id \
--identity-file $ssh_key_path \
--bootstrap \
--run-list $run_list
set +x
# Need Chef admin permission in order to add and remove nodes and clients
echo -e "\033[35mPlease ensure that \"deis-controller\" is added to the Chef \"admins\" group.\033[0m"