How to import python modules in che7 workspace - eclipse-che

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.

Related

Laravel Sail MSSQL database creation on startup

I am currently working on Laravel Sail in combination with SQL server. What i want to do is create databases on sail startup but i can't seem to figure out how to edit my Dockerfile in a way that i can login to the sql server and create the databases. This is my current Dockerfile:
FROM ubuntu:20.04
LABEL maintainer="Taylor Otwell"
ARG WWWGROUP
WORKDIR /var/www/html
ENV DEBIAN_FRONTEND noninteractive
ENV TZ=UTC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt-get update \
&& apt-get install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2 \
&& mkdir -p ~/.gnupg \
&& chmod 600 ~/.gnupg \
&& echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf \
&& apt-key adv --homedir ~/.gnupg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys E5267A6C \
&& apt-key adv --homedir ~/.gnupg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C300EE8C \
&& echo "deb http://ppa.launchpad.net/ondrej/php/ubuntu focal main" > /etc/apt/sources.list.d/ppa_ondrej_php.list \
&& apt-get update \
&& apt-get install -y php8.0-cli php8.0-dev \
php8.0-pgsql php8.0-sqlite3 php8.0-gd \
php8.0-curl php8.0-memcached \
php8.0-imap php8.0-mbstring \
php8.0-xml php8.0-zip php8.0-bcmath php8.0-soap \
php8.0-intl php8.0-readline \
php8.0-msgpack php8.0-igbinary php8.0-ldap \
php8.0-redis \
php-pear \
&& php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer \
&& curl -sL https://deb.nodesource.com/setup_15.x | bash - \
&& apt-get install -y nodejs \
&& curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list \
&& curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
&& curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list > /etc/apt/sources.list.d/mssql-release.list \
&& apt-get update \
&& apt-get install -y yarn \
&& ACCEPT_EULA=Y apt-get install -y msodbcsql17 \
&& ACCEPT_EULA=Y apt-get install -y mssql-tools \
&& ln -sfn /opt/mssql-tools/bin/sqlcmd /usr/bin/sqlcmd \
&& apt-get install -y unixodbc-dev \
gcc \
musl-dev \
make \
&& apt-get -y autoremove \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN setcap "cap_net_bind_service=+ep" /usr/bin/php8.0
RUN groupadd --force -g $WWWGROUP sail
RUN useradd -ms /bin/bash --no-user-group -g $WWWGROUP -u 1337 sail
RUN pecl install sqlsrv
RUN pecl install pdo_sqlsrv
RUN printf "; priority=20\nextension=sqlsrv.so\n" > /etc/php/8.0/mods-available/sqlsrv.ini
RUN printf "; priority=30\nextension=pdo_sqlsrv.so\n" > /etc/php/8.0/mods-available/pdo_sqlsrv.ini
RUN phpenmod sqlsrv pdo_sqlsrv
COPY start-container /usr/local/bin/start-container
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY php.ini /etc/php/8.0/cli/conf.d/99-sail.ini
RUN chmod +x /usr/local/bin/start-container
SHELL ["/bin/bash", "-c"]
RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
EXPOSE 8000
ENTRYPOINT ["start-container"]
I seen some posts on creating an entrypoint.sh and starting the sql server simultaneously but i can't seem to figure out on how to make that work with my Dockerfile, can someone help me out?
Thanks!

Docker timeout error mssql17 connection on M1 arm64 architecture

Could you please help me resolve this issue:
I must to say that everything is working fine on Windows amd64 architecture
But when I tried to start docker-compose on arm64 M1 it went wrong and makes the error
So I have these 2 Dockerfiles
FROM --platform=linux/amd64 python:3.9-buster as builder
WORKDIR ...
COPY ...
RUN apt-get update && apt-get install -y git g++ libgirepository1.0-dev unixodbc unixodbc-dev pkg-config libcairo2-dev gcc python3-dev
RUN pip install virtualenv &&\
python -m venv antenv
RUN . antenv/bin/activate &&\
python -m ensurepip --upgrade &&\
pip install --upgrade pip &&\
pip install wheel gobject PyGObject &&\
pip install -r requirements.txt
FROM --platform=linux/amd64 python:3.9-slim
WORKDIR ...
COPY --from=builder ...
RUN apt-get update && apt-get install curl gnupg -y
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - &&\
curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list > /etc/apt/sources.list.d/mssql-release.list &&\
apt-get update &&\
ACCEPT_EULA=Y apt-get install msodbcsql17 mssql-tools -y &&\
apt-get install -y unixodbc python3-gi gir1.2-secret-1 alembic &&\
. antenv/bin/activate && pip install gunicorn &&\
mkdir -p /opt/antenv/nltk_data
EXPOSE 5000
CMD . antenv/bin/activate && alembic -x data=true upgrade head && gunicorn wsgi:app -w 1 --worker-class eventlet --threads 2 --forwarded-allow-ips=* -b 0.0.0.0:5000
and DataBase:
FROM --platform=linux/amd64 mcr.microsoft.com/mssql/server:2017-latest
WORKDIR /opt/mssql/
# Bundle config source
COPY ./*.sh /opt/mssql/bin/
RUN chmod +x /opt/mssql/bin/*.sh
ENTRYPOINT ["./bin/entrypoint.sh"]
CMD ["tail -f /dev/null"]
As you can see I mentioned everywhere that it is linux/amd64 platform
DataBase is upping good and I don`t get eerors
But when I up Backend, It as if does not see database and I get timeout error
backend | sqlalchemy.exc.OperationalError: (pyodbc.OperationalError) ('HYT00', '[HYT00] [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (0) (SQLDriverConnect)')
backend | (Background on this error at: https://sqlalche.me/e/14/e3q8)

How to verify ODBC version is the one on the odbc.ini file?

I have a requirement to configure shell to install specified version of ODBC.
The app that I'm configuring is an Angular app that uses janusgraph for storing data it is hosted on docker locally.
I updated the odbc.ini file, added the designed version. ref:https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver15
I also updated the install-odbc.sh file and added the version details.
ACCEPT_EULA=Y apt-get -y install msodbcsql17=-17.8.so.1.1
# optional: for bcp and sqlcmd
ACCEPT_EULA=Y apt-get -y install mssql-tools
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
# optional: for unixODBC development headers
apt-get install -y unixodbc-dev
# apt-show-versions msodbcsql17
msodbcsql17:amd64/bionic 17.8.1.1-1 uptodate
Then I deleted the app and installed it again from scratch, everything was successful and my app is backup and running on my local setup on docker.
The only challenge I have is how do I verify that indeed the ODBC version is the one on the odbc.ini file?
ODBC.ini
Driver=/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.8.so.1.1
Description = MSSQL Server
Trace = Yes
Server = 10.0.0.0
Database = IT_D
Port = 1433
TDS_Version = 7.4
QuotedId = YES
AnsiNPW = YES
Encrypt = YES
TrustServerCertificate = YES
#VarMaxAsLong=YES
[Default]
Driver = /opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.8.so.1.1
Docker file:
FROM ubuntu:18.04
# Create app directory
WORKDIR /root/importer
RUN apt-get -y update
# RUN apt-get -y install wget
# RUN wget https://rds-combined-ca-bundle.pem
# Wget not properly resolved by Jenkins, using local file as fallback
COPY ./rds-combined-ca-bundle.pem ./
COPY ./install-odbc.sh ./
RUN apt-get -y install gnupg2
RUN apt-get -y install dos2unix
RUN dos2unix ./install-odbc.sh
# Make sure the microsoft ODBC repository can be added as signed source
RUN apt-get -y update
RUN apt-get install -y curl apt-utils
RUN apt-get install -y apt-transport-https
# RUN apt-key adv --keyserver keyserver.ubuntu.com --keyserver-options http-proxy=${HTTP_PROXY} --recv-keys xxxxxx1229xx
RUN bash ./install-odbc.sh
# Node.js v14
RUN apt-get install -y git-core curl build-essential openssl libssl-dev python
RUN apt-get update -qq && apt-get clean
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash -
RUN apt-get update -qq && apt-get clean
RUN apt-get -y install nodejs
RUN node -v
RUN npm -v
# Oracle installation
ENV ORACLE_INSTANTCLIENT_MAJOR 19.6
ENV ORACLE_INSTANTCLIENT_VERSION 19.6.0.0.0
ENV ORACLE /usr/local/oracle
ENV ORACLE_HOME $ORACLE/lib/oracle/$ORACLE_INSTANTCLIENT_MAJOR/client64
ENV LD_LIBRARY_PATH $LD_LIBRARY_PATH:$ORACLE_HOME/lib
ENV C_INCLUDE_PATH $C_INCLUDE_PATH:$ORACLE/include/oracle/$ORACLE_INSTANTCLIENT_MAJOR/client64
RUN apt-get update && apt-get install -y libaio1 \
curl rpm2cpio cpio \
&& mkdir $ORACLE && TMP_DIR="$(mktemp -d)" && cd "$TMP_DIR" \
&& curl -L https://download.oracle.com/otn_software/linux/instantclient/19600/oracle-instantclient${ORACLE_INSTANTCLIENT_MAJOR}-basic-${ORACLE_INSTANTCLIENT_VERSION}-1.x86_64.rpm -o basic.rpm \
&& rpm2cpio basic.rpm | cpio -i -d -v && cp -r usr/* $ORACLE && rm -rf ./* \
&& ln -s libclntsh.so.${ORACLE_INSTANTCLIENT_MAJOR} $ORACLE/lib/oracle/$ORACLE_INSTANTCLIENT_MAJOR/client64/lib/libclntsh.so.$ORACLE_INSTANTCLIENT_MAJOR \
&& ln -s libocci.so.${ORACLE_INSTANTCLIENT_MAJOR} $ORACLE/lib/oracle/$ORACLE_INSTANTCLIENT_MAJOR/client64/lib/libocci.so.$ORACLE_INSTANTCLIENT_MAJOR \
&& echo "$ORACLE_HOME/lib" > /etc/ld.so.conf.d/oracle.conf && chmod o+r /etc/ld.so.conf.d/oracle.conf && ldconfig \
&& rm -rf /var/lib/apt/lists/* && apt-get purge -y --auto-remove curl rpm2cpio cpio
COPY ./dist/. ./
COPY ./package*.json ./
COPY ./tsconfig.json ./
# RUN npm install node-pre-gyp
RUN npm install
RUN node -v
COPY ./odbc.ini /etc/
RUN dos2unix /etc/odbc.ini
RUN cp /opt/microsoft/msodbcsql17/lib64/* /opt/microsoft/msodbcsql17/lib64/libmsodbcsql
RUN ls /opt/microsoft/msodbcsql17/lib64
COPY ./sqlnet.ora $ORACLE_HOME/network/admin/sqlnet.ora
RUN dos2unix $ORACLE_HOME/network/admin/sqlnet.ora
# CMD bash -c "npm run start:watch"
CMD bash -c "node --max-old-space-size=8192 ./app.js"
I tried to check docker logs but I couldn't file anything that indicates that the ODBC has been updated.
Can you please assist me with the steps to check the ODBC version used by my app.
Thanks in advance
Sivuyile

How to uninstall graphics.h from ubuntu?

I have installed graphics.h using the following steps:
First install build-essential by typing
sudo apt-get install build-essential
Install some additional packages by typing
sudo apt-get install libsdl-image1.2 libsdl-image1.2-dev guile-2.0 \
guile-2.0-dev libsdl1.2debian libart-2.0-dev libaudiofile-dev \
libesd0-dev libdirectfb-dev libdirectfb-extra libfreetype6-dev \
libxext-dev x11proto-xext-dev libfreetype6 libaa1 libaa1-dev \
libslang2-dev libasound2 libasound2-dev
Now extract the downloaded libgraph-1.0.2.tar.gz file.
Go to the folder where the files were extracted and run the following commands:
./configure
make
sudo make install
sudo cp /usr/local/lib/libgraph.* /usr/lib
But now how do I uninstall it again?

'Unable to open X display' error is produced by a CEF application running in windowless (off screen rendering) mode

[01] The application was built and executed in a docker.
The Dockerfile is as follows:
>>>>
FROM ubuntu:xenial
RUN apt-get update -y
RUN apt-get install -y wget
RUN apt-get install -y apt-utils
RUN apt-get install -y python3
RUN apt-get install -y tree
RUN apt-get install build-essential software-properties-common -y
RUN apt-get -y install libgtk2.0-dev
RUN apt-get -y install libgtkglext1-dev
RUN apt-get -y install python3-pip
RUN pip3 install --upgrade pip
RUN apt-get -y install cmake
RUN pip3 install --upgrade cmake
RUN apt-get -y install libnss3-dev
RUN apt-get -y install libxtst6
RUN apt-get -y install libxss1
RUN apt-get -y install libasound2
RUN apt-get -y install libatk-bridge2.0-0
<<<<
the CEF binary being used is
cef_binary_76.1.5+gd8a577c+chromium-76.0.3809.87_linux64/
[02] the application worked fine when starting the docker
with xhost+ and -e DISPLAY=.... as follows:
[A] starting docker with bash
xhost +
docker run \
-it \
--rm \
-e DISPLAY=$DISPLAY
--privileged \
-v /tmp/.X11-unix:/tmp/.X11-unix \
...
--network host \
--name $CONTAINER_NAME \
$REQD_IMAGE \
bash
[B] running the application in bash as
onpaint_streamer \
--no-sandbox \
--disable-gpu \
--disable-gpu-compositing \
--enable-begin-frame-scheduling \
--disable-extensions \
--disable-pdf-extension \
--url=file:///test/027/test.html
[03] the application DID NOT WORK when xhost+ and -e DISPLAY=....
were removed in [02][A]. The following message was dumped
+ ./onpaint_streamer --no-sandbox --disable-gpu --disable-gpu-compositing --enable-begin-frame-scheduling --disable-extensions --disable-pdf-extension --opg-fifo-path=/adhyuh/test/027/onpaint_data_fifo --opg-verbose --url=file:///test/027/test.html
d> CefInitialize : status=about_to
[0812/140301.641476:ERROR:browser_main_loop.cc(1504)] Unable to open X display.
d> CefInitialize : status=done
d> MessageLoop : status=started
[0812/140301.641921:FATAL:context.cc(584)] Check failed: CEF_CURRENTLY_ON(content::BrowserThread::UI).
./run_onpaint_data_writer_in_dk.sh: line 32: 20 Trace/breakpoint trap (core dumped) ./$STREAMER_APP --no-sandbox --disable-gpu --disable-gpu-compositing --enable-begin-frame-scheduling --disable-extensions --disable-pdf-extension --url=file:///test/027/test.html
[04] Some of the other 'flags' embedded in the code are
void SimpleApp::OnContextInitialized() {
//....
CefBrowserSettings browser_settings;
browser_settings.windowless_frame_rate = 30;
CefWindowInfo window_info;
window_info.SetAsWindowless(0);
//....
}
[05] Why should a windowless CEF application require xhost and DISPLAY to be present ? What am i missing or doing wrong ?
CEF depends on X11 library even in windowless mode ... was the answer that i got when a similar post was raised in CEF Forums. Please see https://magpcss.org/ceforum/viewtopic.php?f=6&t=16993&sid=5e46cc6bfb909badf63e0aafcfe9413f&p=42879#p42879

Resources