-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathprovision-vagrant-controller.sh
More file actions
executable file
·132 lines (110 loc) · 3.65 KB
/
provision-vagrant-controller.sh
File metadata and controls
executable file
·132 lines (110 loc) · 3.65 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
126
127
128
129
130
131
132
#!/usr/bin/env bash
#
# Usage: ./provision-vagrant-controller.sh
#
set -e
function echo_color {
echo -e "\033[1m$1\033[0m"
}
THIS_DIR="$(cd $(dirname $0); pwd)" # absolute path
CONTRIB_DIR=$(dirname "$THIS_DIR")
CODE_BASE_DIR=$(dirname "$CONTRIB_DIR/../../")
# For those upgrading from the pre-containerize branch, they may still have some redundant files
# in their code base.
if [ -h $CODE_BASE_DIR/deis/local_settings.py ]; then
echo "Removing old local_settings symlink"
rm $CODE_BASE_DIR/deis/local_settings.py
rm $CODE_BASE_DIR/deis/local_settings.pyc
fi
echo_color "Checking for Deis dependencies..."
# 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
echo_color "Ensuring submodules are cloned and up to date..."
# Ensure all submodules are cloned and up to date
git submodule init && git submodule update
#################
# chef settings #
#################
node_name=deis-controller
run_list="recipe[deis::controller]"
chef_version=11.8.2
################
# SSH settings #
################
ssh-keygen -R "$node_name.local"
ssh_key_path=~/.vagrant.d/insecure_private_key
ssh_user="vagrant"
ssh_port="22"
echo_color "Creating knife data bags..."
# create data bags
# 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
# 'deis provider:discover' detects the host machine's user and IP address, however, that command cannot
# be guareteed to run inside the deis codebase. Therefore we can't use that opportunity to discover
# the path of the codebase on the host machine. Therefore we do it now as this script has to exist
# inside the codebase.
nodes_dir="$CONTRIB_DIR/vagrant/nodes"
nodes_path_file="$CONTRIB_DIR/vagrant/.host_nodes_dir"
echo $nodes_dir > $nodes_path_file
# Add the Controller's public SSH key to user's machine. This allows the Controller to
# issue vagrant commands on the host machine.
echo_color "Ensuring presence of Controller's public key in your ~/.ssh/authorized_keys file..."
KEY=$(cat util/ssh_keys/id_rsa_vagrant-deis-controller.pub)
if [ -z "$(grep "$KEY" ~/.ssh/authorized_keys )" ]; then
echo $KEY >> ~/.ssh/authorized_keys;
echo_color "Key added."
else
echo_color "Key already added."
fi
chef_json=$(echo '
{
"deis": {
"public_ip": "192.168.61.100",
"dev": {
"mode": true,
"source": "/vagrant"
}
}
}' | tr '\n' ' ')
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 \
--json-attributes "$chef_json" \
--sudo
set +x
echo_color "Running post chef run setup..."
vagrant ssh -c '/vagrant/contrib/vagrant/util/_post_chef_run.sh'
popd
# 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"
set +e