Skip to content

Commit de5b199

Browse files
authored
Add user project installation on cluster. (#20)
1 parent 6046c2b commit de5b199

File tree

1 file changed

+153
-0
lines changed

1 file changed

+153
-0
lines changed

scripts/rayvens-setup.sh

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ image="quay.io/ibm/rayvens:$rayvens_version"
2424
service_account="rayvens"
2525
cpu="1"
2626
mem="2G"
27+
project_dir=""
28+
project_requirements_file=""
29+
project_dependencies=()
30+
project_pip_dependencies=()
2731

2832
while [ -n "$1" ]; do
2933
case "$1" in
@@ -44,6 +48,12 @@ while [ -n "$1" ]; do
4448
--example) example="1";;
4549
--preload) preload="1";;
4650
--version) version="1";;
51+
--install-project) install_project="1";;
52+
--project-dir) shift; project_dir=$1;;
53+
-d|--project-dep) shift; project_dependencies+=("$1");;
54+
-p|--project-pip-dep) shift; project_pip_dependencies+=("$1");;
55+
--project-requirements) shift; project_requirements_file=$1;;
56+
--requirements-in-project-dir) requirements_in_project_dir="1";;
4757

4858
--dev)
4959
kind="1";
@@ -83,6 +93,13 @@ Usage: rayvens-setup.sh [options]
8393
--preload preload main camel jars into maven repository
8494
--version shows the version of this script
8595
96+
--install-project install project on cluster nodes, use --project-dir <absolute_dir_path>, --project-requirements <absolute_file_path> or --requirements-in-project-dir
97+
--project-dir <absolute_dir_path> directory of the user project to be pip installed on the cluster nodes
98+
--project-requirements <absolute_file_path> file containing python dependencies to be pip installed on the cluster nodes via requirements file
99+
--requirements-in-project-dir when true, the requirements file in the project directory will be used, if missing the requirements file will be ignored
100+
--project-dep <dep> system project dependency that will use "apt-get install -y <dep>"
101+
--project-pip-dep <dep> python dependency to be pip installed using "pip install <dep>"
102+
86103
--kind setup a development Kind cluster on localhost instead of deploying to current Kubernetes context
87104
(destroy existing Kind cluster if any, set Kubernetes context to Kind)
88105
@@ -335,6 +352,142 @@ worker_start_ray_commands:
335352
- ray stop
336353
- ulimit -n 65536; ray start --address=\$RAY_HEAD_IP:6379
337354
EOF
355+
356+
if [ -n "$install_project" ]; then
357+
if [ -z "$project_dir" ]; then
358+
echo "ERROR: project directory name has not been specified, use flag --project-dir <absolute_path_to_dir>"
359+
exit 1
360+
fi
361+
362+
if [ -z "$(dirname "${project_dir}")" ]; then
363+
echo "ERROR: project directory specified: ${project_dir} but it is not an absolute path"
364+
exit 1
365+
fi
366+
367+
echo "--- mount project from directory $(dirname "${project_dir}")"
368+
echo "$(dirname "${project_dir}")" ; echo "$(basename "${project_dir}")"
369+
dir_name="$(basename "${project_dir}")"
370+
requirements_file_name=""
371+
372+
if [ -z "${dir_name}" ]; then
373+
echo "ERROR: project directory name missing from path: ${project_dir}"
374+
exit 1
375+
fi
376+
377+
cat >> "$config" << EOF
378+
file_mounts:
379+
{
380+
"/home/ray/$dir_name": "$project_dir"
381+
EOF
382+
383+
if [ ! -z "$project_requirements_file" ]; then
384+
if [ -z "$(dirname "${project_requirements_file}")" ]; then
385+
echo "ERROR: project requirements file specified: ${project_requirements_file} but it is not an absolute path"
386+
exit 1
387+
fi
388+
389+
requirements_file_name="$(basename "${project_requirements_file}")"
390+
391+
if [ -z "${requirements_file_name}" ]; then
392+
echo "ERROR: project requirements file missing from path: ${project_requirements_file}"
393+
exit 1
394+
fi
395+
396+
cat >> "$config" << EOF
397+
"/home/ray/$requirements_file_name": "$project_requirements_file"
398+
EOF
399+
400+
fi
401+
cat >> "$config" << EOF
402+
}
403+
file_mounts_sync_continuously: false
404+
EOF
405+
fi
406+
407+
if [ -n "$install_project" ]; then
408+
cat >> "$config" << EOF
409+
head_setup_commands:
410+
EOF
411+
412+
if [ "${#project_dependencies[@]}" -gt "0" ]; then
413+
cat >> "$config" << EOF
414+
- sudo apt-get update
415+
EOF
416+
for dependency in "${project_dependencies[@]}"
417+
do
418+
cat >> "$config" << EOF
419+
- sudo apt-get -y install $dependency
420+
EOF
421+
done
422+
fi
423+
424+
if [ "${#project_pip_dependencies[@]}" -gt "0" ]; then
425+
for pip_dependency in "${project_pip_dependencies[@]}"
426+
do
427+
cat >> "$config" << EOF
428+
- sudo apt-get -y install $pip_dependency
429+
EOF
430+
done
431+
fi
432+
433+
if [ -n "$requirements_in_project_dir" ]; then
434+
cat >> "$config" << EOF
435+
- pip install -r /home/ray/$dir_name/requirements.txt
436+
EOF
437+
fi
438+
439+
if [ ! -z "$requirements_file_name" ]; then
440+
cat >> "$config" << EOF
441+
- pip install -r /home/ray/$requirements_file_name
442+
EOF
443+
fi
444+
445+
cat >> "$config" << EOF
446+
- pip install /home/ray/$dir_name
447+
EOF
448+
449+
cat >> "$config" << EOF
450+
worker_setup_commands:
451+
EOF
452+
453+
if [ "${#project_dependencies[@]}" -gt "0" ]; then
454+
cat >> "$config" << EOF
455+
- sudo apt-get update
456+
EOF
457+
for dependency in "${project_dependencies[@]}"
458+
do
459+
cat >> "$config" << EOF
460+
- sudo apt-get -y install $dependency
461+
EOF
462+
done
463+
fi
464+
465+
if [ "${#project_pip_dependencies[@]}" -gt "0" ]; then
466+
for pip_dependency in "${project_pip_dependencies[@]}"
467+
do
468+
cat >> "$config" << EOF
469+
- sudo apt-get -y install $pip_dependency
470+
EOF
471+
done
472+
fi
473+
474+
if [ -n "$requirements_in_project_dir" ]; then
475+
cat >> "$config" << EOF
476+
- pip install -r /home/ray/$dir_name/requirements.txt
477+
EOF
478+
fi
479+
480+
if [ ! -z "$requirements_file_name" ]; then
481+
cat >> "$config" << EOF
482+
- pip install -r /home/ray/$requirements_file_name
483+
EOF
484+
fi
485+
486+
cat >> "$config" << EOF
487+
- pip install /home/ray/$dir_name
488+
EOF
489+
fi
490+
338491
else
339492
echo "--- skipping generation of cluster configuration file"
340493
if [ ! -f "$config" ]; then

0 commit comments

Comments
 (0)