-
Notifications
You must be signed in to change notification settings - Fork 53
/
run-docker
executable file
·51 lines (44 loc) · 1.53 KB
/
run-docker
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
#!/bin/sh
set -e
cd $(dirname "$0")
if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
echo "Usage: $0 [command]"
echo "Tool to help building and running containers to compile (default action) or serve the website"
echo "Commands:"
echo " -h, --help Display this help and exit"
echo " --recreate Rebuild docker image"
echo " --force Remove ruby cache volume and Rebuild docker image"
echo " --serve Serve the website instead of building it"
exit
fi
IMAGE_NAME="fusionauth-site:latest"
RUBY_CACHE_VOLUME_NAME="fusionauth-site-ruby"
SAVANT_CACHE_VOLUME_NAME="fusionauth-site-savant"
# Building docker image
if [ "$1" = "--recreate" ] || [ "$(docker images -q "${IMAGE_NAME}" 2> /dev/null)" = "" ]; then
docker build --no-cache --pull -t "${IMAGE_NAME}" .
if [ "$1" = "--recreate" ]; then
shift
fi
fi
# Building docker image
if [ "$1" = "--force" ] || [ "$(docker images -q "${IMAGE_NAME}" 2> /dev/null)" = "" ]; then
docker volume rm $RUBY_CACHE_VOLUME_NAME
docker volume rm $SAVANT_CACHE_VOLUME_NAME
docker build --no-cache --pull -t "${IMAGE_NAME}" .
if [ "$1" = "--force" ]; then
shift
fi
fi
# Default command is "sb compile" from the image
COMMAND=""
if [ "$1" = "--serve" ]; then
echo "Will serve at http://localhost:4000/"
COMMAND="sb serve"
fi
docker run --rm \
-v "${PWD}:/srv/jekyll" \
-v "${RUBY_CACHE_VOLUME_NAME}:/usr/local/bundle" \
-v "${SAVANT_CACHE_VOLUME_NAME}:/root/.savant" \
-p "4000:4000" -it \
"${IMAGE_NAME}" $COMMAND