-
Notifications
You must be signed in to change notification settings - Fork 1
/
docker.test.sh
executable file
·70 lines (60 loc) · 1.85 KB
/
docker.test.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
#!/bin/bash -eu
function run_container() {
DOCKER_IMAGE="obmc-webapp-server"
CID=
function on_exit {
# Completely remove container after usage
[[ -z "${CID}" ]] || docker rm --force --volumes "${CID}" > /dev/null
}
trap on_exit EXIT
SOURCE_DIR="${SOURCE_DIR:-$(realpath $(dirname ${BASH_SOURCE[0]}))}"
[[ -d ${DLCACHE_DIR:-} ]] && DLCACHE_OPT="--volume ${DLCACHE_DIR}:${DLCACHE_DIR}:Z" || DLCACHE_OPT=
[[ -t 1 ]] && PASSTTY_OPT="--tty" || PASSTTY_OPT=
CID=$(docker create \
${PASSTTY_OPT} \
--interactive \
--env HOME=/source/build/ \
--env "SSH_AUTH_SOCK=/ssh-agent" \
--tmpfs /tmp \
--tmpfs /run \
--tmpfs /run/lock \
--volume "${SOURCE_DIR}":/source:Z \
--volume "${SSH_AUTH_SOCK}":/ssh-agent \
--volume /sys/fs/cgroup:/sys/fs/cgroup:ro \
--volume /run/systemd/journal/socket:/run/systemd/journal/socket \
--publish 18081:18081 \
--publish 30022:22 \
--privileged \
${DLCACHE_OPT} \
--workdir "${SOURCE_DIR}" \
"${DOCKER_IMAGE}" \
"$@")
docker start --attach --interactive ${CID}
}
function build_docker_images() {
echo "Build 'obmc-webapp-base' image..."
docker build --no-cache --force-rm -t obmc-webapp-base -f Dockerfile.base .
echo "Build 'obmc-webapp-server' image..."
docker build --no-cache --force-rm -t obmc-webapp-server -f Dockerfile .
echo "Building obmc-webapp docker images are successful."
}
COMMAND=${1:-"run"}
case "${COMMAND}" in
run)
mkdir -p build
run_container "$@"
exit
;;
build)
build_docker_images
exit
;;
help)
echo "Usage: ${0} run|build|help"
exit
;;
*)
echo "Unknown command: ${COMMAND}" >&1
exit
;;
esac