Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move tools & configs from /home/user/ to /home/tooling/ #115

Merged
merged 16 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions base/ubi8/.stow-local-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# .viminfo cannot be a symlink for security reasons
\.viminfo

# We store bash related files in /home/tooling/ so they aren't overriden if persistUserHome is enabled
# but we don't want them to be symbolic links (or to cause stow conflicts). They will be copied to /home/user/ manually.
\.bashrc
\.bash_profile
26 changes: 20 additions & 6 deletions base/ubi8/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ LABEL io.openshift.expose-services=""

USER 0

ENV HOME=/home/tooling
RUN mkdir -p /home/tooling/

RUN dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm && \
dnf update -y && \
dnf install -y bash curl diffutils git git-lfs iproute jq less lsof man nano procps p7zip p7zip-plugins \
perl-Digest-SHA net-tools openssh-clients rsync socat sudo time vim wget zip && \
perl-Digest-SHA net-tools openssh-clients rsync socat sudo time vim wget zip stow && \
dnf clean all

## gh-cli
Expand Down Expand Up @@ -89,19 +92,30 @@ RUN \
rm -rf "${TEMP_DIR}"

COPY --chown=0:0 entrypoint.sh /
COPY --chown=0:0 .stow-local-ignore /home/tooling/
RUN \
# add user and configure it
useradd -u 10001 -G wheel,root -d /home/user --shell /bin/bash -m user && \
# Setup $PS1 for a consistent and reasonable prompt
echo "export PS1='\W \`git branch --show-current 2>/dev/null | sed -r -e \"s@^(.+)@\(\1\) @\"\`$ '" >> /home/user/.bashrc && \
touch /etc/profile.d/udi_prompt.sh && \
chown 10001 /etc/profile.d/udi_prompt.sh && \
echo "export PS1='\W \`git branch --show-current 2>/dev/null | sed -r -e \"s@^(.+)@\(\1\) @\"\`$ '" >> /etc/profile.d/udi_prompt.sh && \
# Copy the global git configuration to user config as global /etc/gitconfig
# file may be overwritten by a mounted file at runtime
cp /etc/gitconfig /home/user/.gitconfig && \
chown 10001 /home/user/.gitconfig && \
# file may be overwritten by a mounted file at runtime
cp /etc/gitconfig ${HOME}/.gitconfig && \
chown 10001 ${HOME}/ ${HOME}/.viminfo ${HOME}/.gitconfig ${HOME}/.stow-local-ignore && \
# Set permissions on /etc/passwd and /home to allow arbitrary users to write
chgrp -R 0 /home && \
chmod -R g=u /etc/passwd /etc/group /home && \
chmod +x /entrypoint.sh
chmod +x /entrypoint.sh && \
# Create symbolic links from /home/tooling/ -> /home/user/
stow . -t /home/user/ -d /home/tooling/ && \
# .viminfo cannot be a symbolic link for security reasons, so copy it to /home/user/
cp /home/tooling/.viminfo /home/user/.viminfo && \
# Bash-related files are backed up to /home/tooling/ incase they are deleted when persistUserHome is enabled.
cp /home/user/.bashrc /home/tooling/.bashrc && \
cp /home/user/.bash_profile /home/tooling/.bash_profile && \
chown 10001 /home/tooling/.bashrc /home/tooling/.bash_profile

USER 10001
ENV HOME=/home/user
Expand Down
5 changes: 0 additions & 5 deletions base/ubi8/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ if [ ! -d "${HOME}" ]; then
mkdir -p "${HOME}"
fi

# Setup $PS1 for a consistent and reasonable prompt
if [ -w "${HOME}" ] && [ ! -f "${HOME}"/.bashrc ]; then
echo "PS1='[\u@\h \W]\$ '" > "${HOME}"/.bashrc
fi

# Add current (arbitrary) user to /etc/passwd and /etc/group
if ! whoami &> /dev/null; then
if [ -w /etc/passwd ]; then
Expand Down
117 changes: 72 additions & 45 deletions universal/ubi8/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,22 @@ LABEL description="Image with developers tools. Languages SDK and runtimes inclu
LABEL io.k8s.display-name="devfile-developer-universal"
LABEL io.openshift.expose-services=""

USER 0

# $PROFILE_EXT contains all additions made to the bash environment
ENV PROFILE_EXT=/etc/profile.d/udi_environment.sh
RUN touch ${PROFILE_EXT} & chown 10001 ${PROFILE_EXT}

USER 10001

# We install everything to /home/tooling/ as /home/user/ may get overriden, see github.com/eclipse/che/issues/22412
ENV HOME=/home/tooling

# Java
RUN curl -fsSL "https://get.sdkman.io" | bash \
&& bash -c ". /home/user/.sdkman/bin/sdkman-init.sh \
&& sed -i "s/sdkman_auto_answer=false/sdkman_auto_answer=true/g" /home/user/.sdkman/etc/config \
&& sed -i "s/sdkman_auto_env=false/sdkman_auto_env=true/g" /home/user/.sdkman/etc/config \
RUN curl -fsSL "https://get.sdkman.io/?rcupdate=false" | bash \
&& bash -c ". /home/tooling/.sdkman/bin/sdkman-init.sh \
&& sed -i "s/sdkman_auto_answer=false/sdkman_auto_answer=true/g" /home/tooling/.sdkman/etc/config \
&& sed -i "s/sdkman_auto_env=false/sdkman_auto_env=true/g" /home/tooling/.sdkman/etc/config \
&& sdk install java 8.0.332-tem \
&& sdk install java 11.0.15-tem \
&& sdk install java 17.0.3-tem \
Expand All @@ -34,45 +43,49 @@ RUN curl -fsSL "https://get.sdkman.io" | bash \
&& sdk install jbang \
&& sdk flush archives \
&& sdk flush temp" \
&& chgrp -R 0 /home/user && chmod -R g=u /home/user
&& chgrp -R 0 /home/tooling && chmod -R g=u /home/tooling

# sdk home java <version>
ENV JAVA_HOME_8=/home/user/.sdkman/candidates/java/8.0.332-tem
ENV JAVA_HOME_11=/home/user/.sdkman/candidates/java/11.0.15-tem
ENV JAVA_HOME_17=/home/user/.sdkman/candidates/java/17.0.3-tem
ENV JAVA_HOME_8=/home/tooling/.sdkman/candidates/java/8.0.332-tem
ENV JAVA_HOME_11=/home/tooling/.sdkman/candidates/java/11.0.15-tem
ENV JAVA_HOME_17=/home/tooling/.sdkman/candidates/java/17.0.3-tem

# Java-related environment variables are described and set by /home/user/.bashrc
# Java-related environment variables are described and set by ${PROFILE_EXT}, which will be loaded by ~/.bashrc
# To make Java working for dash and other shells, it needs to initialize them in the Dockerfile.
ENV SDKMAN_CANDIDATES_API="https://api.sdkman.io/2"
ENV SDKMAN_CANDIDATES_DIR="/home/user/.sdkman/candidates"
ENV SDKMAN_DIR="/home/user/.sdkman"
ENV SDKMAN_CANDIDATES_DIR="/home/tooling/.sdkman/candidates"
ENV SDKMAN_DIR="/home/tooling/.sdkman"
ENV SDKMAN_PLATFORM="linuxx64"
ENV SDKMAN_VERSION="5.13.0"

ENV GRADLE_HOME="/home/user/.sdkman/candidates/gradle/current"
ENV JAVA_HOME="/home/user/.sdkman/candidates/java/current"
ENV MAVEN_HOME="/home/user/.sdkman/candidates/maven/current"
ENV GRADLE_HOME="/home/tooling/.sdkman/candidates/gradle/current"
ENV JAVA_HOME="/home/tooling/.sdkman/candidates/java/current"
ENV MAVEN_HOME="/home/tooling/.sdkman/candidates/maven/current"

ENV GRAALVM_HOME=/home/user/.sdkman/candidates/java/22.1.0.0.r17-mandrel
ENV GRAALVM_HOME=/home/tooling/.sdkman/candidates/java/22.1.0.0.r17-mandrel

ENV PATH="/home/user/.krew/bin:$PATH"
ENV PATH="/home/user/.sdkman/candidates/maven/current/bin:$PATH"
ENV PATH="/home/user/.sdkman/candidates/java/current/bin:$PATH"
ENV PATH="/home/user/.sdkman/candidates/gradle/current/bin:$PATH"
ENV PATH="/home/user/.local/share/coursier/bin:$PATH"
ENV PATH="/home/tooling/.krew/bin:$PATH"
ENV PATH="/home/tooling/.sdkman/candidates/maven/current/bin:$PATH"
ENV PATH="/home/tooling/.sdkman/candidates/java/current/bin:$PATH"
ENV PATH="/home/tooling/.sdkman/candidates/gradle/current/bin:$PATH"
ENV PATH="/home/tooling/.local/share/coursier/bin:$PATH"

# NodeJS
ENV NVM_DIR="/home/user/.nvm"
RUN mkdir -p /home/tooling/.nvm/
ENV NVM_DIR="/home/tooling/.nvm"
ENV NODEJS_20_VERSION=20.7.0
# note that 18.18.0 is the latest but 18.16.1 is the supported version downstream and in ubi8
ENV NODEJS_18_VERSION=18.16.1
ENV NODEJS_DEFAULT_VERSION=${NODEJS_18_VERSION}
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash && source /home/user/.bashrc && \
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | PROFILE=/dev/null bash
RUN echo 'export NVM_DIR="$HOME/.nvm"' >> ${PROFILE_EXT} \
&& echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> ${PROFILE_EXT}
RUN source /home/user/.bashrc && \
nvm install v${NODEJS_20_VERSION} && \
nvm install v${NODEJS_18_VERSION} && \
nvm alias default v${NODEJS_DEFAULT_VERSION} && nvm use v${NODEJS_DEFAULT_VERSION} && \
npm install --global [email protected] &&\
chgrp -R 0 /home/user && chmod -R g=u /home/user
chgrp -R 0 /home/tooling && chmod -R g=u /home/tooling
ENV PATH=$NVM_DIR/versions/node/v${NODEJS_DEFAULT_VERSION}/bin:$PATH
ENV NODEJS_HOME_20=$NVM_DIR/versions/node/v${NODEJS_20_VERSION}
ENV NODEJS_HOME_18=$NVM_DIR/versions/node/v${NODEJS_18_VERSION}
Expand All @@ -83,9 +96,10 @@ ENV KUBECONFIG=/home/user/.kube/config
USER 0

# Define user directory for binaries
RUN mkdir -p /home/user/.local/bin && \
RUN mkdir -p /home/tooling/.local/bin && \
chgrp -R 0 /home && chmod -R g=u /home
ENV PATH="/home/user/.local/bin:$PATH"
ENV PATH="/home/tooling/.local/bin:$PATH"

# Required packages for AWT
RUN dnf install -y libXext libXrender libXtst libXi
Expand All @@ -109,11 +123,11 @@ RUN curl -fLo mill https://raw.githubusercontent.com/lefou/millw/main/millw && \
RUN dnf -y install llvm-toolset gcc gcc-c++ clang clang-libs clang-tools-extra gdb

# Go 1.18+ - installed to /usr/bin/go
# gopls 0.10+ - installed to /home/user/go/bin/gopls and /home/user/go/pkg/mod/
# gopls 0.10+ - installed to /home/tooling/go/bin/gopls and /home/tooling/go/pkg/mod/
RUN dnf install -y go-toolset && \
GO111MODULE=on go install -v golang.org/x/tools/gopls@latest && \
chgrp -R 0 /home/user && chmod -R g=u /home/user
ENV GOBIN="/home/user/go/bin/"
chgrp -R 0 /home/tooling && chmod -R g=u /home/tooling
ENV GOBIN="/home/tooling/go/bin/"
ENV PATH="$GOBIN:$PATH"

# Python
Expand Down Expand Up @@ -156,38 +170,33 @@ ENV DOTNET_RPM_VERSION=6.0
RUN dnf install -y dotnet-hostfxr-${DOTNET_RPM_VERSION} dotnet-runtime-${DOTNET_RPM_VERSION} dotnet-sdk-${DOTNET_RPM_VERSION}

# rust
ENV CARGO_HOME=/home/user/.cargo \
RUSTUP_HOME=/home/user/.rustup \
PATH=/home/user/.cargo/bin:${PATH}
ENV CARGO_HOME=/home/tooling/.cargo \
RUSTUP_HOME=/home/tooling/.rustup \
PATH=/home/tooling/.cargo/bin:${PATH}
RUN curl --proto '=https' --tlsv1.2 -sSfo rustup https://sh.rustup.rs && \
chmod +x rustup && \
mv rustup /usr/bin/ && \
rustup -y --no-modify-path --profile minimal -c rust-src -c rust-analysis -c rls && \
chgrp -R 0 /home/user && chmod -R g=u /home/user
chgrp -R 0 /home/tooling && chmod -R g=u /home/tooling

# camel-k
ENV KAMEL_VERSION 1.11.0
RUN curl -L https://github.com/apache/camel-k/releases/download/v${KAMEL_VERSION}/camel-k-client-${KAMEL_VERSION}-linux-64bit.tar.gz | tar -C /usr/local/bin -xz \
&& chmod +x /usr/local/bin/kamel

# git completion
RUN echo "source /usr/share/bash-completion/completions/git" >> /home/user/.bashrc

# Cloud

# oc client and completion
# oc client
ENV OC_VERSION=4.6
RUN curl -L https://mirror.openshift.com/pub/openshift-v4/clients/oc/${OC_VERSION}/linux/oc.tar.gz | tar -C /usr/local/bin -xz \
&& chmod +x /usr/local/bin/oc \
&& oc completion bash > /usr/share/bash-completion/completions/oc \
&& echo "source /usr/share/bash-completion/completions/oc" >> /home/user/.bashrc
&& chmod +x /usr/local/bin/oc

## podman buildah skopeo
RUN dnf -y module enable container-tools:rhel8 && \
dnf -y update && \
dnf -y reinstall shadow-utils && \
dnf -y install podman buildah skopeo fuse-overlayfs
RUN echo 'alias docker=podman' >> /home/user/.bashrc
RUN echo 'alias docker=podman' >> ${PROFILE_EXT}

# Set up environment variables to note that this is
# not starting with usernamespace and default to
Expand Down Expand Up @@ -235,13 +244,9 @@ EOF2

dnf install -y kubectl
curl -sSL -o ~/.kubectl_aliases https://raw.githubusercontent.com/ahmetb/kubectl-alias/master/.kubectl_aliases
echo '[ -f ~/.kubectl_aliases ] && source ~/.kubectl_aliases' >> /home/user/.bashrc
echo '[ -f ~/.kubectl_aliases ] && source ~/.kubectl_aliases' >> ${PROFILE_EXT}
EOF

# kubectl completion
RUN kubectl completion bash > /usr/share/bash-completion/completions/kubectl \
&& echo "source /usr/share/bash-completion/completions/kubectl" >> /home/user/.bashrc

## shellcheck
RUN <<EOF
dnf install -y xz
Expand Down Expand Up @@ -279,7 +284,7 @@ sha256sum -c "${KREW_TGZ}.sha256" 2>&1 | grep OK

tar -zxvf "${KREW_TGZ}"
./"krew-${KREW_ARCH}" install krew
echo 'export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"' >> /home/user/.bashrc
echo 'export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"' >> ${PROFILE_EXT}
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
# kubens and kubectx
kubectl krew install ns
Expand Down Expand Up @@ -414,6 +419,26 @@ cd -
rm -rf "${TEMP_DIR}"
EOF

# Bash completions
RUN dnf -y install bash-completion \
&& dnf clean all \
&& rm -rf /var/cache/yum

RUN <<EOF
oc completion bash > /usr/share/bash-completion/completions/oc
kubectl completion bash > /usr/share/bash-completion/completions/kubectl
cat ${NVM_DIR}/bash_completion > /usr/share/bash-completion/completions/nvm
EOF

## Add sdkman's init script launcher to the end of ${PROFILE_EXT} since we are not adding it on sdkman install
## NOTE: all modifications to ${PROFILE_EXT} must happen BEFORE this step in order for sdkman to function correctly
RUN echo 'export SDKMAN_DIR="/home/tooling/.sdkman"' >> ${PROFILE_EXT}
RUN echo '[[ -s "$SDKMAN_DIR/bin/sdkman-init.sh" ]] && source "$SDKMAN_DIR/bin/sdkman-init.sh"' >> ${PROFILE_EXT}


# Create symbolic links from /home/tooling/ -> /home/user/
RUN stow . -t /home/user/ -d /home/tooling/ --no-folding

AObuchow marked this conversation as resolved.
Show resolved Hide resolved
# Set permissions on /etc/passwd and /home to allow arbitrary users to write
RUN chgrp -R 0 /home && chmod -R g=u /etc/passwd /etc/group /home

Expand All @@ -423,3 +448,5 @@ RUN dnf -y clean all --enablerepo='*'
COPY --chown=0:0 entrypoint.sh /

USER 10001

ENV HOME=/home/user
64 changes: 46 additions & 18 deletions universal/ubi8/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,67 @@ if [ "${KUBEDOCK_ENABLED:-false}" = "true" ]; then
echo "Kubedock is enabled (env variable KUBEDOCK_ENABLED is set to true)."

SECONDS=0
until [ -f /home/user/.kube/config ]; do
if (( SECONDS > 10 )); then
echo "Giving up..."
exit 1
KUBEDOCK_TIMEOUT=${KUBEDOCK_TIMEOUT:-10}
until [ -f $KUBECONFIG ]; do
if (( SECONDS > KUBEDOCK_TIMEOUT )); then
break
fi
echo "Kubeconfig doesn't exist yet. Waiting..."
sleep 1
done
echo "Kubeconfig found."

KUBEDOCK_PARAMS=${KUBEDOCK_PARAMS:-"--reverse-proxy"}
if [ -f $KUBECONFIG ]; then
echo "Kubeconfig found."

echo "Starting kubedock with params \"${KUBEDOCK_PARAMS}\"..."

kubedock server "${KUBEDOCK_PARAMS}" > /tmp/kubedock.log 2>&1 &

echo "Done."
KUBEDOCK_PARAMS=${KUBEDOCK_PARAMS:-"--reverse-proxy --kubeconfig $KUBECONFIG"}

echo "Replacing podman with podman-wrapper..."
echo "Starting kubedock with params \"${KUBEDOCK_PARAMS}\"..."

kubedock server ${KUBEDOCK_PARAMS} > /tmp/kubedock.log 2>&1 &

echo "Done."

ln -f -s /usr/bin/podman.wrapper /home/user/.local/bin/podman
echo "Replacing podman with podman-wrapper..."

export TESTCONTAINERS_RYUK_DISABLED="true"
export TESTCONTAINERS_CHECKS_DISABLE="true"
ln -f -s /usr/bin/podman.wrapper /home/tooling/.local/bin/podman

echo "Done."
echo
export TESTCONTAINERS_RYUK_DISABLED="true"
export TESTCONTAINERS_CHECKS_DISABLE="true"

echo "Done."
echo
else
echo "Could not find Kubeconfig at $KUBECONFIG"
echo "Giving up..."
fi
else
echo
echo "Kubedock is disabled. It can be enabled with the env variable \"KUBEDOCK_ENABLED=true\""
echo "set in the workspace Devfile or in a Kubernetes ConfigMap in the developer namespace."
echo
ln -f -s /usr/bin/podman.orig /home/user/.local/bin/podman
ln -f -s /usr/bin/podman.orig /home/tooling/.local/bin/podman
fi


# 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
# 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 "$@"
Loading