Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 63 lines (51 sloc) 1.37 KB
#!/usr/bin/env bash
usage() {
echo "Usage: $( basename "${BASH_SOURCE}" ) <fg|bg> [--public|-p] | build" 1>&2
exit 1
}
run_docker() {
local name=$1; shift
local options="$1"; shift
docker run \
--name=${name} \
${options} \
--env="BUNDLE_CACHE=true" \
--volume=$( pwd ):/srv/jekyll \
jekyll/jekyll \
"$@"
}
kill_container() {
local name="$1"
local container_id=$( docker ps -qa --filter="name=${name}" )
[[ -n ${container_id} ]] && docker rm --force ${container_id}
}
jekyll_foreground() {
local publish_ip=127.0.0.1
[[ $1 == '--public' || $1 == '-p' ]] && publish_ip=0.0.0.0
kill_container "jekyll-serve"
run_docker "jekyll-serve" \
"--publish=${publish_ip}:4000:4000 --interactive --tty" \
bundle exec jekyll server --watch
}
jekyll_background() {
local publish_ip=127.0.0.1
[[ $1 == '--public' || $1 == '-p' ]] && publish_ip=0.0.0.0
kill_container "jekyll-serve"
run_docker "jekyll-serve" \
"--publish=${publish_ip}:4000:4000 --detach" \
bundle exec jekyll server --watch
}
jekyll_build() {
[[ $# > 0 ]] && usage
kill_container "jekyll-build"
run_docker "jekyll-build" "" bundle exec jekyll build
}
MYBASE=$( dirname "${BASH_SOURCE}" )/..
[[ $# < 1 || $# > 2 ]] && usage
CDPATH="" cd $MYBASE
case $1 in
fg) jekyll_foreground $2;;
bg) jekyll_background $2;;
build) jekyll_build $2;;
*) usage ;;
esac