Skip to content

Commit 873b579

Browse files
Merge pull request #2 from pharmbio/feature/scilife_serve_bundle
Scilifelab serve version in single container..
2 parents ec96000 + cbec14d commit 873b579

File tree

10 files changed

+540
-17
lines changed

10 files changed

+540
-17
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,34 @@ To use this project, follow these steps:
4646
docker-compose up --build
4747
```
4848

49+
### Scilifelab Deployment
50+
51+
1. Build container
52+
```sh
53+
docker build -t ptp .
54+
```
55+
2. Push container to registry
56+
57+
58+
3. Deploy
59+
60+
4. Configuration
61+
- Set environment variables
62+
Use `DOWNLOAD=true` to download models prior to startup.
63+
- preferebly mount `/app/inference/models` directory to outside storage to avoid ram bloat.
64+
65+
- Use `MAX_MODELS` to limit the number of active models (for debug purposes) .otherwise it iterates all models present (currently 800+).
66+
67+
- If desired use `MODEL_DIR` to change path where model are found (default /app/inference/models/models)
68+
4969

5070
## References
5171
Model repository on Hugging Face: [pharmbio/ptp](https://huggingface.co/pharmbio/ptp)
5272

5373
## License
5474
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
5575

76+
5677
## Authors
5778
- **Jonathan Alvarsson** - *Research, scipipe version and models* - [jonathanalvarsson](https://github.com/jonalv)
5879
- **Morgan Ekmefjord** - *Web service, deployment and service packaging* - [morganekmefjord](https://github.com/morganekmefjord)

ptp/.dockerignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
*/conformal_models/*
22
*/vennABERS_models/*
33
inference/models/*
4-
*.jar
4+
*.jar
5+
tmp/*

ptp/Dockerfile

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
FROM python:3.11 AS djangobase
22

3-
# Set working directory
3+
ENV USER=ptp
44

55
RUN mkdir /app
6+
67
WORKDIR /app
78

89
# Install system dependencies
9-
RUN apt-get update && apt-get install -y gcc python3-dev libpq-dev
10+
RUN apt-get update && apt-get install -y gcc git-lfs python3-dev redis-server supervisor \
11+
&& apt-get clean
1012

1113
# Install Java (OpenJDK)
1214
RUN apt-get update && apt-get install -y openjdk-17-jre-headless \
@@ -20,6 +22,8 @@ ENV PATH=$JAVA_HOME/bin:$PATH
2022
COPY requirements.txt /app/
2123
RUN pip install -r requirements.txt
2224

25+
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
26+
2327
# Copy the application code
2428
FROM djangobase AS djangoapp
2529

@@ -32,5 +36,21 @@ WORKDIR /app
3236
# Expose the port the Django app runs on
3337
EXPOSE 8000
3438

35-
# Default command
36-
CMD ["gunicorn", "p2p.wsgi:application", "--bind", "0.0.0.0:8000"]
39+
RUN useradd -u 1000 $USER
40+
41+
RUN chown -R $USER:$USER /etc/supervisor/conf.d/supervisord.conf
42+
RUN chown -R $USER:$USER /app/
43+
RUN chown -R $USER:$USER /var/log/supervisor/
44+
RUN chmod +x /app/start-single.sh
45+
RUN chmod +x /app/start-django.sh
46+
RUN chmod +x /app/download.sh
47+
48+
# Make sure the container is running as non-root
49+
USER $USER
50+
51+
ENV CELERY_BROKER_URL="redis://localhost:6379/0"
52+
ENV REDIS_URL="redis://localhost:6379/0"
53+
ENV DOWNLOAD=false
54+
55+
# Start supervisord
56+
CMD ["sh", "-c", "/app/start-single.sh"]

ptp/download.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
if [ "$DOWNLOAD" = "true" ]; then
3+
git clone https://huggingface.co/pharmbio/ptp /app/inference/models && \
4+
cd /app/inference/models && \
5+
git lfs pull
6+
else
7+
echo "noop"
8+
fi
9+
exit 0

ptp/inference/tasks.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
import pandas as pd
88
from datetime import timezone
99

10+
model_dir = os.environ.get("MODEL_DIR", "/app/inference/models/models/")
11+
max_models = os.environ.get("MAX_MODELS", False)
12+
1013
@shared_task
1114
def run_inference(job_id):
1215

@@ -37,7 +40,7 @@ def run_inference(job_id):
3740
chembl_version = 'chembl_34'
3841
else:
3942
chembl_version = 'chembl_34'
40-
base = '/app/inference/models/'
43+
base = model_dir
4144
try:
4245
model_files = [os.path.join(base,chembl_version,path, f) for f in os.listdir(os.path.join(base, chembl_version,path)) if f.endswith('.jar')]
4346
except Exception as e:
@@ -54,6 +57,8 @@ def run_inference(job_id):
5457
if DEBUG:
5558
print("RUNNING IN DEBUG MODE ONLY CALCULATING 3 MODELS", flush=True)
5659
model_files = model_files#[:5]
60+
if max_models:
61+
model_files = model_files[:int(max_models)]
5762

5863
try:
5964
for model in model_files:

0 commit comments

Comments
 (0)