From 2a2bc1ee6590708c7c982795e66e241a5a6cc49f Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Sat, 10 Oct 2020 14:06:16 +0800 Subject: [PATCH] Fix compatibility with Docker Desktop (for Mac) on Docker Desktop CE (Mac) 2.4.0.0 - command `mv` will cause permission preserve error - command `chown` will get I/O error --- tools/run.sh | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/tools/run.sh b/tools/run.sh index 88492aa..ca11733 100755 --- a/tools/run.sh +++ b/tools/run.sh @@ -18,6 +18,7 @@ CONTAINER="${WORK_DIR}/.container" SYNC_TOOL=_scripts/sh/sync_monitor.sh cmd="bundle exec jekyll s" +JEKYLL_DOCKER_HOME="/srv/jekyll" realtime=false docker=false @@ -45,13 +46,15 @@ _cleanup() { _setup_docker() { # docker image `jekyll/jekyll` based on Alpine Linux echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories + ## CN Apline sources mirror + # sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories apk update apk add yq - - chown -R jekyll:jekyll "$CONTAINER" } _init() { + cd "$WORK_DIR" + if [[ -f Gemfile.lock ]]; then rm -f Gemfile.lock fi @@ -60,10 +63,19 @@ _init() { rm -rf "$CONTAINER" fi - local temp="$(mktemp -d)" - cp -r ./* "$temp" - cp -r ./.git "$temp" - mv "$temp" "$CONTAINER" + mkdir "$CONTAINER" + cp -r ./* "$CONTAINER" + cp -r ./.git "$CONTAINER" + + if $docker; then + local _image_user=$(stat -c "%U" "$JEKYLL_DOCKER_HOME"/.) + + if [[ $_image_user != $(whoami) ]]; then + # under Docker for Linux + chown -R "$(stat -c "%U:%G" "$JEKYLL_DOCKER_HOME"/.)" "$CONTAINER" + fi + + fi trap _cleanup INT } @@ -114,12 +126,11 @@ _run() { } main() { - _init - if $docker; then _setup_docker fi + _init _run }