diff --git a/stack-brew.py b/stack-brew.py new file mode 100644 index 0000000..015f151 --- /dev/null +++ b/stack-brew.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 +import yaml +import sys +import netifaces as ni + +ni.ifaddresses('en0') +ip = ni.ifaddresses('en0')[ni.AF_INET][0]['addr'] + +# List of clients +CLIENTS = ['flask', 'vue', 'rubyonrails'] + +# docker-compose.yml skeleton to fill out using "service" entries above. +COMPOSITION = {'version': '3', 'services': {}} + +if __name__ == '__main__': + + error_clients = [] + error_services = [] + installation_path = sys.argv[1] + args = sys.argv[2:] + args = list(dict.fromkeys(args)) + + services = [x for x in args if x not in CLIENTS] + clients = [x for x in args if x in CLIENTS] + + # Loads the master yaml containing docker service definitions + with open(installation_path+'/master.yaml') as master_service_file: + master_services = yaml.load(master_service_file, Loader=yaml.FullLoader) + + # Populates clients in docker-compose + for client in clients: + if client in master_services: + COMPOSITION['services'][client] = master_services[client] + COMPOSITION['services'][client]['depends_on'] = [] + else: + error_clients.append(client) + CLIENTS.remove(client) + + # Populates services requested by user + for service in services: + if service in master_services: + for client in clients: + COMPOSITION['services'][client]['depends_on'].append(service) + COMPOSITION['services'][service] = master_services[service] + else: + error_services.append(service) + if service == 'kafka': + COMPOSITION['services'][service]['environment']['KAFKA_ADVERTISED_HOST_NAME'] = ip + + with open(installation_path+'docker-compose.yml', 'w') as outfile: + yaml.dump(COMPOSITION, outfile, default_flow_style=False, indent=2) + + if len(error_services) > 0: + print("Couldn't add the following services: ") + for service in error_services: + print("- " + service + "\n") diff --git a/stackbox-brew.sh b/stackbox-brew.sh index 2bb6166..f2156be 100644 --- a/stackbox-brew.sh +++ b/stackbox-brew.sh @@ -7,6 +7,7 @@ echo "\__ \ || (_| | (__| <| |_) | (_) > <" echo '|___/\__\__,_|\___|_|\_\_.__/ \___/_/\_\' printf "\n" echo "######## SELECT YOUR STACK #############" +printf "\n" stack=() installationPath=$(brew --cellar stackbox)/$(brew info --json stackbox | jq -r '.[0].installed[0].version') @@ -28,6 +29,7 @@ do esac done +printf "\n" PS3='Select your backend: ' echo "BACKEND OPTIONS:" @@ -112,11 +114,11 @@ python3_version=$(python3 --version) if beginswith "Python 3" "$python_version" ; then var="$(pip --disable-pip-version-check install -r $installationPath/requirements.txt) > /dev/null " - python $installationPath/stack.py ${stack[*]} + python $installationPath/stack.py $installationPath ${stack[*]} elif beginswith "Python 3" "$python3_version"; then var="$(pip3 --disable-pip-version-check install -r $installationPath/requirements.txt) > /dev/null" - python3 $installationPath/stack.py ${stack[*]} + python3 $installationPath/stack.py $installationPath ${stack[*]} else echo "Unable to find a python 3 installation" fi @@ -133,6 +135,7 @@ sleep 5 printf "\n" echo "######## YOUR STACK ########################" +printf "\n" containers=$(docker ps --format '{{.Names}}') ports="$(docker ps --format '{{.Ports}}')" @@ -165,6 +168,7 @@ done printf "\n" echo "######## SETTING YOUR CODE DIRECTORY #############" +printf "\n" mkdir stackbox cp -r $installationPath/. stackbox/