-
Notifications
You must be signed in to change notification settings - Fork 8
/
local_dev.sh
99 lines (87 loc) · 2.24 KB
/
local_dev.sh
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
#!/bin/bash
function install_system_packages {
apt-get update
apt-get install -y graphviz \
ruby \
ruby-dev \
libsqlite3-dev \
build-essential \
libmysqlclient-dev \
nodejs
}
function install_terraform {
if [ -f /usr/bin/terraform ]
then
echo "Terraform already installed"
echo "$(/usr/bin/terraform -version)"
else
wget --quiet https://releases.hashicorp.com/terraform/0.9.5/terraform_0.9.5_linux_amd64.zip
unzip terraform_0.9.5_linux_amd64.zip -d /usr/bin/
fi
}
function install_gems {
gem install bundler puma
pushd /vagrant || exit
bundle install
if [ -f /vagrant/db/development.sqlite3 ]
then
echo ""
echo "/vagrant/db/development.sqlite3 already exists. Remove and re-run 'vagrant provision' if you want to re-create"
echo ""
else
bundle exec rake db:setup
fi
popd
}
function setup_systemd {
cat << EOF > /etc/systemd/system/tfsoa.service
[Unit]
Description=TFSOA server
After=network.target
[Service]
ExecStart=/usr/local/bin/puma
WorkingDirectory=/vagrant
Restart=always
Type=simple
[Install]
WantedBy=multi-user.target
Alias=tfsoa.service
EOF
/bin/systemctl daemon-reload
/bin/systemctl restart tfsoa
sleep 6
}
function setup_test_states_and_graphs {
echo "Submit test Terraform states..."
curl 127.0.0.1:9292/tfsoa/add_tf_state/example_team_1/product1/example1/dev/ \
--silent \
-H "Content-Type: application/json" \
-X POST \
-d @/vagrant/test/fixtures/state1
curl 127.0.0.1:9292/tfsoa/add_tf_state/example_team_2/product2/example1/dev/ \
--silent \
-H "Content-Type: application/json" \
-X POST \
-d @/vagrant/test/fixtures/state1
pushd /vagrant/test/fixtures/tf_elb
/usr/bin/terraform graph -draw-cycles \
| curl -d @- \
http://127.0.0.1:9292/tfsoa/add_tf_graph/example_team_1/product1/example1/dev/ \
--silent
popd
pushd /vagrant/test/fixtures/tf_asg
/usr/bin/terraform graph -draw-cycles \
| curl -d @- \
http://127.0.0.1:9292/tfsoa/add_tf_graph/example_team_2/product2/example1/dev/ \
--silent
echo "Navigate to http://127.0.0.1:9292"
}
function main {
install_system_packages
install_terraform
install_gems
setup_systemd
setup_test_states_and_graphs
}
# entry point
main