forked from KxSystems/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
local.sh
executable file
·71 lines (60 loc) · 1.83 KB
/
local.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
#!/bin/bash
# title: Build MkDocs instance in KX Docker image for MkDocs for use from isolated filesystem
# required: Docker
# usage: ./local.sh
# sanity check
# ============
if [ ! -d docs ]; then
echo '*** ERROR*** No docs folder found'
exit 1
fi
localdir=local
tempdir=docs/local
site=https://code.kx.com
user=$(whoami)
# map local to remote user
if [ $user == 'sjt' ]; then
user='stephen'
fi
echo "### Copying resources from $site"
rm -f $tempdir local.yml
mkdir $tempdir
wget -r -np -nH -P $tempdir $site/favicon.ico $site/img/ $site/scripts/ $site/stylesheets/
echo '### Deriving temporary config'
rm -f local.yml
cat base-config.yml mkdocs.yml | sed \
-e 's#^INHERIT.*##' \
-e 's#^site_url.*$#site_url: ""#' \
-e 's#favicon: https://code.kx.com/#favicon: local/#' \
-e 's#logo: https://code.kx.com/#logo: local/#' \
-e 's#- https://code.kx.com/#- local/#' \
-e 's#- scripts/qsearch\.js##' \
> local.yml
echo "### Building docs in $localdir/"
# DOCKER_IMAGE='registry.gitlab.com/kxdev/documentation/framework/mkdocs-build'
docker_image="$(cat docker-image-name.txt):$(cat docker-image-version.txt)"
work_dir="/docs"
mnt="type=bind,source=$(pwd),target=$work_dir"
cmd="build --clean -f local.yml --no-directory-urls --site-dir $localdir"
docker run --rm --mount $mnt --workdir $work_dir $docker_image $cmd
zip -r q.zip $localdir
if ( $? ); then
echo "*** ERROR *** Failed to build $localdir/"
exit 2
fi
echo "### Zipping $localdir"
zip -r local.zip $localdir
if ( $? ); then
echo "*** ERROR *** Failed to zip $localdir/"
exit 3
fi
echo "### Copying to $site"
scp local.zip [email protected]:/var/www/download/q.zip
if ( $? ); then
echo '*** ERROR *** Failed to upload local.zip'
exit 4
fi
echo '### Cleaning up'
rm -fr $tempdir $localdir local.yml local.zip
echo "### Static site built in $localdir/"
echo '### DONE: subsite zipped and uploaded'