-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-entrypoint.sh
executable file
·72 lines (51 loc) · 1.77 KB
/
docker-entrypoint.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
#!/bin/sh
set -e
echo -e "[Entrypoint] mkdocs docker image for generating site.tar.gz and serving the file over the HTTP Server"
if [ "$1" = 'produce' ]; then
echo $2
if [ ! -d "$2" ]; 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 '=================================================================='
exit 1
fi
#Switch to mkdocs Directory
cd "$2"
#Check mkdocs.yml file exist
if [ ! -f "mkdocs.yml" ]; then
echo -e 'Unable to Locate mkdocs.yml config file '
exit 1
fi
#Build the mkdocs dirctory
mkdocs build --clean
if [ ! -f "site.tar.gz" ]; then
#Clean it
rm -rf site.tar.gz
fi
#Create the TAR Arhive
tar czf site.tar.gz *
#Place the TAR Arhive in the ROOT mount LOcation
mv site.tar.gz ../
echo -e 'mkdocs file generated site.tar.gz and ready to serve'
elif [ "$1" = 'serve' ]; then
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 'docker run -v $PWD:/var/mkdocs mkdocs produce <directoryName>'
echo -e '=================================================================='
exit 1
fi
# Create Location for the html file where mkdocs will be served
mkdir -p /opt/www
#Clean the Directory
rm -rf /opt/www/*
# Extract the tar gz file to a new www Location
tar xf site.tar.gz -C /opt/www
# Switch to the WWW directory
cd /opt/www
# Server the file
mkdocs serve --dev-addr=0.0.0.0:8000
else
exec "$@"
fi