Skip to content

Commit 0a56954

Browse files
authored
Merge pull request #43 from strangest-quark/master
Adding stack-brew.py #39
2 parents 5c76c68 + 59605ec commit 0a56954

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

stack-brew.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env python3
2+
import yaml
3+
import sys
4+
import netifaces as ni
5+
6+
ni.ifaddresses('en0')
7+
ip = ni.ifaddresses('en0')[ni.AF_INET][0]['addr']
8+
9+
# List of clients
10+
CLIENTS = ['flask', 'vue', 'rubyonrails']
11+
12+
# docker-compose.yml skeleton to fill out using "service" entries above.
13+
COMPOSITION = {'version': '3', 'services': {}}
14+
15+
if __name__ == '__main__':
16+
17+
error_clients = []
18+
error_services = []
19+
installation_path = sys.argv[1]
20+
args = sys.argv[2:]
21+
args = list(dict.fromkeys(args))
22+
23+
services = [x for x in args if x not in CLIENTS]
24+
clients = [x for x in args if x in CLIENTS]
25+
26+
# Loads the master yaml containing docker service definitions
27+
with open(installation_path+'/master.yaml') as master_service_file:
28+
master_services = yaml.load(master_service_file, Loader=yaml.FullLoader)
29+
30+
# Populates clients in docker-compose
31+
for client in clients:
32+
if client in master_services:
33+
COMPOSITION['services'][client] = master_services[client]
34+
COMPOSITION['services'][client]['depends_on'] = []
35+
else:
36+
error_clients.append(client)
37+
CLIENTS.remove(client)
38+
39+
# Populates services requested by user
40+
for service in services:
41+
if service in master_services:
42+
for client in clients:
43+
COMPOSITION['services'][client]['depends_on'].append(service)
44+
COMPOSITION['services'][service] = master_services[service]
45+
else:
46+
error_services.append(service)
47+
if service == 'kafka':
48+
COMPOSITION['services'][service]['environment']['KAFKA_ADVERTISED_HOST_NAME'] = ip
49+
50+
with open(installation_path+'docker-compose.yml', 'w') as outfile:
51+
yaml.dump(COMPOSITION, outfile, default_flow_style=False, indent=2)
52+
53+
if len(error_services) > 0:
54+
print("Couldn't add the following services: ")
55+
for service in error_services:
56+
print("- " + service + "\n")

stackbox-brew.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ echo "\__ \ || (_| | (__| <| |_) | (_) > <"
77
echo '|___/\__\__,_|\___|_|\_\_.__/ \___/_/\_\'
88
printf "\n"
99
echo "######## SELECT YOUR STACK #############"
10+
printf "\n"
1011

1112
stack=()
1213
installationPath=$(brew --cellar stackbox)/$(brew info --json stackbox | jq -r '.[0].installed[0].version')
@@ -28,6 +29,7 @@ do
2829
esac
2930
done
3031

32+
printf "\n"
3133
PS3='Select your backend: '
3234

3335
echo "BACKEND OPTIONS:"
@@ -112,11 +114,11 @@ python3_version=$(python3 --version)
112114
if beginswith "Python 3" "$python_version" ;
113115
then
114116
var="$(pip --disable-pip-version-check install -r $installationPath/requirements.txt) > /dev/null "
115-
python $installationPath/stack.py ${stack[*]}
117+
python $installationPath/stack.py $installationPath ${stack[*]}
116118
elif beginswith "Python 3" "$python3_version";
117119
then
118120
var="$(pip3 --disable-pip-version-check install -r $installationPath/requirements.txt) > /dev/null"
119-
python3 $installationPath/stack.py ${stack[*]}
121+
python3 $installationPath/stack.py $installationPath ${stack[*]}
120122
else
121123
echo "Unable to find a python 3 installation"
122124
fi
@@ -133,6 +135,7 @@ sleep 5
133135

134136
printf "\n"
135137
echo "######## YOUR STACK ########################"
138+
printf "\n"
136139

137140
containers=$(docker ps --format '{{.Names}}')
138141
ports="$(docker ps --format '{{.Ports}}')"
@@ -165,6 +168,7 @@ done
165168

166169
printf "\n"
167170
echo "######## SETTING YOUR CODE DIRECTORY #############"
171+
printf "\n"
168172

169173
mkdir stackbox
170174
cp -r $installationPath/. stackbox/

0 commit comments

Comments
 (0)