-
Notifications
You must be signed in to change notification settings - Fork 0
/
WINLocator.bash
executable file
·72 lines (58 loc) · 2.04 KB
/
WINLocator.bash
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
#!/bin/bash
## def names
image_name='hypomh'; tag_name='v1.1-base'
container_name='hypomh-1'
app_name='python3 src/hypomh.py'
win32tooltar="dockerfiles/win32tools/win32tools.tar.gz"
## check OS
OSname="Mac-Linux"
if [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "win32" ]]; then
OSname="Windows"
fi
## set config
docker_head=""; docker_head_images=""
workdir=`pwd`; arg_head=""
if [[ $OSname == "Windows" ]]; then
docker_head="winpty"; docker_head_images=""
workdir=/`pwd`; arg_head="/"
fi
## read args
volume="-v $workdir:$workdir"
for arg in ${@//=/ }; do
if [[ $arg == *"/"* ]]; then
arg="$arg_head$(cd -- "$(dirname -- "$arg")" && pwd)" || exit $? # convert to absolute dirname
volume+=" -v $arg:$arg"
fi
done
args=$@
## pull image
if ! $docker_head_images docker images --format '{{.Repository}}:{{.Tag}}' | grep -q -x "$image_name:$tag_name"; then
$docker_head docker pull rintrsuzuki/$image_name:$tag_name
$docker_head docker tag rintrsuzuki/$image_name:$tag_name $image_name:$tag_name
$docker_head docker rmi rintrsuzuki/$image_name:$tag_name
fi
## build image with win32tools if tar exists
if [ -e $win32tooltar ]; then
tag_name=${tag_name//-base/}
if ! $docker_head_images docker images --format '{{.Repository}}:{{.Tag}}' | grep -q -x "$image_name:$tag_name"; then
$docker_head docker build -t $image_name:$tag_name -f dockerfiles/win32tools/Dockerfile dockerfiles/win32tools
fi
fi
### stop old container if exists
if $docker_head_images docker ps --format '{{.Names}}' | grep -q -x "$container_name"; then
$docker_head docker stop $container_name
fi
## run container
$docker_head docker run -itd --rm \
$volume \
--name $container_name \
$image_name:$tag_name
if [[ $1 == "DEBUG" ]]; then
### attach container as DEBUG mode
$docker_head docker exec -it -w $workdir $container_name bash
else
### exec app
$docker_head docker exec -it -w $workdir $container_name $app_name $args
### stop container
$docker_head docker stop $container_name
fi