Skip to content

Commit b22bcb8

Browse files
committed
Add docker option to the tools.
1 parent e17943d commit b22bcb8

2 files changed

Lines changed: 52 additions & 4 deletions

File tree

tools/build.sh

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,34 @@ CONTAINER="${WORK_DIR}/.container"
1616

1717
DEST="${WORK_DIR}/_site"
1818

19+
docker=false
20+
1921
_help() {
2022
echo "Usage:"
2123
echo
2224
echo " bash build.sh [options]"
2325
echo
2426
echo "Options:"
25-
echo " -b, --baseurl <URL> The site relative url that start with slash, e.g. '/project'"
26-
echo " -h, --help Print the help information"
27-
echo " -d, --destination <DIR> Destination directory (defaults to ./_site)"
27+
echo " -b, --baseurl <URL> The site relative url that start with slash, e.g. '/project'"
28+
echo " -h, --help Print the help information"
29+
echo " -d, --destination <DIR> Destination directory (defaults to ./_site)"
30+
echo " --docker Build site within docker"
31+
}
32+
33+
_install_tools() {
34+
# docker image `jekyll/jekyll` based on Apline Linux
35+
echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories
36+
apk update
37+
apk add yq
2838
}
2939

3040
_init() {
3141
cd "$WORK_DIR"
3242

43+
if [[ -f Gemfile.lock ]]; then
44+
rm -f Gemfile.lock
45+
fi
46+
3347
if [[ -d $CONTAINER ]]; then
3448
rm -rf "$CONTAINER"
3549
fi
@@ -93,6 +107,10 @@ main() {
93107
shift
94108
shift
95109
;;
110+
--docker)
111+
docker=true
112+
shift
113+
;;
96114
-h | --help)
97115
_help
98116
exit 0
@@ -104,6 +122,10 @@ main() {
104122
esac
105123
done
106124

125+
if $docker; then
126+
_install_tools
127+
fi
128+
107129
_init
108130
_build
109131
}

tools/run.sh

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ WORK_DIR="$(dirname "$(dirname "$(realpath "$0")")")"
1717
CONTAINER=.container
1818
SYNC_TOOL=_scripts/sh/sync_monitor.sh
1919

20-
cmd="bundle exec jekyll s -l -o"
20+
cmd="bundle exec jekyll s -l"
2121
realtime=false
22+
docker=false
2223

2324
_help() {
2425
echo "Usage:"
@@ -32,6 +33,7 @@ _help() {
3233
echo " -h, --help Print the help information"
3334
echo " -t, --trace Show the full backtrace when an error occurs"
3435
echo " -r, --realtime Make the modified content updated in real time"
36+
echo " --docker Run within docker"
3537
}
3638

3739
_cleanup() {
@@ -44,6 +46,9 @@ _cleanup() {
4446
}
4547

4648
_init() {
49+
if [[ -f Gemfile.lock ]]; then
50+
rm -f Gemfile.lock
51+
fi
4752

4853
if [[ -d "${WORK_DIR}/${CONTAINER}" ]]; then
4954
rm -rf "${WORK_DIR}/${CONTAINER}"
@@ -72,9 +77,20 @@ _check_command() {
7277
fi
7378
}
7479

80+
_install_tools() {
81+
# docker image `jekyll/jekyll` based on Apline Linux
82+
echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories
83+
apk update
84+
apk add yq
85+
}
86+
7587
main() {
7688
_init
7789

90+
if $docker; then
91+
_install_tools
92+
fi
93+
7894
cd "${WORK_DIR}/${CONTAINER}"
7995
bash _scripts/sh/create_pages.sh
8096
bash _scripts/sh/dump_lastmod.sh
@@ -94,6 +110,12 @@ main() {
94110
"$WORK_DIR" | xargs -0 -I {} bash "./${SYNC_TOOL}" {} "$WORK_DIR" . &
95111
fi
96112

113+
if ! $docker; then
114+
cmd+=" -o"
115+
else
116+
cmd+=" -H 0.0.0.0"
117+
fi
118+
97119
echo "\$ $cmd"
98120
eval "$cmd"
99121
}
@@ -133,6 +155,10 @@ while (($#)); do
133155
realtime=true
134156
shift
135157
;;
158+
--docker)
159+
docker=true
160+
shift
161+
;;
136162
-h | --help)
137163
_help
138164
exit 0

0 commit comments

Comments
 (0)