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
This commit is contained in:
Cotes Chung 2020-10-10 14:06:16 +08:00
parent e806a8556b
commit 2a2bc1ee65

View file

@ -18,6 +18,7 @@ CONTAINER="${WORK_DIR}/.container"
SYNC_TOOL=_scripts/sh/sync_monitor.sh SYNC_TOOL=_scripts/sh/sync_monitor.sh
cmd="bundle exec jekyll s" cmd="bundle exec jekyll s"
JEKYLL_DOCKER_HOME="/srv/jekyll"
realtime=false realtime=false
docker=false docker=false
@ -45,13 +46,15 @@ _cleanup() {
_setup_docker() { _setup_docker() {
# docker image `jekyll/jekyll` based on Alpine Linux # docker image `jekyll/jekyll` based on Alpine Linux
echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories 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 update
apk add yq apk add yq
chown -R jekyll:jekyll "$CONTAINER"
} }
_init() { _init() {
cd "$WORK_DIR"
if [[ -f Gemfile.lock ]]; then if [[ -f Gemfile.lock ]]; then
rm -f Gemfile.lock rm -f Gemfile.lock
fi fi
@ -60,10 +63,19 @@ _init() {
rm -rf "$CONTAINER" rm -rf "$CONTAINER"
fi fi
local temp="$(mktemp -d)" mkdir "$CONTAINER"
cp -r ./* "$temp" cp -r ./* "$CONTAINER"
cp -r ./.git "$temp" cp -r ./.git "$CONTAINER"
mv "$temp" "$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 trap _cleanup INT
} }
@ -114,12 +126,11 @@ _run() {
} }
main() { main() {
_init
if $docker; then if $docker; then
_setup_docker _setup_docker
fi fi
_init
_run _run
} }