Skip to content

Commit 346c934

Browse files
committed
temp switcheroo 2
1 parent 5104123 commit 346c934

File tree

2 files changed

+187
-23
lines changed

2 files changed

+187
-23
lines changed

Dockerfile

Lines changed: 75 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
# This Dockerfile creates a container with pyOpenMS
1+
# This Dockerfile builds OpenMS, the TOPP tools, pyOpenMS and thidparty tools.
22
# It also adds a basic streamlit server that serves a pyOpenMS-based app.
33
# hints:
4-
# build image with: docker build -f Dockerfile_simple --no-cache -t streamlitapp:latest --build-arg GITHUB_TOKEN=<your-github-token> . 2>&1 | tee build.log
4+
# build image and give it a name (here: streamlitapp) with: docker build --no-cache -t streamlitapp:latest --build-arg GITHUB_TOKEN=<your-github-token> . 2>&1 | tee build.log
55
# check if image was build: docker image ls
6-
# run container: docker run -p 8501:8501 streamlitapp:latest
6+
# run container: docker run -p 8501:8501 streamlitappsimple:latest
77
# debug container after build (comment out ENTRYPOINT) and run container with interactive /bin/bash shell
88
# prune unused images/etc. to free disc space (e.g. might be needed on gitpod). Use with care.: docker system prune --all --force
99

10-
FROM ubuntu:22.04 AS stage1
10+
FROM ubuntu:22.04 AS setup-build-system
1111
ARG OPENMS_REPO=https://github.com/OpenMS/OpenMS.git
12-
ARG OPENMS_BRANCH=develop
12+
ARG OPENMS_BRANCH=release/3.2.0
1313
ARG PORT=8501
1414
# GitHub token to download latest OpenMS executable for Windows from Github action artifact.
1515
ARG GITHUB_TOKEN
@@ -19,14 +19,19 @@ ARG GITHUB_USER=OpenMS
1919
# Streamlit app Gihub repository name (to download artifact from).
2020
ARG GITHUB_REPO=streamlit-template
2121

22-
23-
# Step 1: set up a sane build system
2422
USER root
2523

24+
# Install required Ubuntu packages.
2625
RUN apt-get -y update
27-
# note: streamlit in docker needs libgtk2.0-dev (see https://yugdamor.medium.com/importerror-libgthread-2-0-so-0-cannot-open-shared-object-file-no-such-file-or-directory-895b94a7827b)
28-
RUN apt-get install -y --no-install-recommends --no-install-suggests wget ca-certificates libgtk2.0-dev curl jq cron
26+
RUN apt-get install -y --no-install-recommends --no-install-suggests g++ autoconf automake patch libtool make git gpg wget ca-certificates curl jq libgtk2.0-dev openjdk-8-jdk cron
2927
RUN update-ca-certificates
28+
RUN apt-get install -y --no-install-recommends --no-install-suggests libsvm-dev libeigen3-dev coinor-libcbc-dev libglpk-dev libzip-dev zlib1g-dev libxerces-c-dev libbz2-dev libomp-dev libhdf5-dev
29+
RUN apt-get install -y --no-install-recommends --no-install-suggests libboost-date-time1.74-dev \
30+
libboost-iostreams1.74-dev \
31+
libboost-regex1.74-dev \
32+
libboost-math1.74-dev \
33+
libboost-random1.74-dev
34+
RUN apt-get install -y --no-install-recommends --no-install-suggests qtbase5-dev libqt5svg5-dev libqt5opengl5-dev
3035

3136
# Install Github CLI
3237
RUN (type -p wget >/dev/null || (apt-get update && apt-get install wget -y)) \
@@ -52,16 +57,66 @@ RUN echo "mamba activate streamlit-env" >> ~/.bashrc
5257
SHELL ["/bin/bash", "--rcfile", "~/.bashrc"]
5358
SHELL ["mamba", "run", "-n", "streamlit-env", "/bin/bash", "-c"]
5459

55-
#################################### install streamlit
56-
# install packages
57-
COPY requirements.txt requirements.txt
58-
RUN mamba install pip
59-
RUN python -m pip install --upgrade pip
60-
RUN python -m pip install -r requirements.txt
60+
# Install up-to-date cmake via mamba and packages for pyOpenMS build.
61+
RUN mamba install cmake
62+
RUN pip install --upgrade pip && python -m pip install -U setuptools nose Cython autowrap pandas numpy pytest
6163

64+
# Clone OpenMS branch and the associcated contrib+thirdparties+pyOpenMS-doc submodules.
65+
RUN git clone --recursive --depth=1 -b ${OPENMS_BRANCH} --single-branch ${OPENMS_REPO} && cd /OpenMS
66+
67+
# Pull Linux compatible third-party dependencies and store them in directory thirdparty.
68+
WORKDIR /OpenMS
69+
RUN mkdir /thirdparty && \
70+
git submodule update --init THIRDPARTY && \
71+
cp -r THIRDPARTY/All/* /thirdparty && \
72+
cp -r THIRDPARTY/Linux/64bit/* /thirdparty && \
73+
chmod -R +x /thirdparty
74+
ENV PATH="/thirdparty/LuciPHOr2:/thirdparty/MSGFPlus:/thirdparty/Sirius:/thirdparty/ThermoRawFileParser:/thirdparty/Comet:/thirdparty/Fido:/thirdparty/MaRaCluster:/thirdparty/MyriMatch:/thirdparty/OMSSA:/thirdparty/Percolator:/thirdparty/SpectraST:/thirdparty/XTandem:/thirdparty/crux:${PATH}"
75+
76+
# Build OpenMS and pyOpenMS.
77+
FROM setup-build-system AS compile-openms
78+
WORKDIR /
79+
80+
# Set up build directory.
81+
RUN mkdir /openms-build
82+
WORKDIR /openms-build
83+
84+
# Configure.
85+
RUN /bin/bash -c "cmake -DCMAKE_BUILD_TYPE='Release' -DCMAKE_PREFIX_PATH='/OpenMS/contrib-build/;/usr/;/usr/local' -DHAS_XSERVER=OFF -DBOOST_USE_STATIC=OFF -DPYOPENMS=ON ../OpenMS -DPY_MEMLEAK_DISABLE=On"
86+
87+
# Build TOPP tools and clean up.
88+
RUN make -j4 TOPP
89+
RUN rm -rf src doc CMakeFiles
90+
91+
# Build pyOpenMS wheels and install via pip.
92+
RUN make -j4 pyopenms
93+
WORKDIR /openms-build/pyOpenMS
94+
RUN pip install dist/*.whl
95+
96+
97+
WORKDIR /
98+
RUN mkdir openms
99+
100+
# Copy TOPP tools bin directory, add to PATH.
101+
RUN cp -r openms-build/bin /openms/bin
102+
ENV PATH="/openms/bin/:${PATH}"
103+
104+
# Copy TOPP tools bin directory, add to PATH.
105+
RUN cp -r openms-build/lib /openms/lib
106+
ENV LD_LIBRARY_PATH="/openms/lib/:${LD_LIBRARY_PATH}"
107+
108+
# Copy share folder, add to PATH, remove source directory.
109+
RUN cp -r OpenMS/share/OpenMS /openms/share
110+
RUN rm -rf OpenMS
111+
ENV OPENMS_DATA_PATH="/openms/share/"
112+
113+
# Remove build directory.
114+
RUN rm -rf openms-build
115+
116+
# Prepare and run streamlit app.
117+
FROM compile-openms AS run-app
118+
# Create workdir and copy over all streamlit related files/folders.
62119

63-
# create workdir and copy over all streamlit related files/folders
64-
WORKDIR /app
65120
# note: specifying folder with slash as suffix and repeating the folder name seems important to preserve directory structure
66121
WORKDIR /app
67122
COPY assets/ /app/assets
@@ -77,15 +132,14 @@ COPY default-parameters.json /app/default-parameters.json
77132

78133
# For streamlit configuration
79134
COPY .streamlit/config.toml /app/.streamlit/config.toml
80-
81135
COPY clean-up-workspaces.py /app/clean-up-workspaces.py
82136

83137
# add cron job to the crontab
84138
RUN echo "0 3 * * * /root/miniforge3/envs/streamlit-env/bin/python /app/clean-up-workspaces.py >> /app/clean-up-workspaces.log 2>&1" | crontab -
85139

86140
# create entrypoint script to start cron service and launch streamlit app
87-
RUN echo "#!/bin/bash" > /app/entrypoint.sh
88-
RUN echo "source /root/miniforge3/bin/activate streamlit-env" >> /app/entrypoint.sh && \
141+
RUN echo "#!/bin/bash" > /app/entrypoint.sh && \
142+
echo "source /root/miniforge3/bin/activate streamlit-env" >> /app/entrypoint.sh && \
89143
echo "service cron start" >> /app/entrypoint.sh && \
90144
echo "streamlit run app.py" >> /app/entrypoint.sh
91145
# make the script executable
@@ -105,8 +159,6 @@ RUN if [ -n "$GH_TOKEN" ]; then \
105159
echo "GH_TOKEN is not set, skipping the release asset download."; \
106160
fi
107161

108-
# make sure that mamba environment is used
109-
SHELL ["mamba", "run", "-n", "streamlit-env", "/bin/bash", "-c"]
110-
162+
# Run app as container entrypoint.
111163
EXPOSE $PORT
112164
ENTRYPOINT ["/app/entrypoint.sh"]

Dockerfile_simple

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# This Dockerfile creates a container with pyOpenMS
2+
# It also adds a basic streamlit server that serves a pyOpenMS-based app.
3+
# hints:
4+
# build image with: docker build -f Dockerfile_simple --no-cache -t streamlitapp:latest --build-arg GITHUB_TOKEN=<your-github-token> . 2>&1 | tee build.log
5+
# check if image was build: docker image ls
6+
# run container: docker run -p 8501:8501 streamlitapp:latest
7+
# debug container after build (comment out ENTRYPOINT) and run container with interactive /bin/bash shell
8+
# prune unused images/etc. to free disc space (e.g. might be needed on gitpod). Use with care.: docker system prune --all --force
9+
10+
FROM ubuntu:22.04 AS stage1
11+
ARG OPENMS_REPO=https://github.com/OpenMS/OpenMS.git
12+
ARG OPENMS_BRANCH=develop
13+
ARG PORT=8501
14+
# GitHub token to download latest OpenMS executable for Windows from Github action artifact.
15+
ARG GITHUB_TOKEN
16+
ENV GH_TOKEN=${GITHUB_TOKEN}
17+
# Streamlit app Gihub user name (to download artifact from).
18+
ARG GITHUB_USER=OpenMS
19+
# Streamlit app Gihub repository name (to download artifact from).
20+
ARG GITHUB_REPO=streamlit-template
21+
22+
23+
# Step 1: set up a sane build system
24+
USER root
25+
26+
RUN apt-get -y update
27+
# note: streamlit in docker needs libgtk2.0-dev (see https://yugdamor.medium.com/importerror-libgthread-2-0-so-0-cannot-open-shared-object-file-no-such-file-or-directory-895b94a7827b)
28+
RUN apt-get install -y --no-install-recommends --no-install-suggests wget ca-certificates libgtk2.0-dev curl jq cron
29+
RUN update-ca-certificates
30+
31+
# Install Github CLI
32+
RUN (type -p wget >/dev/null || (apt-get update && apt-get install wget -y)) \
33+
&& mkdir -p -m 755 /etc/apt/keyrings \
34+
&& wget -qO- https://cli.github.com/packages/githubcli-archive-keyring.gpg | tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null \
35+
&& chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg \
36+
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
37+
&& apt-get update \
38+
&& apt-get install gh -y
39+
40+
# Download and install miniforge.
41+
ENV PATH="/root/miniforge3/bin:${PATH}"
42+
RUN wget -q \
43+
https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh \
44+
&& bash Miniforge3-Linux-x86_64.sh -b \
45+
&& rm -f Miniforge3-Linux-x86_64.sh
46+
RUN mamba --version
47+
48+
# Setup mamba environment.
49+
COPY environment.yml ./environment.yml
50+
RUN mamba env create -f environment.yml
51+
RUN echo "mamba activate streamlit-env" >> ~/.bashrc
52+
SHELL ["/bin/bash", "--rcfile", "~/.bashrc"]
53+
SHELL ["mamba", "run", "-n", "streamlit-env", "/bin/bash", "-c"]
54+
55+
#################################### install streamlit
56+
# install packages
57+
COPY requirements.txt requirements.txt
58+
RUN mamba install pip
59+
RUN python -m pip install --upgrade pip
60+
RUN python -m pip install -r requirements.txt
61+
62+
63+
# create workdir and copy over all streamlit related files/folders
64+
WORKDIR /app
65+
# note: specifying folder with slash as suffix and repeating the folder name seems important to preserve directory structure
66+
WORKDIR /app
67+
COPY assets/ /app/assets
68+
COPY content/ /app/content
69+
COPY docs/ /app/docs
70+
COPY example-data/ /app/example-data
71+
COPY gdpr_consent/ /app/gdpr_consent
72+
COPY hooks/ /app/hooks
73+
COPY src/ /app/src
74+
COPY app.py /app/app.py
75+
COPY settings.json /app/settings.json
76+
COPY default-parameters.json /app/default-parameters.json
77+
78+
# For streamlit configuration
79+
COPY .streamlit/config.toml /app/.streamlit/config.toml
80+
81+
COPY clean-up-workspaces.py /app/clean-up-workspaces.py
82+
83+
# add cron job to the crontab
84+
RUN echo "0 3 * * * /root/miniforge3/envs/streamlit-env/bin/python /app/clean-up-workspaces.py >> /app/clean-up-workspaces.log 2>&1" | crontab -
85+
86+
# create entrypoint script to start cron service and launch streamlit app
87+
RUN echo "#!/bin/bash" > /app/entrypoint.sh
88+
RUN echo "source /root/miniforge3/bin/activate streamlit-env" >> /app/entrypoint.sh && \
89+
echo "service cron start" >> /app/entrypoint.sh && \
90+
echo "streamlit run app.py" >> /app/entrypoint.sh
91+
# make the script executable
92+
RUN chmod +x /app/entrypoint.sh
93+
94+
# Patch Analytics
95+
RUN mamba run -n streamlit-env python hooks/hook-analytics.py
96+
97+
# Set Online Deployment
98+
RUN jq '.online_deployment = true' settings.json > tmp.json && mv tmp.json settings.json
99+
100+
# Download latest OpenMS App executable for Windows from Github actions workflow.
101+
RUN if [ -n "$GH_TOKEN" ]; then \
102+
echo "GH_TOKEN is set, proceeding to download the release asset..."; \
103+
gh run download -R ${GITHUB_USER}/${GITHUB_REPO} $(gh run list -R ${GITHUB_USER}/${GITHUB_REPO} -b main -e push -s completed -w "Build executable for Windows" --json databaseId -q '.[0].databaseId') -n OpenMS-App --dir /app; \
104+
else \
105+
echo "GH_TOKEN is not set, skipping the release asset download."; \
106+
fi
107+
108+
# make sure that mamba environment is used
109+
SHELL ["mamba", "run", "-n", "streamlit-env", "/bin/bash", "-c"]
110+
111+
EXPOSE $PORT
112+
ENTRYPOINT ["/app/entrypoint.sh"]

0 commit comments

Comments
 (0)