-
Notifications
You must be signed in to change notification settings - Fork 0
/
exectution
executable file
·43 lines (32 loc) · 1.14 KB
/
exectution
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
#providing basic help
if [ "$#" -lt 1 ] || [ "$#" -gt 3 ] || [ $2 = "--help" ]; then
echo "Man page:"
echo "./execution FOLDER_NAME [GPU_ID] [CPUs]"
echo " FOLDER NAME must contain the folder of the project, that it self must contain the dockerfile"
echo " GPU_ID is optional, is the GPU to allocato to the docker"
echo " CPUs in optionalA valid value might be 0-3 (to use the first, second, third, and fourth CPU) or 1,3 (to use the second and fourth CPU)"
exit 0
fi
#check GPU ID is provided
if [ -z $2 ];
then GPU="";
else GPU="NV_GPU=$2";
fi
#limit docker to given CPUs
if [ -z $3 ];
then CPU="";
else CPU="--cpuset-cpus=$3";
fi
#retriving gid
gid=$(id -g $USER)
#build new image
cmd_build="docker image build -t $USER:$1 $1"
$cmd_build
#run the container from the built image $CPU
cmd_run="$GPU nvidia-docker run -v /home/$USER/datasets/private:/datasets/ -v /home/$USER/storage/models:/models/ --user $UID:$gid --name ${USER}_$1 $USER:$1 "
eval $cmd_run;
cmd_rm="docker rm ${USER}_$1" #remove container
cmd_img_rm="docker image rm $USER:$1" #remove image
$cmd_rm
$cmd_img_rm