11#! /bin/bash
2- # #################################################################################
3- # # Script launches BioLockJ via Docker + creates $DOCKER_CLONE_SCRIPT ##
4- # # Bash env must include pipeline base directory: ${BLJ_PROJ} ##
5- # # ##
6- # # Required Parameters (If -gui arg passed, no other args required) ##
7- # # Config file path: - c <file-path> ##
8- # # ##
9- # # Optional Parameters: ##
10- # # Aws flag: -aws ##
11- # # Use local BLJ flag: -blj ##
12- # # Use local BLJ_SUP flag: -blj_sup ##
13- # # Run GUI flag: -gui ##
14- # # New email password: - p <new_password> ##
15- # # Restart flag: - r <directory-path> ##
16- # # ##
17- # #################################################################################
2+ # ##############################################################################
3+ # # Script launches BioLockJ via Docker + creates $DOCKER_CLONE_SCRIPT ##
4+ # # Bash env must include pipeline base directory: ${BLJ_PROJ} ##
5+ # # ##
6+ # # Required Parameters (If g arg passed, no other args required) ##
7+ # # Config file path: c <file_path> ##
8+ # # ##
9+ # # Optional Parameters: ##
10+ # # Aws flag: a ##
11+ # # Use local BLJ flag: -blj ##
12+ # # Use local BLJ_SUP flag: -blj_sup ##
13+ # # Run GUI flag: g ##
14+ # # New email password: p <new_password> ##
15+ # # Restart flag: r <dir_path> ##
16+ # # ##
17+ # ##############################################################################
1818. " ${DOCKER_LIB} "
1919
20- DOCKER_ENV_FLAG=" /.dockerenv"
2120GUI_PORT=8080
2221
2322# Populate docker run env variable $BLJ_OPTIONS
2423# Always include vars to map Host paths: Config, $BLJ_PROJ, and $HOME.
25- # In AWS mode, add -aws indicator, otherwise include the Host path for pipeline input.
24+ # In AWS mode, add a indicator, otherwise include the Host path for pipeline input.
2625# These paths are used by biolockj_controller to map Docker volumes for java_module containers
2726blj_options () {
2827 options=" -u ${HOME} -b $( blj_proj) -h $( hostname) "
29- $( var_not_null $overrideBLJ ) && options=" ${options} -blj ${overrideBLJ} "
30- $( var_not_null $overrideBLJ_SUP ) && options=" ${options} -blj_sup ${overrideBLJ_SUP} "
31- $( var_not_null $launchGui ) && echo " ${options} " && return
32-
33- $( var_not_null $restartDir ) && options=" ${options} -r ${BLJ_PROJ} /${restartDir# $(blj_proj)/ } "
34- $( var_not_null $newPass ) && options=" ${options} -p $newPass "
35- $( var_not_null $metaPath ) && options=" ${options} -m $metaPath "
36- $( var_not_null $primerPath ) && options=" ${options} -t $primerPath "
37-
38- echo ${options} -i ${inputDir} -c ${config} ${runAws}
28+ ! $( null_var $blj ) && options=" ${options} -blj ${blj} "
29+ ! $( null_var $blj_sup ) && options=" ${options} -blj_sup ${blj_sup} "
30+ ! $( null_var $runGui ) && echo " ${options} " && return
31+ ! $( null_var $restartDir ) && options=" ${options} r ${BLJ_PROJ} /${restartDir# $(blj_proj)/ } "
32+ ! $( null_var $newPass ) && options=" ${options} p $newPass "
33+ ! $( null_var $metaPath ) && options=" ${options} -m $metaPath "
34+ ! $( null_var $primerPath ) && options=" ${options} -t $primerPath "
35+ echo " ${options} -i ${inputDir} c ${config} ${runAws} "
3936}
4037
4138# If dockblj called by biolockj_controller Docker container in GUI mode, set BLJ_PROJ based on the $BLJ_OPTIONS
4239# env var, otherwise return $BLJ_PROJ if called from a host machine. If dir ends with "/" trim it off
4340blj_proj () {
44- if [ -f " ${DOCKER_ENV_FLAG} " ] && $( var_exists BLJ_OPTIONS) ; then
41+ if [ -f " /.dockerenv " ] && $( var_exists BLJ_OPTIONS) ; then
4542 bljProj=$( named_arg " ${BLJ_OPTIONS} " -b)
4643 else
4744 bljProj=" ${BLJ_PROJ} "
4845 fi
49-
5046 if [ " ${bljProj: -1} " == " /" ]; then
5147 len=$(( ${# bljProj} - 1 ))
5248 bljProj=" ${bljProj: 0: len} "
5349 fi
54- ! $( var_not_null $bljProj ) && exit_script " Error [ dockblj.blj_proj ]: Required env variable BLJ_PROJ undefined"
50+ $( null_var $bljProj ) && exit_script " Error [ dockblj.blj_proj ]: Required env variable BLJ_PROJ undefined"
5551 echo " ${bljProj} "
5652}
5753
@@ -60,8 +56,7 @@ blj_proj() {
6056build_clone_script () {
6157 img=" $( dock_id) /biolockj_controller"
6258 cmd=${@/ $img / -ti $img / bin/ bash}
63- $( var_not_null $launchGui ) && cmd=${cmd/ npm start}
64-
59+ ! $( null_var $runGui ) && cmd=${cmd/ npm start}
6560 echo " #!/bin/bash" > " ${DOCKER_CLONE_SCRIPT} "
6661 echo " # This script launches a clone of the last biolockj_controller (same env vars + volumes)" >> " ${DOCKER_CLONE_SCRIPT} "
6762 echo " ${cmd} " >> " ${DOCKER_CLONE_SCRIPT} "
@@ -73,57 +68,72 @@ build_clone_script() {
7368# Get Docker image - add port, entrypoint, anc command if launching GUI
7469get_docker_img () {
7570 cmd=$( dock_id) /biolockj_controller
76- $( var_not_null $launchGui ) && echo " -p ${GUI_PORT} :3000 --expose ${GUI_PORT} -w /app/biolockj/web_app ${ cmd} npm start "
77- ! $( var_not_null $launchGui ) && echo " ${ cmd}"
71+ $( null_var $runGui ) && echo " ${ cmd}"
72+ ! $( null_var $runGui ) && echo " -p ${GUI_PORT} :3000 --expose ${GUI_PORT} -w /app/biolockj/web_app ${ cmd} npm start "
7873}
7974
8075# Get mapped Docker volumes
8176get_volumes () {
8277 vols=" -v ${DOCK_SOCK} :${DOCK_SOCK} -v ${HOME} :${BLJ_HOST_HOME} :delegated"
83- if $( var_not_null $runAws ) ; then
84- vols=" ${vols} -v ${EFS} :${EFS} :delegated"
85- else
78+ if $( null_var $runAws ) ; then
8679 vols=" ${vols} -v $( blj_proj) :${EFS_PROJ} :delegated"
87- if $( var_not_null $launchGui ) ; then
88- vols=" ${vols} -v ${BLJ} /resources/config/gui:${BLJ_CONFIG} :delegated"
89- else
80+ if $( null_var $runGui ) ; then
9081 vols=" ${vols} -v $inputDir :${BLJ_INPUT} :ro -v $( dirname $config ) :${BLJ_CONFIG} :ro"
91- $( var_not_null $metaPath ) && vols=" ${vols} -v $metaPath :${BLJ_META} :ro"
92- $( var_not_null $primerPath ) && vols=" ${vols} -v $primerPath :${BLJ_PRIMER} :ro"
82+ $( null_var $metaPath ) && vols=" ${vols} -v $metaPath :${BLJ_META} :ro"
83+ $( null_var $primerPath ) && vols=" ${vols} -v $primerPath :${BLJ_PRIMER} :ro"
84+ else
85+ vols=" ${vols} -v ${BLJ} /resources/config/gui:${BLJ_CONFIG} :delegated"
9386 fi
94-
95- $( var_not_null $overrideBLJ ) && vols=" ${vols} -v ${overrideBLJ} :/app/biolockj:ro"
96- $( var_not_null $overrideBLJ_SUP ) && vols=" ${vols} -v ${overrideBLJ_SUP} :/app/blj_support:ro"
87+ ! $( null_var $blj ) && vols=" ${vols} -v ${blj} :/app/biolockj:ro"
88+ ! $( null_var $blj_sup ) && vols=" ${vols} -v ${blj_sup} :/app/blj_support:ro"
89+ else
90+ vols=" ${vols} -v ${EFS} :${EFS} :delegated"
9791 fi
9892 echo " ${vols} "
9993}
10094
95+ # Boolean evaluation if single argument passed exists with a non-zero size
96+ # Param 1 - Script arg
97+ null_var () {
98+ [ ${# 1} -eq 0 ]
99+ }
100+
101101# Print and execute the docker run command with the correct volumes and env variables
102102run_docker () {
103- cmd=" docker run --rm -e \" BLJ_OPTIONS=$( blj_options) \" $( get_volumes) $( get_docker_img) "
103+ ! $( null_var $runGui ) && runInBak=" &"
104+ cmd=" docker run --rm -e \" BLJ_OPTIONS=$( blj_options) \" $( get_volumes) $( get_docker_img) ${runInBak} "
104105 printf " \n---------> Execute CMD [ ${cmd} ] \n\n"
105106 build_clone_script " ${cmd} "
106- docker run --rm -e " BLJ_OPTIONS=$( blj_options) " $( get_volumes) $( get_docker_img)
107+ if $( null_var $runGui ) ; then
108+ docker run --rm -e " BLJ_OPTIONS=$( blj_options) " $( get_volumes) $( get_docker_img)
109+ else
110+ docker run --rm -e " BLJ_OPTIONS=$( blj_options) " $( get_volumes) $( get_docker_img) &
111+ fi
107112}
108113
109114# Read script args and bash env vars
110115# Param 1 - Array of dockblj script args
111116scan_script_and_env_args () {
112- launchGui=$( arg_exists " $@ " -gui)
113- runAws=$( arg_exists " $@ " -aws)
114- overrideBLJ=$( named_arg " $@ " -blj)
115- overrideBLJ_SUP=$( named_arg " $@ " -blj_sup)
116- ! $( var_not_null $overrideBLJ ) && overrideBLJ=$( arg_exists " $@ " -blj) && [ ${# overrideBLJ} -eq 0 ] && overrideBLJ=" ${BLJ} "
117- ! $( var_not_null $overrideBLJ_SUP ) && overrideBLJ_SUP=$( arg_exists " $@ " -blj_sup) && [ ${# overrideBLJ_SUP} -eq 0 ] && overrideBLJ_SUP=" ${BLJ_SUP} "
118- config=$( named_arg " $@ " -c)
119- newPass=$( named_arg " $@ " -p)
120- restartDir=$( named_arg " $@ " -r)
121- inputDir=$( named_arg " $@ " -i)
122- metaPath=$( named_arg " $@ " -m)
123- primerPath=$( named_arg " $@ " -t)
124- # inputDir="$(get_property $config input.dirPaths)"
125- # metaPath="$(get_property $config metadata.filePath)" && [ ${#metaPath} -gt 0 ] && metaPath="$(dirname $metaPath)"
126- # primerPath="$(get_property $config trimPrimers.filePath)" && [ ${#primerPath} -gt 0 ] && primerPath="$(dirname $primerPath)"
117+ runGui=$( arg_exists " $@ " g)
118+ runAws=$( arg_exists " $@ " a)
119+ config=$( named_arg " $@ " c)
120+ newPass=$( named_arg " $@ " p)
121+ restartDir=$( named_arg " $@ " r)
122+ blj=$( named_arg " $@ " -blj)
123+ blj_sup=$( named_arg " $@ " -blj_sup)
124+
125+ if $( null_var $blj ) && blj=$( arg_exists " $@ " -blj) ; then
126+ blj=" ${BLJ} " && $( null_var $blj ) && echo " Arg \" blj\" will be ignored because environment variable \" BLJ\" is undefined"
127+ fi
128+ if $( null_var $blj_sup ) && blj_sup=$( arg_exists " $@ " -blj_sup) ; then
129+ blj_sup=" ${BLJ_SUP} " && $( null_var $blj_sup ) && echo " Arg \" blj_sup\" will be ignored because environment variable \" BLJ_SUP\" is undefined"
130+ fi
131+
132+ if $( null_var $runGui ) ; then
133+ inputDir=" $( get_property $config input.dirPaths) "
134+ metaPath=" $( get_property $config metadata.filePath) " && [ ${# metaPath} -gt 0 ] && metaPath=" $( dirname $metaPath ) "
135+ primerPath=" $( get_property $config trimPrimers.filePath) " && [ ${# primerPath} -gt 0 ] && primerPath=" $( dirname $primerPath ) "
136+ fi
127137}
128138
129139# Start the local browswer
@@ -141,12 +151,6 @@ startBrowser() {
141151 fi
142152}
143153
144- # Boolean evaluation if single argument passed exists with a non-zero size
145- # Param 1 - Script arg
146- var_not_null () {
147- [ ${# 1} -gt 0 ]
148- }
149-
150154# Verify host directory exists, if dockblj is not deployed inside a Docker container
151155# Param 1 - System path
152156verify_dir () {
@@ -161,24 +165,18 @@ verify_file() {
161165
162166# Verify paths are valid, if dockblj is not run inside a Docker container
163167verify_inputs () {
164- $( var_not_null $inputDir ) && dirPath=( ${inputDir// , } )
165- ! $( var_not_null $inputDir ) || [ ${# dirPath[@]} -gt 1 ] && exit_script " Error [ dockblj ]: The -i parameter must reference a single input directory"
168+ ! $( null_var $inputDir ) && dirPath=( ${inputDir// , } )
169+ $( null_var $inputDir ) || [ ${# dirPath[@]} -gt 1 ] && exit_script " Error [ dockblj ]: The -i parameter must reference a single input directory"
166170 verify_dir $dirPath
167171 verify_dir $BLJ_PROJ
168- $( var_not_null $restartDir ) && verify_dir $restartDir
169- $( var_not_null $config ) && verify_file $config
170- $( var_not_null $metaPath ) && verify_dir $metaPath
171- $( var_not_null $primerPath ) && verify_file $primerPath
172+ ! $( null_var $restartDir ) && verify_dir $restartDir
173+ ! $( null_var $config ) && verify_file $config
174+ ! $( null_var $metaPath ) && verify_dir $metaPath
175+ ! $( null_var $primerPath ) && verify_file $primerPath
172176}
173177
174178printf " \n ---------> Execute CMD [ dockblj $( echo ${@ } ) ]\n\n"
175179scan_script_and_env_args $@
176-
177- if $( var_not_null $launchGui ) ; then
178- # Execute run_docker in background to startBrowser
179- run_docker &
180- startBrowser
181- else
182- verify_inputs
183- run_docker
184- fi
180+ $( null_var $runGui ) && verify_inputs
181+ run_docker
182+ ! $( null_var $runGui ) && startBrowser
0 commit comments