Skip to content

Commit

Permalink
Fix files r/w permissions under Linux Docker (#145)
Browse files Browse the repository at this point in the history
also improve the scripts
  • Loading branch information
cotes2020 committed Oct 9, 2020
1 parent 049b486 commit e806a85
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 32 deletions.
2 changes: 1 addition & 1 deletion tools/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ _help() {
}

_install_tools() {
# docker image `jekyll/jekyll` based on Apline Linux
# docker image `jekyll/jekyll` based on Alpine Linux
echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories
apk update
apk add yq
Expand Down
65 changes: 34 additions & 31 deletions tools/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ set -eu

WORK_DIR="$(dirname "$(dirname "$(realpath "$0")")")"

CONTAINER=.container
CONTAINER="${WORK_DIR}/.container"
SYNC_TOOL=_scripts/sh/sync_monitor.sh

cmd="bundle exec jekyll s -l"
cmd="bundle exec jekyll s"

realtime=false
docker=false

Expand All @@ -37,27 +38,32 @@ _help() {
}

_cleanup() {
if [[ -d _site || -d .jekyll-cache ]]; then
jekyll clean
fi

rm -rf "${WORK_DIR}/${CONTAINER}"
rm -rf "$CONTAINER"
ps aux | grep fswatch | awk '{print $2}' | xargs kill -9 > /dev/null 2>&1
}

_setup_docker() {
# docker image `jekyll/jekyll` based on Alpine Linux
echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories
apk update
apk add yq

chown -R jekyll:jekyll "$CONTAINER"
}

_init() {
if [[ -f Gemfile.lock ]]; then
rm -f Gemfile.lock
fi

if [[ -d "${WORK_DIR}/${CONTAINER}" ]]; then
rm -rf "${WORK_DIR}/${CONTAINER}"
if [[ -d $CONTAINER ]]; then
rm -rf "$CONTAINER"
fi

temp="$(mktemp -d)"
cp -r "$WORK_DIR"/* "$temp"
cp -r "${WORK_DIR}/.git" "$temp"
mv "$temp" "${WORK_DIR}/${CONTAINER}"
local temp="$(mktemp -d)"
cp -r ./* "$temp"
cp -r ./.git "$temp"
mv "$temp" "$CONTAINER"

trap _cleanup INT
}
Expand All @@ -77,21 +83,8 @@ _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}"
_run() {
cd "$CONTAINER"
bash _scripts/sh/create_pages.sh
bash _scripts/sh/dump_lastmod.sh

Expand All @@ -110,16 +103,26 @@ main() {
"$WORK_DIR" | xargs -0 -I {} bash "./${SYNC_TOOL}" {} "$WORK_DIR" . &
fi

if ! $docker; then
cmd+=" -o"
else
if $docker; then
cmd+=" -H 0.0.0.0"
else
cmd+=" -l -o"
fi

echo "\$ $cmd"
eval "$cmd"
}

main() {
_init

if $docker; then
_setup_docker
fi

_run
}

while (($#)); do
opt="$1"
case $opt in
Expand Down

0 comments on commit e806a85

Please sign in to comment.