diff --git a/docker/Dockerfile b/docker/Dockerfile index b2ab56be0..38f771217 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -11,7 +11,7 @@ ENV PUSERNAME=${PUSERNAME} PUID=${PUID} PGID=${PGID} \ TERM=${TERM} ZINIT_ZSH_VERSION=${ZINIT_ZSH_VERSION} RUN apk --no-cache --virtual base add \ - zsh curl git libuser sudo && \ + zsh curl git libuser sudo rsync && \ apk --no-cache --virtual build-tools add \ build-base autoconf ncurses-dev bash go @@ -19,8 +19,8 @@ RUN sed -ir 's#^(root:.+):/bin/ash#\1:/bin/zsh#' /etc/passwd && \ adduser -D -s /bin/zsh -u "${PUID}" -h "/home/${PUSERNAME}" \ "${PUSERNAME}" && \ printf "${PUSERNAME} ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/user && \ - mkdir -p /src /data && \ - chown -R "${PUID}:${PGID}" /data && \ + mkdir -p /src /data /data-static && \ + chown -R "${PUID}:${PGID}" /data /data-static && \ ln -sfv /src/docker/zshenv /home/${PUSERNAME}/.zshenv && \ ln -sfv /src/docker/zshrc /home/${PUSERNAME}/.zshrc @@ -33,8 +33,7 @@ USER ${PUSERNAME} # Fetch keys config and store it outside of ZINIT[HOME_DIR] since it might get # overridden at runtime (the /data volume) -RUN zsh -ils -c -- '@zinit-scheduler burst' && \ - cp -vf /data/snippets/OMZL::key-bindings.zsh/OMZL::key-bindings.zsh \ - /home/${PUSERNAME}/OMZL::key-bindings.zsh +RUN ZINIT_HOME_DIR=/data-static ZSH_NO_INIT=1 \ + zsh -ils -c -- '@zinit-scheduler burst' CMD ["/bin/zsh"] diff --git a/docker/init.zsh b/docker/init.zsh new file mode 100644 index 000000000..f03c83701 --- /dev/null +++ b/docker/init.zsh @@ -0,0 +1,18 @@ +# Fix permissions on /data +if [[ -z "$QUIET" ]] +then + echo "Setting owner of /data to ${PUID}:${PGID}" >&2 +fi + +sudo chown "${PUID}:${PGID}" /data +sudo chown -R "${PUID}:${PGID}" /data + +# sync files between /data-static and /data +if [[ -z "$NOTHING_FANCY" ]] +then + if [[ -z "$QUIET" ]] + then + echo "Copying files from /data-static to /data" >&2 + fi + rsync -raq /data-static/ /data +fi diff --git a/docker/utils.zsh b/docker/utils.zsh index 4c5fded4c..ef68adb78 100644 --- a/docker/utils.zsh +++ b/docker/utils.zsh @@ -5,14 +5,7 @@ zinit::setup() { } zinit::setup-keys() { - local file="${HOME}/OMZL::key-bindings.zsh" - - if [[ -r "$file" ]] - then - source "$file" - else - zinit snippet OMZL::key-bindings.zsh - fi + zinit snippet OMZL::key-bindings.zsh } zinit::setup-annexes() { diff --git a/docker/zshenv b/docker/zshenv index 7d08b1271..c43684b5e 100644 --- a/docker/zshenv +++ b/docker/zshenv @@ -4,5 +4,7 @@ export TERM=${TERM:-xterm-256color} typeset -Ag ZINIT -export ZINIT[HOME_DIR]=/data +# ZINIT_HOME_DIR is used at build time to force the installation of plugins +# etc to /data-static +export ZINIT[HOME_DIR]=${ZINIT_HOME_DIR:-/data} export ZINIT[BIN_DIR]=/src diff --git a/docker/zshrc b/docker/zshrc index ad424a65d..64e2417ca 100644 --- a/docker/zshrc +++ b/docker/zshrc @@ -1,20 +1,20 @@ -# Fix permissions on /data (run only once, at startup) -if [[ "$$" == 1 ]] +# Initialization. Trigger stuff that only needs to be run once, at startup. +if [[ "$$" == 1 ]] && [[ -z "$ZSH_NO_INIT" ]] then - if [[ -z "$QUIET" ]] - then - echo "Setting owner of /data to ${PUID}:${PGID}" >&2 - fi - sudo chown /data - sudo chown -R "${PUID}:${PGID}" /data + source /src/docker/init.zsh fi # load zinit source /src/zinit.zsh +autoload -Uz _zinit +(( ${+_comps} )) && _comps[zinit]=_zinit # load zinit setup utility functions source /src/docker/utils.zsh +# Annexes +[[ -z "$NOTHING_FANCY" ]] && zinit::setup-annexes + # Add ZPFX/bin to PATH typeset -U path path=("${ZPFX:-${HOME}/.local/share/zinit/polaris}/bin" $path) @@ -33,6 +33,6 @@ then fi # Setup keys -zinit::setup-keys +[[ -z "$NOTHING_FANCY" ]] && zinit::setup-keys # vim: ft=zsh et ts=2 sw=2 : diff --git a/scripts/docker-run.sh b/scripts/docker-run.sh index 7b104ec61..da059f8f7 100755 --- a/scripts/docker-run.sh +++ b/scripts/docker-run.sh @@ -209,6 +209,7 @@ then ) CONTAINER_ENV+=( "QUIET=1" + "NOTHING_FANCY=1" ) fi