<commit_before>#!/bin/bash

# A simple script to deploy Layers Box as set of docker containers
# Authors: <NAME>, <NAME>, <NAME> (RWTH Aachen University)

clear && 
echo "***** Layers Box - Basic Deployment Script *****" &&
echo "" &&

echo "It is mandatory to use BTRFS for the OpenStack Swift component. Checking Docker storage driver: " &&
HOST_FS=$(docker info | grep Storage | awk '{print $3}') &&
if [ HOST_FS==btrfs ]; then
  echo "The host system uses BTRFS. Proceeding with the Layers Box set-up." 
else
  echo "The host system uses a FS different than BTRFS! Ceasing Layers Box deployment." && exit 1
fi  &&
echo "This script will now deploy a Layers Box in a Docker-enabled environment step-by-step. After successful deployment, the Layers Box exposes its APIs and applications under the following URIs:" &&
echo && 

# set variables to be forwarded as environment variables to docker containers
LAYERS_API_URI="http://192.168.59.103/";
LAYERS_APP_URI="http://192.168.59.103/";
LAYERS_API_URL="http://192.168.59.103";

# block of environment variables set to Docker containers
# use for configuration of Layers Box
MYSQL_ROOT_PASSWORD="<PASSWORD>";
LDAP_URI="192.168.59.103";
LDAP_ROOT_PASSWORD="<PASSWORD>";
OIDC_MYSQL_DB="OpenIDConnect";
OIDC_MYSQL_USER="oidc";
MM_DB="mobsos_logs";
MM_USER="mobsos_monitor"; 
SHIPYARD_ADMIN_PASS="<PASSWORD>"; 
SWIFT_TENANT_NAME_NAME="tethysTenant";
SWIFT_USER_NAME_NAME="tethysUserStorage";
SWIFT_KEY="pass";
LDAP_ADMINS="koren;nicolaescu";

# Used for IP geolocation; get API key: http://ipinfodb.com/ip_location_api_json.php";
MM_IPINFODB_KEY="";

# Define alias for docker run including all environment variables that must be available to containers.
alias drenv='docker run -e "LAYERS_API_URI=$LAYERS_API_URI" -e "LAYERS_APP_URI=$LAYERS_APP_URI"';

echo ""
echo "Layers API URI: $LAYERS_API_URI";
echo "Layers App URI: $LAYERS_APP_URI";
echo ""

# Clean up: remove all docker containers first to avoid conflicts
echo "****************" &&
echo "** WARNING!!! **" &&
echo "****************" &&
echo "" &&
echo "To clean up the Layers Box host environment, all containers will be removed, including all data containers! Use backup.sh for a simple backup of all Layers Box data volume containers before you continue! (Press enter to continue)" && 
read # Comment interactive step for complete automation
 
echo "Removing all containers..." &&
docker rm -f $(docker ps -a -q);
echo " -> done" &&
echo "" && 

# start Layers Storage mysql data volume container
echo "Starting Layers Common Data Storage MySQL data volume container..." &&
drenv -e "MYSQL_ROOT_PASSWORD=$<PASSWORD>" --name mysql-data learninglayers/mysql-data &&
echo " -> done" &&
echo "" && 

# start Layers Storage mysql container
echo "Starting Layers Common Data Storage MySQL database server..." &&
drenv -d -p 3306:3306 -e "MYSQL_ROOT_PASSWORD=$<PASSWORD>" --volumes-from mysql-data --name mysql learninglayers/mysql &&
echo " -> done" &&
echo "" && 

echo "Waiting 4 seconds for MySql to start"
sleep 4

# start Layers Adapter data volume container
echo "Starting Layers Adapter data volume..." &&
drenv --name adapter-data learninglayers/adapter-data &&
echo " -> done" &&
echo "" && 

# start Layers Adapter
echo "Starting Layers Adapter..." &&
drenv -d -p 80:80 --volumes-from adapter-data --name adapter learninglayers/adapter &&
echo " -> done" &&
echo "" && 

# start Layers OpenLDAP data volume
echo "Starting Layers OpenLDAP data volume..." &&
docker run -e "LDAP_ROOT_PASSWORD=$LDAP_ROOT_PASSWORD" --name openldap-data learninglayers/openldap-data &&
echo " -> done" &&
echo "" && 

# start Layers OpenLDAP
echo "Starting Layers OpenLDAP..." &&
docker run -d -p 389:389 -e "LDAP_ROOT_PASSWORD=$LDAP_ROOT_PASSWORD" --volumes-from openldap-data --name openldap learninglayers/openldap &&
echo " -> done" &&
echo "" && 

# create OpenID Connect database and user
echo "Creating OpenID Connect database and user..." &&
OIDC_MYSQL_PASSWORD=`docker run --link mysql:mysql learninglayers/mysql-create -p$MYSQL_ROOT_PASSWORD --new-database $OIDC_MYSQL_DB --new-user $OIDC_MYSQL_USER | grep "mysql" | awk '{split($0,a," "); print a[3]}' | cut -c3-` &&
echo " -> done" &&
echo "" &&

# start OpenID Connect data volume (TODO: switch to DockerHub)
echo "Starting Layers OpenID Connect data volume..." &&
docker run -e "OIDC_MYSQL_USER=$OIDC_MYSQL_USER" -e "OIDC_MYSQL_PASSWORD=$OIDC_MYSQL_PASSWORD" -e "LAYERS_API_URI=$LAYERS_API_URL" -e "LDAP_DC=dc=layersbox" --name openidconnect-data learninglayers/openidconnect-data &&
echo " -> done" &&
echo "" && 

##updated to support default admin users
#docker run -e "OIDC_MYSQL_USER=$OIDC_MYSQL_USER" -e
#"OIDC_MYSQL_PASSWORD=$OIDC_MYSQL_PASSWORD" -e
#"LAYERS_API_URI=http://192.168.59.103:8080" -e "LDAP_DC=dc=layersbox"
#"LDAP_ADMINS=$LDAP_ADMINS" --name openidconnect-data learninglayers/openidconnect-data

# start OpenID Connect
echo "Starting Layers OpenID Connect provider..." &&<commit_msg>Substituted LDAP ip with container ip<commit_after>#!/bin/bash

# A simple script to deploy Layers Box as set of docker containers
# Authors: <NAME>, <NAME>, <NAME> (RWTH Aachen University)

clear && 
echo "***** Layers Box - Basic Deployment Script *****" &&
echo "" &&

echo "It is mandatory to use BTRFS for the OpenStack Swift component. Checking Docker storage driver: " &&
HOST_FS=$(docker info | grep Storage | awk '{print $3}') &&
if [ HOST_FS==btrfs ]; then
  echo "The host system uses BTRFS. Proceeding with the Layers Box set-up." 
else
  echo "The host system uses a FS different than BTRFS! Ceasing Layers Box deployment." && exit 1
fi  &&
echo "This script will now deploy a Layers Box in a Docker-enabled environment step-by-step. After successful deployment, the Layers Box exposes its APIs and applications under the following URIs:" &&
echo && 

# set variables to be forwarded as environment variables to docker containers
LAYERS_API_URI="http://192.168.59.103/";
LAYERS_APP_URI="http://192.168.59.103/";
LAYERS_API_URL="http://192.168.59.103";

# block of environment variables set to Docker containers
# use for configuration of Layers Box
MYSQL_ROOT_PASSWORD="<PASSWORD>";
LDAP_URI="192.168.59.103";
LDAP_ROOT_PASSWORD="<PASSWORD>";
OIDC_MYSQL_DB="OpenIDConnect";
OIDC_MYSQL_USER="oidc";
MM_DB="mobsos_logs";
MM_USER="mobsos_monitor"; 
SHIPYARD_ADMIN_PASS="<PASSWORD>"; 
SWIFT_TENANT_NAME_NAME="tethysTenant";
SWIFT_USER_NAME_NAME="tethysUserStorage";
SWIFT_KEY="pass";
LDAP_ADMINS="koren;nicolaescu";

# Used for IP geolocation; get API key: http://ipinfodb.com/ip_location_api_json.php";
MM_IPINFODB_KEY="";

# Define alias for docker run including all environment variables that must be available to containers.
alias drenv='docker run -e "LAYERS_API_URI=$LAYERS_API_URI" -e "LAYERS_APP_URI=$LAYERS_APP_URI"';

echo ""
echo "Layers API URI: $LAYERS_API_URI";
echo "Layers App URI: $LAYERS_APP_URI";
echo ""

# Clean up: remove all docker containers first to avoid conflicts
echo "****************" &&
echo "** WARNING!!! **" &&
echo "****************" &&
echo "" &&
echo "To clean up the Layers Box host environment, all containers will be removed, including all data containers! Use backup.sh for a simple backup of all Layers Box data volume containers before you continue! (Press enter to continue)" && 
read # Comment interactive step for complete automation
 
echo "Removing all containers..." &&
docker rm -f $(docker ps -a -q);
echo " -> done" &&
echo "" && 

# start Layers Storage mysql data volume container
echo "Starting Layers Common Data Storage MySQL data volume container..." &&
drenv -e "MYSQL_ROOT_PASSWORD=$<PASSWORD>" --name mysql-data learninglayers/mysql-data &&
echo " -> done" &&
echo "" && 

# start Layers Storage mysql container
echo "Starting Layers Common Data Storage MySQL database server..." &&
drenv -d -p 3306:3306 -e "MYSQL_ROOT_PASSWORD=$<PASSWORD>" --volumes-from mysql-data --name mysql learninglayers/mysql &&
echo " -> done" &&
echo "" && 

echo "Waiting 4 seconds for MySql to start"
sleep 4

# start Layers Adapter data volume container
echo "Starting Layers Adapter data volume..." &&
drenv --name adapter-data learninglayers/adapter-data &&
echo " -> done" &&
echo "" && 

# start Layers Adapter
echo "Starting Layers Adapter..." &&
drenv -d -p 80:80 --volumes-from adapter-data --name adapter learninglayers/adapter &&
echo " -> done" &&
echo "" && 

# start Layers OpenLDAP data volume
echo "Starting Layers OpenLDAP data volume..." &&
docker run -e "LDAP_ROOT_PASSWORD=$LDAP_ROOT_PASSWORD" --name openldap-data learninglayers/openldap-data &&
echo " -> done" &&
echo "" && 

# start Layers OpenLDAP
echo "Starting Layers OpenLDAP..." &&
docker run -d -p 389:389 -e "LDAP_ROOT_PASSWORD=$LDAP_ROOT_PASSWORD" --volumes-from openldap-data --name openldap learninglayers/openldap &&
echo " -> done" &&
echo "" &&

LDAP_URI=`docker inspect -f {{.NetworkSettings.IPAddress}} openldap`

# create OpenID Connect database and user
echo "Creating OpenID Connect database and user..." &&
OIDC_MYSQL_PASSWORD=`docker run --link mysql:mysql learninglayers/mysql-create -p$MYSQL_ROOT_PASSWORD --new-database $OIDC_MYSQL_DB --new-user $OIDC_MYSQL_USER | grep "mysql" | awk '{split($0,a," "); print a[3]}' | cut -c3-` &&
echo " -> done" &&
echo "" &&

# start OpenID Connect data volume (TODO: switch to DockerHub)
echo "Starting Layers OpenID Connect data volume..." &&
docker run -e "OIDC_MYSQL_USER=$OIDC_MYSQL_USER" -e "OIDC_MYSQL_PASSWORD=$OIDC_MYSQL_PASSWORD" -e "LAYERS_API_URI=$LAYERS_API_URL" -e "LDAP_DC=dc=layersbox" --name openidconnect-data learninglayers/openidconnect-data &&
echo " -> done" &&
echo "" && 

##updated to support default admin users
#docker run -e "OIDC_MYSQL_USER=$OIDC_MYSQL_USER" -e
#"OIDC_MYSQL_PASSWORD=$OIDC_MYSQL_PASSWORD" -e
#"LAYERS_API_URI=http://192.168.59.103:8080" -e "LDAP_DC=dc=layersbox"
#"LDAP_ADMINS=$LDAP_ADMINS" --name openidconnect-data learninglayers/openidconnect-data

# start OpenID Connect
echo "Starting Layers OpenID Connect provider..." &&
{'fraction_non_alphanumeric': 0.1343715683338325, 'fraction_numerical': 0.016771488469601678, 'mean_word_length': 4.977326968973747, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 10, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '151799', 'n_tokens_mistral': 3443, 'n_tokens_neox': 3232, 'n_words': 1032}