-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathprovision-controller.sh
More file actions
executable file
·125 lines (105 loc) · 3.43 KB
/
provision-controller.sh
File metadata and controls
executable file
·125 lines (105 loc) · 3.43 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
118
119
120
121
122
123
124
125
#!/usr/bin/env bash
#
# Usage: ./provision-vagrant-controller.sh
#
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
# Make sure SSHD is installed
# TODO: Better SSH server detection
if [ ! -f /etc/ssh/sshd_config ] && [ ! -f /etc/sshd_config ]; then
echo 'Please install an SSH server'
exit 1
fi
# Make sure avahi-daemon is installed and running
if [[ `uname -s` =~ Linux ]]; then
if ! pgrep avahi-daemon >/dev/null; then
echo 'Please install avahi-daemon to broadcast your hostname to the local network.'
exit 1
fi
fi
#################
# chef settings #
#################
node_name=deis-controller
run_list="recipe[deis::controller]"
chef_version=11.6.2
################
# SSH settings #
################
ssh_key_path=~/.vagrant.d/insecure_private_key
ssh_user="vagrant"
ssh_port="22"
# 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
# Boot the deis-controller VM
echo_color "Booting $node_name with 'vagrant up'"
pushd $THIS_DIR/../../
vagrant up --provision
if [ $? -gt 0 ]; then
echo_color "Canceling provision because 'vagrant up' failed"
exit 1
fi
# Add the Controller's public SSH key to user's machine. This allows the Controller to
# issue vagrant commands on the host machine.
read -p "Add the Deis Controller's SSH key to your authorized_keys file? " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then #TODO: Might be nice to have flag to make manual confirmation optional?
# Create an SSH key pair for the deis user
vagrant ssh -c "
if [ ! -f ~/.ssh/id_rsa ]; then
ssh-keygen -t rsa -N \"\" -f ~/.ssh/id_rsa
chmod a+r ~/.ssh/id_rsa # Not strictly best practice, but the deis user needs to be able to read it
fi"
# Copy the created key over to your local machine
scp \
-P22 \
-o IdentityFile=$ssh_key_path \
'vagrant@deis-controller.local:/home/vagrant/.ssh/id_rsa.pub' \
'/tmp/vagrant_key'
KEY=$(cat /tmp/vagrant_key)
if [ ! -n "$KEY" ]; then
echo_color "Aborting. No SSH key copied from the Deis Controller"
exit 1
fi
if [ -z "$(grep "$KEY" ~/.ssh/authorized_keys )" ]; then
echo $KEY >> ~/.ssh/authorized_keys;
echo_color "Key added."
else
echo_color "Key already added."
fi
fi
echo_color "Provisioning $node_name with knife vagrant..."
set -x
knife bootstrap "$node_name.local" \
--bootstrap-version $chef_version \
--ssh-user $ssh_user \
--ssh-port $ssh_port \
--identity-file $ssh_key_path \
--node-name $node_name \
--run-list $run_list \
--sudo
set +x
echo_color "Updating Django site object from 'example.com' to 'deis-controller'..."
vagrant ssh -c "sudo su deis -c \"psql deis -c \\\" \
UPDATE django_site \
SET domain = 'deis-controller.local', \
name = 'deis-controller.local' \
WHERE id = 1 \\\"\"" >/dev/null
if [ $? -eq 0 ]; then
echo_color "Site object updated."
fi
popd
echo_color "Setting devmode flag on 'deis-controller'..."
knife exec -E 'nodes.transform("name:deis-controller") {|n| n.normal_attrs["deis"]["devmode"] = true; n.save }'
# 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"