forked from amazon-ion/ion-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-docker.sh
executable file
·89 lines (71 loc) · 1.91 KB
/
build-docker.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
#!/bin/bash
# Arguments are passed-through to Rake.
source run_check.sh
set -e
IMAGE_TAG="ion-spec-asciidoc"
#DOCKER_ARGS="--platform linux/amd64"
DOCKER_ARGS=""
function build_image()
{
run_check docker build ${DOCKER_ARGS} \
--tag "${IMAGE_TAG}" \
--build-arg USER_ID="$(id -u)" \
--build-arg GROUP_ID="$(id -g)" \
"$(pwd)"
}
function run_inside()
{
# --rm Automatically remove the container when it exits
run_check docker run ${DOCKER_ARGS} \
--interactive --tty --rm \
--mount type=bind,source="$(pwd)",target=/workspace \
"${IMAGE_TAG}" \
"$@"
}
function execute_build_logic()
{
run_inside /bin/bash --login docker-run.sh "$@"
}
function start_shell()
{
run_inside /bin/bash "$@"
}
#===============================================================================
function usage()
{
echo "Usage: " "$0" "[-h] [-r] [-b] [-s]"
echo
echo " -h Show this help."
echo " -u Update the Docker image."
echo " -b Execute the build logic (docker-run.sh) inside a new container."
echo " -s Start a shell inside a new container."
echo
echo "By default, when none of -ubs are given then -ub is assumed."
echo
echo "From a shell inside a container, you can run the build logic directly"
echo "via 'rake'. Run 'rake -T' to see the tasks our Rakefile defines."
}
while getopts ":ubsh" o; do
case "$o" in
h) usage; exit;;
u) do_update=true;;
b) do_build=true;;
s) do_shell=true;;
*) echo "illegal option -$OPTARG"; usage; exit 1;;
esac
done
shift $((OPTIND-1))
unset OPTIND
if [[ -z $do_update$do_build$do_shell ]]
then
do_update=true
do_build=true
fi
# FIXME -bs should give a shell inside the -b container.
if [[ $do_build$do_shell = truetrue ]]
then
echo "WARNING: -b and -s use separate containers!"
fi
[[ -n $do_update ]] && build_image
[[ -n $do_build ]] && execute_build_logic "$@"
[[ -n $do_shell ]] && start_shell "$@"