forked from equinor/team-dogleg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.ps1
73 lines (65 loc) · 2.64 KB
/
run.ps1
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# A powershell script to easier run Dockerized container
param (
# Flag switches
[switch]$build = $false,
[switch]$b = $false,
[switch]$run = $false,
[switch]$r = $false,
[switch]$auto = $false,
[switch]$a = $false,
[switch]$help = $false,
# Arguments for python script
$action = $args[0],
$name = $args[1],
$algorithm = $args[2],
$timesteps = $args[3],
$new_save_name = $args[4]
)
$global:container_name = "auto_well_path"
$global:container_running_name = "auto_well_path_running"
$global:python_filename_train = "main.py"
$global:python_filename_load = "FlaskApp.py"
function build_container {
docker build -t $container_name . ; if ($?) {Write-Output "Success!"} else {Write-Output "Error!"}
}
# A bad attempt at ignoring the return output form the delete command
function run_container {
# We run with detached mode to avoid python image blocking
try{
delete_running($container_running_name)
}
catch{
docker run -dit --mount type=bind,source="$(pwd)",target=/usr/src/app -p 0.0.0.0:6006:6006 -p 5000:5000 --name $container_running_name $container_name
}
docker run -dit --mount type=bind,source="$(pwd)",target=/usr/src/app -p 0.0.0.0:6006:6006 -p 5000:5000 --name $container_running_name $container_name
}
function run_python_script($filename,$action,$name,$algorithm,$timesteps,$new_save_name){
docker exec -it $container_running_name python $filename $action $name $algorithm $timesteps $new_save_name
}
function run_tensorboard {
docker exec -dit $container_running_name tensorboard --logdir /usr/src/app/tensorboard_logs --host 0.0.0.0 --port 6006 ; if ($?) {Write-Output "Tensorboard running at port 6006"}
}
function delete_running($name) {
docker rm -f $name
}
function run($script_action) {
if ($script_action -eq "load") {
run_container ; if($?) {run_tensorboard} ; if ($?) {run_python_script $python_filename_load $action $name $algorithm $timesteps $new_save_name}
}
elseif ($script_action -eq "train" -or $script_action -eq "retrain"){
run_container ; if($?) {run_tensorboard} ; if ($?) {run_python_script $python_filename_train $action $name $algorithm $timesteps $new_save_name}
Write-Output("train")
}
else{
Write-Output($script_action, "is not a valid argument!")
}
}
if ($build -or $b) {build_container}
elseif ($run -or $r) {run($action)}
elseif ($auto -or $a) {build_container ; if ($?) {run($action)}}
elseif ($help){
Write-Output("Use -build to build, use -run to run og use -auto to do both")
}
else {
Write-Output("You must specify a flag! For info, pass -help")
}