-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
executable file
·102 lines (87 loc) · 2.6 KB
/
run.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
98
99
100
101
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
# Volumes: folders shared between hosts and docker containers
export VOLUME_SLIDES="$PWD/Slides/:/data/Slides/"
export VOLUME_CAHIEREXERCICES="$PWD/CahierExercices:/data/CahierExercices"
export VOLUME_GRUNTFILE="$PWD/Gruntfile.js:/data/Gruntfile.js"
export VOLUME_PACKAGE="$PWD/package.json:/data/package.json"
export VOLUME_PDF_GENERATE="$PWD/PDF:/data/PDF"
export VOLUME_PDF_PUBLISH="$PWD/PDF:/data/node_modules/zenika-formation-framework/pdf"
# Docker image related informations
export DOCKER_IMAGE_NAME="zenika/formation-framework"
export DOCKER_IMAGE_VERSION="latest"
usage(){
echo "Usage: `basename $0` pdf|dev|prod|clean"
}
checkInstall(){
commandExists docker || { echo "docker must be installed" >&2; exit 1; }
}
commandExists(){
command -v "$1" 1>/dev/null 2>&1 \
&& return 0 || return 1
}
getDockerAddress(){
if commandExists boot2docker; then
echo `boot2docker ip`
else
echo localhost
fi
}
generatePdf(){
docker run -it --rm \
-v "$VOLUME_GRUNTFILE" -v "$VOLUME_SLIDES" -v "$VOLUME_PACKAGE" \
-v "$VOLUME_CAHIEREXERCICES" -v "$VOLUME_PDF_GENERATE" \
"$DOCKER_IMAGE_NAME":"$DOCKER_IMAGE_VERSION" \
grunt pdf
}
runProd(){
local containerName=${PWD##*/}
docker run -d -P \
-v "$VOLUME_GRUNTFILE" -v "$VOLUME_SLIDES" -v "$VOLUME_PACKAGE" \
-v "$VOLUME_CAHIEREXERCICES" -v "$VOLUME_PDF_PUBLISH" \
--name="$containerName" \
"$DOCKER_IMAGE_NAME":"$DOCKER_IMAGE_VERSION" \
grunt sed copy:rename displaySlides
local dockerPort=`docker ps -l | sed -e '2 !d' -e 's/.*:\([0-9]*\)->8000.*/\1/'`
local dockerAddress=$(getDockerAddress)
open http://$dockerAddress:$dockerPort/ || echo "Open http://$dockerAddress:$dockerPort/"
}
runDev(){
local containerName=${PWD##*/}
docker run -d -P \
-v "$VOLUME_GRUNTFILE" -v "$VOLUME_SLIDES" -v "$VOLUME_PACKAGE" \
-v "$VOLUME_CAHIEREXERCICES" -v "$VOLUME_PDF_PUBLISH" \
--name="$containerName" \
"$DOCKER_IMAGE_NAME":"$DOCKER_IMAGE_VERSION" \
grunt displaySlides
local dockerPort=`docker ps -l | sed -e '2 !d' -e 's/.*:\([0-9]*\)->8000.*/\1/'`
local dockerAddress=$(getDockerAddress)
open http://$dockerAddress:$dockerPort/ || echo "Open http://$dockerAddress:$dockerPort/"
}
clean(){
local containerName=${PWD##*/}
docker stop "$containerName" | xargs docker rm
}
if [ "$#" -ne 1 ]; then
usage
exit 1
fi
checkInstall
case "$1" in
pdf)
generatePdf
;;
dev)
runDev
;;
prod)
runProd
;;
clean)
clean
;;
*)
usage # unknown option
;;
esac