forked from akhikhl/gretty
-
Notifications
You must be signed in to change notification settings - Fork 36
/
docker_gradlew.sh
61 lines (46 loc) · 1.6 KB
/
docker_gradlew.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
#!/usr/bin/env bash
set -e
function build_docker_gradlew_image(){
docker build -t "docker_gradlew" . \
--build-arg JAVA_VERSIONS="$_javas" \
--build-arg GRADLE_VERSION="$_gradle"
}
function run_docker(){
build_docker_gradlew_image "$*"
local working_dir="-w //project/${_working_dir}"
local project_volume="-v //$(realpath .)://project"
local gradle_home_volume=""
if [ "$_gradle_home" ]; then
gradle_home_volume="-v //$(realpath $_gradle_home)://root/.gradle"
fi
local params="$DOCKER_ARGS $project_volume $working_dir $gradle_home_volume"
echo "RUNNING:" docker run --rm -it $params docker_gradlew "$@"
docker run --rm -it $params docker_gradlew "$@"
}
function run_docker_gradle() {
run_docker bash -lc "gradle $*"
}
JDK["8"]="8.0.412-amzn"
JDK["11"]="11.0.23-amzn"
JDK["17"]="17.0.11-amzn"
JDK["21"]="21.0.3-amzn"
GRADLE["6"]="6.9.4"
GRADLE["7"]="7.6.4"
GRADLE["8"]="8.6"
POSITIONAL_ARGS=()
while [[ $# -gt 0 ]]; do
case "$1" in
-j|--java) export _javas+=",${JDK[$2]:=$2}" && shift 2 ;;
-g|--gradle) export _gradle=${GRADLE[$2]:=$2} && shift 2 ;;
-h|--gradle-home) export _gradle_home=$2 && shift 2 ;;
-w|--working-dir) export _working_dir=$2 && shift 2 ;;
-b|--bash) export _bash="Yes" && shift 1 ;;
*) POSITIONAL_ARGS+=("$1") && shift ;;
esac
done
set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters
if [ "$_bash" ]; then
run_docker bash -l
else
run_docker_gradle "${@}"
fi