Skip to content

Commit

Permalink
refactoring initial script
Browse files Browse the repository at this point in the history
  • Loading branch information
cdsap committed Aug 15, 2019
1 parent 6be3d30 commit b7a5407
Show file tree
Hide file tree
Showing 16 changed files with 388 additions and 528 deletions.
169 changes: 47 additions & 122 deletions bagan
@@ -1,35 +1,24 @@
#!/bin/bash
set -e
type=$1
mode=$2

color() {
printf '\033[%sm%s\033[m\n' "$@"
}

. scripts/log.sh
. scripts/command_helm.sh
. scripts/command_bagan.sh
. scripts/command_init_credentials.sh
. scripts/command_previous_experiments.sh
. scripts/command_cluster.sh
. scripts/command_secret.sh
. scripts/command_utils.sh
. scripts/command_end.sh

type=$1
mode=$2

if [ ! "$type" = "gcloud" ] && [ ! "$type" = "minikube" ] && [ ! "$type" = "gcloud_docker" ]; then
printf '%s\n' "Error: type not supported. Current clusters environments supported are minikube, gcloud and gcloud_docker:"
printf '%s\n' "Example: ./bagan gcloud cluster"
printf '%s\n' "Example: ./bagan gcloud_docker infrastructure"
printf '%s\n' "Example: ./bagan minkube experiment"
printf '%s\n' ""
exit 1
fi

if [ ! "$mode" = "cluster" ] && [ ! "$mode" = "infrastructure" ] && [ ! "$mode" = "experiment" ]; then
printf '%s\n' ""
printf '%s\n' "Error: mode not supported. Current modes supported are cluster, experiment and infrastructure:"
printf '%s\n' "cluster: create cluster in gcloud, initalizing the infrastructure and finally executing Bagan to generate the experiments"
printf '%s\n' "infrastrucure: initialize the infrastrucure with helm and required charts of Grafana and InfluxDb"
printf '%s\n' "experiment: execute Bagan to generate experiments in the environment selected"
printf '%s\n' ""
exit 1
fi
. scripts/mode_gcloud.sh
. scripts/mode_gcloud_docker.sh
. scripts/mode_standalone.sh
. scripts/mode_standalone.sh
. scripts/validations.sh

echo ""
echo "Welcome to Bagan"
Expand All @@ -45,43 +34,44 @@ elif [ "$type" == "gcloud_docker" ]; then
requeriments=" -- jq: https://stedolan.github.io/jq/
-- docker: https://www.docker.com/"

elif [ "$type" == "minikube" ]; then
requeriments=" -- jq: https://stedolan.github.io/jq/
-- minikube: https://cloud.google.com/sdk/
-- docker: https://www.docker.com/
elif [ "$type" == "standalone" ]; then
requeriments=" -- Setup locally kubectl in the execution machine
-- kscript: https://github.com/holgerbrandl/kscript"
else
echo "error : Be sure you have included the bagan_conf.json with the desired configuration."
fi

. scripts/validate_json.sh

printf '%s\n' ""
printf '%s\n' "Requeriments for your $type environment selection:"
printf '%s\n' "$requeriments"
printf '%s\n' ""
printf '%s\n' "Values:"
printf '%s\n' "type: $type"
printf '%s\n' "cluster: $cluster"
printf '%s\n' "zone: $zone"
printf '%s\n' "machine: $machine"
printf '%s\n' "repository: $repository"
printf '%s\n' "gradleCommand: $gradleCommand"
printf '%s\n' "properties: $properties"
printf '%s\n' ""
log ""
log "Requeriments for your $type environment selection:"
log "$requeriments"
log ""
log "Values:"
log "type: $type"
log "cluster: $cluster"
log "zone: $zone"
log "machine: $machine"
log "repository: $repository"
log "private repository: $private"
if [ "$private" == "true" ]; then
log "ssh key path: $ssh"
log "known hosts path: $known_hosts"
fi
log "gradleCommand: $gradleCommand"
log "properties: $properties"
log ""
if [ "$mode" == "experiment" ] && ([ "$type" == "gcloud" ] || [ "$type" == "gcloud_docker" ]) ; then
printf '%s\n' "In case you are running experiments, not for the first time, and you didn't remove it from Gcloud console, you can delete previous experiment releases with:"
printf '%s\n' "helm del --purge \$( helm ls --all experimen* --short)"
printf '%s\n' ""
log "In case you are running experiments, not for the first time, and you didn't remove it from Gcloud console, you can delete previous experiment releases with:"
log "helm del --purge \$( helm ls --all experimen* --short)"
log ""
fi;
echo -n "Do you want to continue [y/n]: "
read ans2
read ans

if [ "$ans2" != "y" ] || [ -z "$ans2" ]; then
if [ "$ans" != "y" ] || [ -z "$ans" ]; then
exit 1
fi;

printf '%s\n' "Staring Bagan"
log "Staring Bagan"

rm -rf tmp
mkdir tmp
Expand All @@ -92,81 +82,16 @@ cp -r docker/installer/bin/creator tmp/
cp -r docker/pod/bin/ tmp

if [ $type == "gcloud" ]; then
printf '%s\n' "Running gcloud"
if [ $mode == "cluster" ]; then
printf '%s\n' "Mode cluster"
eval "$(gcloudInit)"
eval "$(gcloudCredentials)"
eval "$(gcloudHelm)"
eval "$(gcloudInfraPods)"
eval "$(createSecret)"
eval "$(gcloudBagan)"
elif [ $mode == "infrastructure" ]; then
printf '%s\n' "Mode infrastrucure"
eval "$(gcloudCredentials)"
eval "$(gcloudHelm)"
eval "$(gcloudInfraPods)"
eval "$(createSecret)"
checkPreviousExperiments
eval "$(gcloudBagan)"
elif [ $mode == "experiment" ]; then
printf '%s\n' "Mode expreriment"
eval "$(gcloudCredentials)"
# eval "$(createSecret)"
eval "$(gcloudBagan)"
else
printf '%s\n' "Error no mode parsed properly for gcloud"
exit 1
fi
log "Running gcloud"
gcloudExecutor
echo "$(endGcloud)"
elif [ $type == "gcloud_docker" ]; then
printf '%s\n' "Running gcloud docker"
if [ $mode == "cluster" ]; then
printf '%s\n' "Mode cluster"
execution="$(gcloudInit) $(gcloudCredentials) $(gcloudHelm) $(gcloudInfraPods) $(gcloudDockerBagan)"
elif [ $mode == "infrastructure" ]; then
printf '%s\n' "Mode infrastrucure"
execution="$(gcloudCredentials) $(gcloudHelm) $(gcloudInfraPods) $(gcloudDockerBagan) "
elif [ $mode == "experiment" ]; then
printf '%s\n' "Mode experiment"
execution="$(gcloudCredentials) $(gcloudDockerBagan)"
else
printf '%s\n' "Error no mode parsed properly for gcloud_docker"
exit 1
fi
printf '%s\n' "Executing Docker"
docker run -ti -v $HOME/.config/gcloud:/root/.config/gcloud \
-v $PWD/tmp:/usr/local/tmp \
-v $PWD/bagan_conf.json:/usr/local/tmp/creator/bagan_conf.json \
cdsap/bagan-init:0.1.4 /bin/bash -c "
export PATH=$PATH:/usr/local/gcloud/google-cloud-sdk/bin/;
cd /usr/local;
$execution;"

elif [ $type == "minikube" ]; then
printf '%s\n' "Runing Minikube"
output=(`minikube status`)
if [ "${output[1]}" != "Running" ]; then
printf '%s\n' "Not found minikube instance with status Running"
exit 1
fi
if [ $mode == "cluster" ] || [ $mode == "infrastrucure" ]; then
eval "$(minikubeHelm)"



echo 1;


eval "$(gcloudInfraPods)"
eval "$(gcloudBagan)"
elif [ $mode == "experiment" ]; then
eval "$(gcloudBagan)"
else
printf '%s\n' "Error: no mode parsed properly for minikube"
exit 1
fi
log "Running gcloud docker"
gcloudDockerExecutor
elif [ $type == "standalone" ]; then
log "Runing standalone"
standaloneExecutor
else
printf '%s\n' "Error: no type parsed properly "
error "Error: no type parsed properly "
exit 1
fi
13 changes: 10 additions & 3 deletions bagan_conf.json
@@ -1,16 +1,23 @@
{
"bagan": {
"repository": "git@github.com:cdsap/TestPrivateRepository.git",
"gradleCommand": "./gradlew clean",
"repository": "https://github.com/android/plaid.git",
"gradleCommand": "./gradlew clean assembleDebug",
"clusterName": "",
"machine": "n1-standard-1",
"zone": null,
"iterations": 1,
"private": false,
"ssh": "",
"known_hosts": "/tmp/known_hosts",
"iterations": 5,
"experiments": {
"properties": [
{
"name": "org.gradle.jvmargs",
"options": ["-Xmx3g","-Xmx4g"]
},
{
"name": "org.gradle.caching",
"options": ["true","false"]
}
]
}
Expand Down

0 comments on commit b7a5407

Please sign in to comment.