diff --git a/base/ubi9/.stow-local-ignore b/base/ubi9/.stow-local-ignore index e4a7df98..7012d319 100644 --- a/base/ubi9/.stow-local-ignore +++ b/base/ubi9/.stow-local-ignore @@ -10,3 +10,6 @@ \.krew \.sdkman \.local/bin/podman + +# Ignore files under .config directory +\.config diff --git a/base/ubi9/entrypoint.sh b/base/ubi9/entrypoint.sh index 0754ce5a..0e2920f3 100644 --- a/base/ubi9/entrypoint.sh +++ b/base/ubi9/entrypoint.sh @@ -15,6 +15,13 @@ if [ ! -d "${HOME}/.config/containers" ]; then fi fi +# Create Sym Link for Composer Keys in /home/tooling/.config +if [ -d /home/tooling/.config/composer ] && [ ! -d "${HOME}/.config/composer" ]; then + mkdir -p ${HOME}/.config/composer + ln -s /home/tooling/.config/composer/keys.dev.pub ${HOME}/.config/composer/keys.dev.pub + ln -s /home/tooling/.config/composer/keys.tags.pub ${HOME}/.config/composer/keys.tags.pub +fi + # Setup $PS1 for a consistent and reasonable prompt if [ -w "${HOME}" ] && [ ! -f "${HOME}"/.bashrc ]; then echo "PS1='[\u@\h \W]\$ '" > "${HOME}"/.bashrc @@ -30,4 +37,52 @@ fi source kubedock_setup + +# Stow +## Required for https://github.com/eclipse/che/issues/22412 + +# /home/user/ will be mounted to by a PVC if persistUserHome is enabled +mountpoint -q /home/user/; HOME_USER_MOUNTED=$? + +# This file will be created after stowing, to guard from executing stow everytime the container is started +STOW_COMPLETE=/home/user/.stow_completed + +if [ $HOME_USER_MOUNTED -eq 0 ] && [ ! -f $STOW_COMPLETE ]; then + # There may be regular, non-symlink files in /home/user that match the + # pathing of files in /home/tooling. Stow will error out when it tries to + # stow on top of that. Instead, we can append to the current + # /home/tooling/.stow-local-ignore file to ignore pre-existing, + # non-symlinked files in /home/user that match those in /home/tooling before + # we run stow. + # + # Create two text files containing a sorted path-based list of files in + # /home/tooling and /home/user. Cut off "/home/user" and "/home/tooling" and + # only get the sub-paths so we can do a proper comparison + # + # In the case of /home/user, we want regular file types and not symbolic + # links. + find /home/user -type f -xtype f -print | sort | sed 's|/home/user||g' > /tmp/user.txt + find /home/tooling -print | sort | sed 's|/home/tooling||g' > /tmp/tooling.txt + # We compare the two files, trying to find files that exist in /home/user + # and /home/tooling. Being that the files that get flagged here are not + # already synlinks, we will want to ignore them. + IGNORE_FILES="$(comm -12 /tmp/user.txt /tmp/tooling.txt)" + # We no longer require the file lists, so remove them + rm /tmp/user.txt /tmp/tooling.txt + # For each file we need to ignore, append them to + # /home/tooling/.stow-local-ignore. + for f in $IGNORE_FILES; do echo "${f}" >> /home/tooling/.stow-local-ignore;done + # We are now ready to run stow + # + # Create symbolic links from /home/tooling/ -> /home/user/ + stow . -t /home/user/ -d /home/tooling/ --no-folding -v 2 > /tmp/stow.log 2>&1 + # Vim does not permit .viminfo to be a symbolic link for security reasons, so manually copy it + cp /home/tooling/.viminfo /home/user/.viminfo + # We have to restore bash-related files back onto /home/user/ (since they will have been overwritten by the PVC) + # but we don't want them to be symbolic links (so that they persist on the PVC) + cp /home/tooling/.bashrc /home/user/.bashrc + cp /home/tooling/.bash_profile /home/user/.bash_profile + touch $STOW_COMPLETE +fi + exec "$@" diff --git a/universal/ubi9/Dockerfile b/universal/ubi9/Dockerfile index 5ddad6f6..9922c539 100644 --- a/universal/ubi9/Dockerfile +++ b/universal/ubi9/Dockerfile @@ -423,8 +423,6 @@ RUN chgrp -R 0 /home && chmod -R g=u /etc/passwd /etc/group /home /etc/pki # cleanup dnf cache RUN dnf -y clean all --enablerepo='*' -COPY --chown=0:0 entrypoint.sh / - USER 10001 ENV HOME=/home/user diff --git a/universal/ubi9/entrypoint.sh b/universal/ubi9/entrypoint.sh deleted file mode 100755 index 1a22938e..00000000 --- a/universal/ubi9/entrypoint.sh +++ /dev/null @@ -1,52 +0,0 @@ -#!/bin/bash - -source kubedock_setup - -# Stow -## Required for https://github.com/eclipse/che/issues/22412 - -# /home/user/ will be mounted to by a PVC if persistUserHome is enabled -mountpoint -q /home/user/; HOME_USER_MOUNTED=$? - -# This file will be created after stowing, to guard from executing stow everytime the container is started -STOW_COMPLETE=/home/user/.stow_completed - -if [ $HOME_USER_MOUNTED -eq 0 ] && [ ! -f $STOW_COMPLETE ]; then - # There may be regular, non-symlink files in /home/user that match the - # pathing of files in /home/tooling. Stow will error out when it tries to - # stow on top of that. Instead, we can append to the current - # /home/tooling/.stow-local-ignore file to ignore pre-existing, - # non-symlinked files in /home/user that match those in /home/tooling before - # we run stow. - # - # Create two text files containing a sorted path-based list of files in - # /home/tooling and /home/user. Cut off "/home/user" and "/home/tooling" and - # only get the sub-paths so we can do a proper comparison - # - # In the case of /home/user, we want regular file types and not symbolic - # links. - find /home/user -type f -xtype f -print | sort | sed 's|/home/user||g' > /tmp/user.txt - find /home/tooling -print | sort | sed 's|/home/tooling||g' > /tmp/tooling.txt - # We compare the two files, trying to find files that exist in /home/user - # and /home/tooling. Being that the files that get flagged here are not - # already synlinks, we will want to ignore them. - IGNORE_FILES="$(comm -12 /tmp/user.txt /tmp/tooling.txt)" - # We no longer require the file lists, so remove them - rm /tmp/user.txt /tmp/tooling.txt - # For each file we need to ignore, append them to - # /home/tooling/.stow-local-ignore. - for f in $IGNORE_FILES; do echo "${f}" >> /home/tooling/.stow-local-ignore;done - # We are now ready to run stow - # - # Create symbolic links from /home/tooling/ -> /home/user/ - stow . -t /home/user/ -d /home/tooling/ --no-folding -v 2 > /tmp/stow.log 2>&1 - # Vim does not permit .viminfo to be a symbolic link for security reasons, so manually copy it - cp /home/tooling/.viminfo /home/user/.viminfo - # We have to restore bash-related files back onto /home/user/ (since they will have been overwritten by the PVC) - # but we don't want them to be symbolic links (so that they persist on the PVC) - cp /home/tooling/.bashrc /home/user/.bashrc - cp /home/tooling/.bash_profile /home/user/.bash_profile - touch $STOW_COMPLETE -fi - -exec "$@"