In Che7 I have created a workspace that uses a custom docker image that I built. This docker image has Python3.7 installed and a 3rd party module named Pyomo installed via pip. The workspace starts up properly, and if I open a terminal into that image I can see that Pyomo is installed, but at runtime I can't import the module into my python code.
I have tried to determine the difference between the dockerimage that is included in the devfile and the runtime environment for Python. What I have noticed is that the user that the python is executed under is 'theia', so at runtime I can print out the contents of the /home/theia directory, but if I have a terminal open to the image I created there is no theia user.
I have tried to install the module from my python script but that fails because I don't have permissions. (I don't really want to do it this way because it feels hackish. I would rather figure out the proper configuration of the workspace)
Below is the docker file that I have to create the image with Pyomo installed.
FROM <my-ubuntu-image>
RUN sudo apt-get purge -y python.* && \
sudo apt autoremove -y && \
sudo apt-get update && \
sudo apt-get install -y --no-install-recommends \
autoconf \
automake \
bzip2 \
file \
g++ \
gcc \
imagemagick \
libbz2-dev \
libc6-dev \
libcurl4-openssl-dev libdb-dev libevent-dev libffi-dev libgdbm-dev libgeoip-dev libglib2.0-dev libjpeg-dev \
libkrb5-dev liblzma-dev libmagickcore-dev libmagickwand-dev libmysqlclient-dev libncurses-dev libpng-dev \
libpq-dev libreadline-dev libsqlite3-dev libssl-dev libtool libwebp-dev libxml2-dev libxslt-dev libyaml-dev make patch xz-utils zlib1g-dev
ENV LANG=C.UTF-8
ENV PYTHON_VERSION=3.7.4
ENV PYTHON_PIP_VERSION=19.2.3
RUN set -ex && \
sudo curl -fSL "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" -o python.tar.xz && \
sudo curl -fSL "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" -o python.tar.xz.asc && \
export GNUPGHOME="$(mktemp -d)" && \
sudo rm -r "$GNUPGHOME" python.tar.xz.asc && \
sudo mkdir -p /usr/src/python && \
sudo tar -xJC /usr/src/python --strip-components=1 -f python.tar.xz && \
sudo rm python.tar.xz && \
cd /usr/src/python && \
sudo ./configure --enable-shared --enable-unicode=ucs4 && \
sudo make -j$(nproc) && \
sudo make install && \
sudo ldconfig && \
sudo pip3 install --upgrade --ignore-installed pip==$PYTHON_PIP_VERSION && \
sudo pip3 install pyomo && \
sudo find /usr/local \( -type d -a -name test -o -name tests \) -o \( -type f -a -name '*.pyc' -o -name '*.pyo' \) -exec rm -rf '{}' + && \
sudo rm -rf /usr/src/python
RUN cd /usr/local/bin && \
sudo ln -s easy_install-3.7 easy_install && \
sudo ln -s idle3 idle && \
sudo ln -s pydoc3 pydoc && \
sudo ln -s python3 python && \
sudo ln -s python-config3 python-config
RUN sudo pip3 install --upgrade pip && \
sudo pip3 install --no-cache-dir virtualenv && \
sudo pip3 install --upgrade setuptools && \
sudo pip3 install 'python-language-server[all]'
EXPOSE 8080
Once this docker image is successfully built, I create a workspace and the devfile is below
metadata:
name: Pyomo
projects:
- name: python-hello-world
source:
location: 'https://github.com/che-samples/python-hello-world.git'
type: git
branch: master
components:
- id: ms-python/python/latest
memoryLimit: 512Mi
type: chePlugin
- mountSources: true
memoryLimit: 512Mi
type: dockerimage
alias: pyomo
image: '<my-Pyomo-image>'
apiVersion: 1.0.0
commands:
- name: run
actions:
- workdir: '${CHE_PROJECTS_ROOT}/python-hello-world'
type: exec
command: python hello-world.py
component: python
Once the workspace is successfully opened, the following won't work
import pyomo
My expectation was that, as a result of installing the Pyomo (or any other python module) in the docker image that it would be available in the Che Workspace to code with.