forked from spring-attic/spring-native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-dev-container.sh
executable file
·97 lines (90 loc) · 2.59 KB
/
run-dev-container.sh
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env bash
MILESTONE=0.12.x
JAVA_VERSION=11
GRAALVM_VERSION=stable
PULL=false
REBUILD=false
HOST_WORK_DIR="$( pwd )"
while test $# -gt 0; do
case "$1" in
-h|--help)
echo "run-dev-container.sh - run Spring GraalVM native dev container"
echo " "
echo "run-dev-container.sh [options]"
echo " "
echo "options:"
echo "-h, --help show brief help"
echo "-j, --java=VERSION specify Java version to use, can be 11 or 17, 11 by default"
echo "-w, --workdir=/foo specify the working directory, should be an absolute path, current one by default"
echo "-p, --pull force pulling of remote container images"
echo "-r, --rebuild force container image rebuild"
exit 0
;;
-j)
shift
if test $# -gt 0; then
export JAVA_VERSION=$1
else
echo "no Java version specified"
exit 1
fi
shift
;;
--java*)
export JAVA_VERSION=`echo $1 | sed -e 's/^[^=]*=//g'`
shift
;;
-w)
shift
if test $# -gt 0; then
export HOST_WORK_DIR=$1
else
echo "no working directory specified"
exit 1
fi
shift
;;
--workdir)
export HOST_WORK_DIR=`echo $1 | sed -e 's/^[^=]*=//g'`
shift
;;
-p)
export PULL=true
export REBUILD=true
shift
;;
--pull)
export PULL=true
export REBUILD=true
shift
;;
-r)
export REBUILD=true
shift
;;
--rebuild)
export REBUILD=true
shift
;;
*)
break
;;
esac
done
DOCKER_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/docker" >/dev/null 2>&1 && pwd )"
CONTAINER_HOME=/home/$USER
CONTAINER_WORK_DIR=$CONTAINER_HOME/spring-native
CONTAINER_TAG=java${JAVA_VERSION}-${MILESTONE}
DEV_IMAGE=Dockerfile.spring-native-dev
if [ "$PULL" = true ] ; then
echo "Updating container image if needed"
docker pull springci/spring-native:${CONTAINER_TAG}
fi
docker image ls | grep spring-native-dev | grep ${CONTAINER_TAG} >/dev/null 2>&1 || export REBUILD=true
test "$REBUILD" = false || docker build \
--build-arg BASE_IMAGE=springci/spring-native:${CONTAINER_TAG} \
--build-arg USER=$USER \
--build-arg USER_ID=$(id -u ${USER}) \
--build-arg USER_GID=$(id -g ${USER}) \
-t spring-native-dev:${CONTAINER_TAG} - < $DOCKER_DIR/$DEV_IMAGE
docker run --hostname docker -p 8080:8080 -v $HOST_WORK_DIR:$CONTAINER_WORK_DIR:delegated -v $HOME/.m2:$CONTAINER_HOME/.m2:delegated -it --privileged -w $CONTAINER_WORK_DIR spring-native-dev:${CONTAINER_TAG}