-
Notifications
You must be signed in to change notification settings - Fork 52
/
elixir-stack.sh
114 lines (86 loc) · 2.12 KB
/
elixir-stack.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env sh
app_name=$(grep -m 1 -oh 'app: :[[:alnum:]_]*' mix.exs | sed 's/app:\ ://')
git_repo_url=$(git config --get remote.origin.url)
mkdir -p playbooks/vars playbooks/templates
cat > playbooks/setup.yml <<EOF
---
- hosts: app-servers
remote_user: root
vars_files:
- vars/main.yml
roles:
- {role: "HashNuke.elixir-stack", action: "setup"}
EOF
cat > playbooks/deploy.yml <<EOF
---
- hosts: app-servers
remote_user: root
vars_files:
- vars/main.yml
roles:
- {role: "HashNuke.elixir-stack", action: "deploy"}
EOF
cat > playbooks/migrate.yml <<EOF
---
- hosts: app-servers
remote_user: root
vars_files:
- vars/main.yml
roles:
- {role: "HashNuke.elixir-stack", action: "migrate"}
EOF
cat > playbooks/remove-app.yml <<EOF
---
- hosts: app-servers
remote_user: root
vars_files:
- vars/main.yml
roles:
- {role: "HashNuke.elixir-stack", action: "remove-app"}
EOF
cat > inventory <<EOF
[app-servers]
1.2.3.4
4.5.6.7
# Delete the above IP addresses and add your server's IP addresses
EOF
cat > ansible.cfg <<EOF
[defaults]
inventory=inventory
[ssh_connection]
ssh_args="-o ForwardAgent=yes"
EOF
cat > playbooks/vars/main.yml <<EOF
---
app_name: $app_name
repo_url: "$git_repo_url"
app_port: 3001
EOF
# Check if SERVER=1 when starting release.
# This way we can compile the release with auto-start server
# But for all other purposes, can run mix tasks
grep -m 1 -nriq "{:phoenix" mix.exs
if [ $? = 0 ]; then
cat >> config/config.exs <<EOF
# This line was automatically added by ansible-elixir-stack setup script
if System.get_env("SERVER") do
config :phoenix, :serve_endpoints, true
end
EOF
fi
echo
echo '*-*-*'
echo 'Oolaa ~! your project has been setup for deployment'
echo '*-*-*'
echo
# Create .tool-versions file if not present
if [ ! -f ./.tool-versions ]; then
cat > .tool-versions <<EOF
erlang 18.0
elixir 1.0.5
nodejs 0.12.5
EOF
echo "TODO Edit .tool-versions file with appropriate versions of Erlang, Elixir & Node.js required for project"
fi
echo "TODO Add server IP address to inventory file"
echo "TODO Edit app name, app port & repo url in playbooks/vars/main.yml"