Add docker option to the tools.

This commit is contained in:
Cotes Chung 2020-10-08 16:00:08 +08:00
parent d314c02a13
commit 8f11f91677
2 changed files with 52 additions and 4 deletions

View file

@ -16,20 +16,34 @@ CONTAINER="${WORK_DIR}/.container"
DEST="${WORK_DIR}/_site"
docker=false
_help() {
echo "Usage:"
echo
echo " bash build.sh [options]"
echo
echo "Options:"
echo " -b, --baseurl <URL> The site relative url that start with slash, e.g. '/project'"
echo " -h, --help Print the help information"
echo " -d, --destination <DIR> Destination directory (defaults to ./_site)"
echo " -b, --baseurl <URL> The site relative url that start with slash, e.g. '/project'"
echo " -h, --help Print the help information"
echo " -d, --destination <DIR> Destination directory (defaults to ./_site)"
echo " --docker Build site within docker"
}
_install_tools() {
# docker image `jekyll/jekyll` based on Apline Linux
echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories
apk update
apk add yq
}
_init() {
cd "$WORK_DIR"
if [[ -f Gemfile.lock ]]; then
rm -f Gemfile.lock
fi
if [[ -d $CONTAINER ]]; then
rm -rf "$CONTAINER"
fi
@ -93,6 +107,10 @@ main() {
shift
shift
;;
--docker)
docker=true
shift
;;
-h | --help)
_help
exit 0
@ -104,6 +122,10 @@ main() {
esac
done
if $docker; then
_install_tools
fi
_init
_build
}

View file

@ -17,8 +17,9 @@ WORK_DIR="$(dirname "$(dirname "$(realpath "$0")")")"
CONTAINER=.container
SYNC_TOOL=_scripts/sh/sync_monitor.sh
cmd="bundle exec jekyll s -l -o"
cmd="bundle exec jekyll s -l"
realtime=false
docker=false
_help() {
echo "Usage:"
@ -32,6 +33,7 @@ _help() {
echo " -h, --help Print the help information"
echo " -t, --trace Show the full backtrace when an error occurs"
echo " -r, --realtime Make the modified content updated in real time"
echo " --docker Run within docker"
}
_cleanup() {
@ -44,6 +46,9 @@ _cleanup() {
}
_init() {
if [[ -f Gemfile.lock ]]; then
rm -f Gemfile.lock
fi
if [[ -d "${WORK_DIR}/${CONTAINER}" ]]; then
rm -rf "${WORK_DIR}/${CONTAINER}"
@ -72,9 +77,20 @@ _check_command() {
fi
}
_install_tools() {
# docker image `jekyll/jekyll` based on Apline Linux
echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories
apk update
apk add yq
}
main() {
_init
if $docker; then
_install_tools
fi
cd "${WORK_DIR}/${CONTAINER}"
bash _scripts/sh/create_pages.sh
bash _scripts/sh/dump_lastmod.sh
@ -94,6 +110,12 @@ main() {
"$WORK_DIR" | xargs -0 -I {} bash "./${SYNC_TOOL}" {} "$WORK_DIR" . &
fi
if ! $docker; then
cmd+=" -o"
else
cmd+=" -H 0.0.0.0"
fi
echo "\$ $cmd"
eval "$cmd"
}
@ -133,6 +155,10 @@ while (($#)); do
realtime=true
shift
;;
--docker)
docker=true
shift
;;
-h | --help)
_help
exit 0