From 6f728c3031777504318b20d4ad838050f4a5fcc9 Mon Sep 17 00:00:00 2001 From: Philipp Schmitt Date: Mon, 22 Nov 2021 22:46:22 +0100 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=90=B3=20Add=20annexes=20to=20contain?= =?UTF-8?q?er?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker/Dockerfile | 11 +++++------ docker/init.zsh | 15 +++++++++++++++ docker/utils.zsh | 9 +-------- docker/zshenv | 4 +++- docker/zshrc | 14 ++++++-------- 5 files changed, 30 insertions(+), 23 deletions(-) create mode 100644 docker/init.zsh 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..de5a05ec9 --- /dev/null +++ b/docker/init.zsh @@ -0,0 +1,15 @@ +# 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 "$QUIET" ]] +then + echo "Copying files from /data-static to /data" >&2 +fi +rsync -raq /data-static/ /data 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..cde144665 100644 --- a/docker/zshrc +++ b/docker/zshrc @@ -1,12 +1,7 @@ -# 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 @@ -15,6 +10,9 @@ source /src/zinit.zsh # load zinit setup utility functions source /src/docker/utils.zsh +# Annexes +zinit::setup-annexes + # Add ZPFX/bin to PATH typeset -U path path=("${ZPFX:-${HOME}/.local/share/zinit/polaris}/bin" $path) From cc3f33411c79a629dd3c365b7fb58ea447c831cd Mon Sep 17 00:00:00 2001 From: Philipp Schmitt Date: Mon, 22 Nov 2021 22:54:04 +0100 Subject: [PATCH 2/3] Disable almost all custom mechanisms by setting NOTHING_FANCY at runtime --- docker/init.zsh | 9 ++++++--- docker/zshrc | 4 ++-- scripts/docker-run.sh | 1 + 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/docker/init.zsh b/docker/init.zsh index de5a05ec9..f03c83701 100644 --- a/docker/init.zsh +++ b/docker/init.zsh @@ -8,8 +8,11 @@ sudo chown "${PUID}:${PGID}" /data sudo chown -R "${PUID}:${PGID}" /data # sync files between /data-static and /data -if [[ -z "$QUIET" ]] +if [[ -z "$NOTHING_FANCY" ]] then - echo "Copying files from /data-static to /data" >&2 + if [[ -z "$QUIET" ]] + then + echo "Copying files from /data-static to /data" >&2 + fi + rsync -raq /data-static/ /data fi -rsync -raq /data-static/ /data diff --git a/docker/zshrc b/docker/zshrc index cde144665..0d8da5523 100644 --- a/docker/zshrc +++ b/docker/zshrc @@ -11,7 +11,7 @@ source /src/zinit.zsh source /src/docker/utils.zsh # Annexes -zinit::setup-annexes +[[ -z "$NOTHING_FANCY" ]] && zinit::setup-annexes # Add ZPFX/bin to PATH typeset -U path @@ -31,6 +31,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 From c7a12615cea83be59faaf5d26c4ffb4e448408af Mon Sep 17 00:00:00 2001 From: Philipp Schmitt Date: Mon, 22 Nov 2021 22:58:48 +0100 Subject: [PATCH 3/3] Setup completions for zinit --- docker/zshrc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker/zshrc b/docker/zshrc index 0d8da5523..64e2417ca 100644 --- a/docker/zshrc +++ b/docker/zshrc @@ -6,6 +6,8 @@ fi # load zinit source /src/zinit.zsh +autoload -Uz _zinit +(( ${+_comps} )) && _comps[zinit]=_zinit # load zinit setup utility functions source /src/docker/utils.zsh