diff --git a/tools/build.sh b/tools/build.sh index 4d1c58a..8b7a5c2 100755 --- a/tools/build.sh +++ b/tools/build.sh @@ -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 The site relative url that start with slash, e.g. '/project'" - echo " -h, --help Print the help information" - echo " -d, --destination Destination directory (defaults to ./_site)" + echo " -b, --baseurl The site relative url that start with slash, e.g. '/project'" + echo " -h, --help Print the help information" + echo " -d, --destination 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 } diff --git a/tools/run.sh b/tools/run.sh index 938256e..31c16f5 100755 --- a/tools/run.sh +++ b/tools/run.sh @@ -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