-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
changes for issue #6 and other improvements
- Loading branch information
1 parent
c79bd91
commit bd0666e
Showing
1 changed file
with
73 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
#!/bin/sh | ||
# simple - CLI for the SIMPLE Framework | ||
# v0.2 - 2020/03/08 | ||
# v0.4 - 2020/03/09 | ||
# authors: [email protected], [email protected] | ||
|
||
logdir=/var/log/simple | ||
|
||
mkdir -p $logdir || exit | ||
|
||
usage() | ||
{ | ||
echo "Usage: $0 command [args]" >&2 | ||
|
@@ -21,6 +25,8 @@ usage() | |
docker { ls | ps } | ||
validate { install | config | pre_deploy | deploy } | ||
EOF | ||
echo "Logs in $logdir" >&2 | ||
echo "" >&2 | ||
|
||
exit 1 | ||
} | ||
|
@@ -31,9 +37,9 @@ installed_compiler=$compiler_dir/.installed_compiler | |
confdir=/etc/simple_grid/site_config | ||
conf=$confdir/site_level_config_file.yaml | ||
compiled_conf=$confdir/augmented_site_level_config_file.yaml | ||
validation_cmd="simple_infra_validation_engine validate -vvv -f $compiled_conf" | ||
lc_file=/etc/simple_grid/lc | ||
|
||
logdir=/var/log/simple | ||
stamp=`date +%y%m%d-%H%M%S` | ||
err_=$logdir/simple-$stamp-err- | ||
out_=$logdir/simple-$stamp-out- | ||
|
@@ -43,58 +49,61 @@ sg_i=simple_grid::install | |
cm_i=$sg_i::config_master::simple_installer | ||
lc_i=$sg_i::lightweight_component::simple_installer | ||
|
||
mkdir -p $logdir || exit | ||
|
||
case "${1:-?}" in | ||
*[!a-z0-9-]*) | ||
usage | ||
esac | ||
|
||
log=$1.txt out=$out_$log err=$err_$log | ||
val=0 | ||
|
||
case $1 in | ||
create-template) | ||
log=$1.txt out=$out_$log err=$err_$log | ||
|
||
c="class{'$cm_i::create_sample_site_level_config_file':}" | ||
|
||
puppet apply -e "$c" > $out 2> $err && | ||
echo "The template has been created in $conf" || | ||
echo "The command finished with exit code $?" | ||
echo "The template has been created in $conf" || val=$? | ||
;; | ||
|
||
############################################################################### | ||
pre-compile) | ||
log=$1.txt out=$out_$log err=$err_$log | ||
( | ||
[ -e $installed_pip ] || ( | ||
mkdir -p $compiler_dir/.temp && cd $compiler_dir && | ||
yum install -y python-pip && pip install --upgrade pip && | ||
touch $installed_pip | ||
) || exit | ||
|
||
[ -e $installed_pip ] || ( | ||
mkdir -p $compiler_dir/.temp && cd $compiler_dir && | ||
yum install -y python-pip && pip install --upgrade pip && | ||
touch $installed_pip | ||
) || exit | ||
cd $compiler_dir | ||
pip install virtualenv || exit | ||
virtualenv .env || exit | ||
source ./.env/bin/activate | ||
|
||
cd $compiler_dir | ||
pip install virtualenv || exit | ||
virtualenv .env || exit | ||
source ./.env/bin/activate | ||
[ -e $installed_compiler ] || ( | ||
pip install simple-grid-yaml-compiler && touch $installed_compiler | ||
) || exit | ||
|
||
[ -e $installed_compiler ] || ( | ||
pip install simple-grid-yaml-compiler && touch $installed_compiler | ||
) || exit | ||
simple_grid_yaml_compiler $conf -o output.yaml -s schema.yaml | ||
val=$? | ||
|
||
simple_grid_yaml_compiler $conf -o output.yaml -s schema.yaml > $out 2> $err | ||
deactivate | ||
pip uninstall virtualenv | ||
|
||
echo "The command finished with exit code $?" | ||
exit $val | ||
|
||
deactivate | ||
pip uninstall virtualenv | ||
) > $out 2> $err | ||
;; | ||
|
||
############################################################################### | ||
install-cm) | ||
log=$1.txt out=$out_$log err=$err_$log | ||
|
||
echo 'This make take a few minutes...' | ||
puppet apply --modulepath $mp -e "class{'$cm_i':}" > $out 2> $err | ||
|
||
echo "The command finished with exit code $?" | ||
val=$? | ||
;; | ||
|
||
############################################################################### | ||
install-lc) | ||
log=$1.txt out=$out_$log err=$err_$log | ||
|
||
case $2 in | ||
*.*.*) | ||
: | ||
|
@@ -105,19 +114,22 @@ install-lc) | |
esac | ||
|
||
c="class{'$lc_i':puppet_master => '$2'}" | ||
puppet apply --modulepath $mp -e "$c" > $out 2> $err | ||
|
||
echo "The command finished with exit code $?" | ||
echo 'This make take a few minutes...' | ||
puppet apply --modulepath $mp -e "$c" > $out 2> $err | ||
val=$? | ||
;; | ||
|
||
############################################################################### | ||
cm-stage) | ||
puppet facts| grep simple_stage | ||
exit | ||
;; | ||
|
||
############################################################################### | ||
lc-stage) | ||
bolt command run 'puppet facts| grep simple_stage' -t @$lc_file | ||
exit | ||
;; | ||
|
||
############################################################################### | ||
|
@@ -131,16 +143,14 @@ check-stage) | |
usage | ||
esac | ||
|
||
a=augmented_site_level_config_file | ||
|
||
bolt task run simple_grid::check_stage $a=$confdir/$a.yaml \ | ||
bolt task run simple_grid::check_stage \ | ||
augmented_site_level_config_file=$compiled_conf \ | ||
site_infrastructure_key=site_infrastructure expected_stage=$2 -t localhost | ||
exit | ||
;; | ||
|
||
############################################################################### | ||
rollback-to) | ||
log=$1.txt out=$out_$log err=$err_$log | ||
|
||
case $2 in | ||
config|pre_deploy|deploy) | ||
: | ||
|
@@ -153,9 +163,12 @@ rollback-to) | |
case $2:$3 in | ||
config:lc) | ||
c='class{"simple_grid::config::lightweight_component::rollback":}' | ||
|
||
echo 'This make take a few minutes...' | ||
bolt command run "puppet apply -e '$c'" -t @$lc_file > $out 2> $err | ||
val=$? | ||
echo "The command finished with exit code $?" | ||
exit | ||
exit $val | ||
;; | ||
deploy:rmi) | ||
rmi='remove_images => true' | ||
|
@@ -165,18 +178,26 @@ rollback-to) | |
esac | ||
|
||
c="class{'simple_grid::$2::config_master::rollback':$rmi}" | ||
puppet apply -e "$c" > $out 2> $err | ||
|
||
echo "The command finished with exit code $?" | ||
echo 'This make take a few minutes...' | ||
puppet apply -e "$c" > $out 2> $err | ||
val=$? | ||
;; | ||
|
||
############################################################################### | ||
pre-deploy|deploy) | ||
log=$1.txt out=$out_$log err=$err_$log | ||
|
||
pre-deploy) | ||
echo 'This make take a few minutes...' | ||
puppet agent -t > $out 2> $err | ||
val=$? | ||
[ $val = 2 ] && echo "Ignoring exit code $val" && val=0 | ||
;; | ||
|
||
echo "The command finished with exit code $?" | ||
############################################################################### | ||
deploy) | ||
echo 'This make take ~15 minutes per container...' | ||
puppet agent -t > $out 2> $err | ||
val=$? | ||
[ $val = 2 ] && echo "Ignoring exit code $val" && val=0 | ||
;; | ||
|
||
############################################################################### | ||
|
@@ -194,36 +215,28 @@ docker) | |
esac | ||
|
||
bolt command run "docker $cmd" -t @$lc_file | ||
exit | ||
;; | ||
|
||
############################################################################### | ||
validate) | ||
log=$1.txt out=$out_$log err=$err_$log | ||
|
||
case $2 in | ||
install) | ||
stage='install' | ||
;; | ||
config) | ||
stage='config' | ||
;; | ||
pre_deploy) | ||
stage='pre_deploy' | ||
;; | ||
deploy) | ||
stage='deploy' | ||
install|config|pre_deploy|deploy) | ||
;; | ||
*) | ||
echo "$0: $1 requires a valid stage as argument" >&2 | ||
usage | ||
esac | ||
|
||
simple_infra_validation_engine validate -vvv -f $compiled_conf $stage > $out 2> $err | ||
|
||
echo "The command finished with exit code $?" | ||
$validation_cmd $2 > $out 2> $err | ||
val=$? | ||
;; | ||
|
||
############################################################################### | ||
*) | ||
usage | ||
esac | ||
|
||
echo "The command finished with exit code $val (logs in $logdir)" | ||
exit $val | ||
|