-
Notifications
You must be signed in to change notification settings - Fork 48
/
mkdockerize.sh
executable file
·99 lines (84 loc) · 3.27 KB
/
mkdockerize.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
#!/bin/bash
#
# a simple way to parse shell script arguments
#
# please edit and use to your hearts content
#
MKDOCS="my-project"
function usage()
{
echo "mkdockerize for buidling and serving the mkdocs project using Docker "
echo ""
echo "./mkdockerize.sh"
echo -e "-h --help"
echo -e "--produce=PROJECT-DIR"
echo -e "--serve {For running the mkdocs project inside docker}"
echo -e "--build {For Buidling the Docker Image}"
echo ""
}
while [ "$1" != "" ]; do
PARAM=`echo $1 | awk -F= '{print $1}'`
VALUE=`echo $1 | awk -F= '{print $2}'`
case $PARAM in
-h | --help)
usage
exit
;;
--produce)
WORK_DIR=$PWD
if [ ! -d "$VALUE" ]; then
echo -e 'Unable to Locate Mkdocs Directory. Please Use the Correct Argument'
echo -e '=================================================================='
echo -e 'docker run -v $PWD:/var/mkdocs mkdocs produce <directoryName>'
echo -e 'docker run -v $PWD:/var/mkdocs mkdocs produce my-project'
echo -e '=================================================================='
exit 1
fi
echo -e "Validating $VALUE"
#Switch to mkdocs Directory
cd "$VALUE"
#Check mkdocs.yml file exist
if [ ! -f "mkdocs.yml" ]; then
echo 'Unable to Locate mkdocs.yml config file '
exit 1
fi
cd ..
echo "MKDOCS Directory is Valid Producting site.tar.gz file"
docker run -v $PWD:/var/mkdocs mkdocs produce $VALUE
;;
--serve)
if [ ! -f "site.tar.gz" ]; then
echo -e 'Unable to locate mkdocs [site.tar.gz] tar file, Please generate it by issuing the below command '
echo -e '=================================================================='
echo -e './mkdockerize.sh --produce=my-project'
echo -e '=================================================================='
exit 1
fi
echo -e "Starting the mkdocs server on port 8000"
CONTAINER=`docker ps | grep mkdocs | awk -F" " '{print $1}'`
if [ -z "$CONTAINER" ]
then
docker run -d -p 8000:8000 -v $PWD:/var/mkdocs mkdocs serve
CONTAINER=`docker ps | grep mkdocs | awk -F" " '{print $1}'`
echo -e "Docker Container $CONTAINER started on port 8000"
else
docker kill $CONTAINER
docker run -d -p 8000:8000 -v $PWD:/var/mkdocs mkdocs serve
CONTAINER=`docker ps | grep mkdocs | awk -F" " '{print $1}'`
echo -e "Docker Container $CONTAINER started on port 8000"
fi
;;
--build)
echo "Executing docker build -t mkdocs . "
echo "-------------------"
docker build -t mkdocs .
echo "-------------------"
;;
*)
echo "ERROR: unknown parameter \"$PARAM\""
usage
exit 1
;;
esac
shift
done