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

feat(python-jupyter): Setting up venv in a dedicated volume #958

Merged
merged 1 commit into from
May 25, 2021
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
25 changes: 18 additions & 7 deletions sidecars/python/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ FROM python:3.8.6-slim

ENV HOME=/home/theia

RUN mkdir /projects ${HOME} && \
# Change permissions to let any arbitrary user
for f in "${HOME}" "/etc/passwd" "/projects"; do \
echo "Changing permissions on ${f}" && chgrp -R 0 ${f} && \
chmod -R g+rwX ${f}; \
done

RUN apt-get update && \
apt-get install exuberant-ctags && \
apt-get install wget -y && \
Expand All @@ -29,6 +22,24 @@ RUN apt-get update && \
apt-get purge -y --auto-remove gcc build-essential && \
apt-get clean && apt-get -y autoremove && rm -rf /var/lib/apt/lists/*


SHELL ["/bin/bash", "-c"]
RUN command -v source || (echo "ERROR: Could not find 'source' command. SHELL may not supported. If you are using podman, try again with the '--format docker' flag." && exit 126)

RUN cd "${HOME}"; \
python -m venv .venv ; \
source .venv/bin/activate; \
pip install -U ipykernel jupyter; \
python -m ipykernel install --name=.venv --user; \
mv "${HOME}"/.venv "${HOME}"/.venv-tmp

RUN mkdir /projects && \
# Change permissions to let any arbitrary user
for f in "${HOME}" "/etc/passwd" "/projects"; do \
echo "Changing permissions on ${f}" && chgrp -R 0 ${f} && \
chmod -R g+rwX ${f}; \
done

ADD etc/entrypoint.sh /entrypoint.sh
ENTRYPOINT [ "/entrypoint.sh" ]
CMD ${PLUGIN_REMOTE_ENDPOINT_EXECUTABLE}
13 changes: 11 additions & 2 deletions sidecars/python/etc/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
#
# Copyright (c) 2018-2020 Red Hat, Inc.
# This program and the accompanying materials are made
Expand All @@ -20,12 +20,21 @@ GROUP_ID=$(id -g)
export GROUP_ID

if ! whoami >/dev/null 2>&1; then
echo "${USER_NAME:-user}:x:${USER_ID}:0:${USER_NAME:-user} user:${HOME}:/bin/sh" >> /etc/passwd
echo "${USER_NAME:-user}:x:${USER_ID}:0:${USER_NAME:-user} user:${HOME}:/bin/bash" >> /etc/passwd
fi

# Grant access to projects volume in case of non root user with sudo rights
if [ "${USER_ID}" -ne 0 ] && command -v sudo >/dev/null 2>&1 && sudo -n true > /dev/null 2>&1; then
sudo chown "${USER_ID}:${GROUP_ID}" /projects
fi

# Setup .venv in the 'venv' volume that should be mounted in HOME/.venv
mkdir -p "${HOME}"/.venv
if [ ! -f "${HOME}"/.venv/bin/activate ]; then
echo "${HOME}"/.venv is empty, moving files from "${HOME}"/.venv-tmp/
mv "${HOME}"/.venv-tmp/* "${HOME}"/.venv
fi

# shellcheck source=/dev/null
source "${HOME}"/.venv/bin/activate
exec "$@"