Skip to content

Commit

Permalink
Merge pull request #57 from nimh-dsst/docker-speedup
Browse files Browse the repository at this point in the history
Docker speedup
  • Loading branch information
leej3 authored Sep 5, 2024
2 parents d7fe692 + f14e270 commit 4a2cf1d
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 80 deletions.
21 changes: 20 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,21 @@
*/.terraform
**/.terraform
tempdata/*
.venv
.DS_Store
.env
.gitattributes
.github
.gitignore
.pre-commit-config.yaml
.public_dns
.pytest_cache
.ruff_cache
LICENSE
README.md
build
draft_of_specification_2024-05-06.md
*.egg-info
osm_output
scripts
tests
uv.lock
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Ignore the virtual environment directory
.git
_version.py
dashboard_data
node_modules
Expand All @@ -23,3 +24,4 @@ osm_output
.terraform.lock.hcl
.public_dns
tempdata
.aider*
22 changes: 14 additions & 8 deletions Dockerfile.base
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
FROM tiangolo/uvicorn-gunicorn:python3.11

SHELL ["/bin/bash", "--login", "-c"]
COPY --from=ghcr.io/astral-sh/uv:0.4.0 /uv /bin/uv
WORKDIR /app
RUN mkdir -p /opt/data
RUN mkdir -p /opt/osm

RUN pip install poetry fastapi[standard] uvicorn
RUN mkdir -p /opt/osm/osm
ENV UV_SYSTEM_PYTHON=1
# ENV UV_PYTHON=/usr/local/bin/python
# Install requirements first in a separate layer to avoid re-installing them on
# every code changes
COPY pyproject.toml /opt/osm
RUN bash -c 'FORCE_OSM_VERSION=0.0.0 pip install -r <(poetry export --without-hashes --format=requirements.txt)'
# Install the package
COPY osm /opt/osm/osm
RUN --mount=source=.git,target=/opt/osm/.git,type=bind pip install --no-dependencies -e /opt/osm
RUN --mount=type=cache,target=/root/.cache/uv \
SETUPTOOLS_SCM_PRETEND_VERSION_FOR_OSM=9.9.9; \
cd /opt/osm; \
uv pip install --system -r <(uv pip compile --all-extras pyproject.toml )
COPY ./osm /opt/osm/osm
RUN --mount=source=.git,target=/opt/osm/.git,type=bind \
--mount=type=cache,target=/root/.cache/uv \
cd /opt/osm; \
uv pip install --system -r <(uv pip compile --all-extras pyproject.toml ) -e .
91 changes: 47 additions & 44 deletions compose.development.override.yaml
Original file line number Diff line number Diff line change
@@ -1,75 +1,78 @@
name: local-osm
services:
base_image:
image: nimhdsst/osm_base
build:
context: .
dockerfile: Dockerfile.base

rtransparent:
container_name: rtransparent
build:
context: .
dockerfile: ./external_components/rtransparent/Dockerfile
volumes:
- ./external_components/rtransparent:/app

llm_extraction:
image: nimhdsst/osm_base
environment:
- OPENAI_API_KEY=${OPENAI_API_KEY:-NOKEY}
build:
context: .
dockerfile: ./external_components/llm_extraction/Dockerfile
volumes:
- ./external_components/llm_extraction:/app
depends_on:
- base_image


############ Development images ############

web_api:
image: nimhdsst/osm_base
container_name: web_api
db:
# use old version of mongo to avoid Apple Instruction set error
image: mongo:4.4.6
container_name: db
ports:
- 27017:27017
environment:
- MONGODB_URI=mongodb://db:27017/osm
- MONGO_INITDB_DATABASE=osm

base:
command: ["echo", "base image"]
image: nimhdsst/osm_base:latest
build:
context: .
dockerfile: ./web/api/Dockerfile
ports:
- 80:80
volumes:
- ./web/api:/app/app
- ./osm:/opt/osm/osm
working_dir: /app/app
command: ["fastapi","dev","--host","0.0.0.0","--port","80"]
depends_on:
- db
- base_image
dockerfile: Dockerfile.base

dashboard:
image: nimhdsst/osm_base
container_name: dashboard
environment:
- MONGODB_URI=mongodb://db:27017/osm
image: nimhdsst/osm_dashboard:latest
build:
context: .
dockerfile: ./web/dashboard/Dockerfile
ports:
- "8501:8501"
volumes:
- ./web/dashboard:/app
- ./osm:/opt/osm/osm
working_dir: /app
command: ["python", "app.py"]
- ./dashboard_data:/opt/data
depends_on:
- db
- base_image
- base
develop:
watch:
- action: sync+restart
path: ./osm
target: /opt/osm/osm
ignore:
- __pycache__

db:
container_name: db
# use old version of mongo to avoid Apple Instruction set error
image: mongo:4.4.6
ports:
- 27017:27017
web_api:
container_name: web_api
working_dir: /app/app
command: ["fastapi","dev","--host","0.0.0.0","--port","80"]
environment:
- MONGO_INITDB_DATABASE=osm
- MONGODB_URI=mongodb://db:27017/osm
image: nimhdsst/osm_web_api:latest
build:
context: .
dockerfile: ./web/api/Dockerfile
ports:
- 80:80
volumes:
- ./web/api:/app/app
depends_on:
- db
- base
develop:
watch:
- action: sync+restart
path: ./osm
target: /opt/osm/osm
ignore:
- __pycache__
5 changes: 0 additions & 5 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,3 @@ services:
image: nimhdsst/rtransparent:staging
ports:
- "8071:8071"
llm_extraction:
container_name: llm_extraction
image: nimhdsst/llm_extraction:staging
ports:
- "8072:8072"
7 changes: 5 additions & 2 deletions external_components/llm_extraction/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
FROM nimhdsst/osm_base
RUN pip install llama-index llama-index-llms-openai llama-index-program-openai

# # Copy the project files and install the package
COPY external_components/llm_extraction/app.py /app

# Install the package
COPY osm /opt/osm/osm
RUN --mount=type=cache,target=/root/.cache/uv \
export SETUPTOOLS_SCM_PRETEND_VERSION_FOR_OSM=9.9.9; \
cd /opt/osm ; uv pip install -e .
CMD ["fastapi", "dev", "--host", "0.0.0.0", "--port", "8072"]
4 changes: 2 additions & 2 deletions external_components/rtransparent/environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ dependencies:
- r-lubridate
- r-magrittr
- r-pbapply
- r-pdftools
#- r-pdftools
- r-plyr
- r-purrr
- r-qpdf
#- r-qpdf
- r-readr
# - r-rentrez
- r-rlang
Expand Down
7 changes: 4 additions & 3 deletions osm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

def get_version():
try:
if os.environ.get("FORCE_OSM_VERSION"):
return os.environ["FORCE_OSM_VERSION"]
from . import _version

return _version.version
Expand All @@ -18,7 +16,10 @@ def get_version():
def generate_version_file():
import pkg_resources

version = pkg_resources.get_distribution("osm").version
if os.get("SETUPTOOLS_SCM_PRETEND_VERSION_FOR_OSM"):
version = os.environ["SETUPTOOLS_SCM_PRETEND_VERSION_FOR_OSM"]
else:
version = pkg_resources.get_distribution("osm").version
version_file_content = f"version = '{version}'\n"

version_file_path = os.path.join(os.path.dirname(__file__), "_version.py")
Expand Down
27 changes: 23 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ keywords = [
"scientific transparency",
"reproducibility"
]

dynamic = ["version"]
dependencies = [
"dill",
Expand All @@ -21,6 +22,28 @@ dependencies = [
"requests",
]

[project.optional-dependencies]
dev = [
"pdbpp",
"ipython",
"ruff",
"pytest",
]
server = [
"fastapi[standard]",
"uvicorn",
"gunicorn",
]
llm = [
"llama-index",
"llama-index-llms-openai",
"llama-index-program-openai",
"llama-index-llms-openrouter"
]
plot = [
"colorcet",
"panel",
]
[project.urls]
homepage = "https://website"
source = "https://github.com/nimh-dsst/osm"
Expand All @@ -39,10 +62,6 @@ where = ["."]
[project.scripts]
osm = "osm.cli:main"

[tool.black]
line-length = 88
target-version = ["py38", "py39", "py310"]

[tool.ruff]
line-length = 88
indent-width = 4
2 changes: 0 additions & 2 deletions web/api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
FROM nimhdsst/osm_base

COPY ./web/api/main.py /app/app/main.py

CMD ["fastapi", "run", "--host", "0.0.0.0", "--port", "80", "--root-path", "/api"]
11 changes: 2 additions & 9 deletions web/dashboard/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@

FROM nimhdsst/osm_base
RUN pip install colorcet panel
# # Copy the project files and install the package
COPY web/dashboard/ /app
ENV LOCAL_DATA_PATH=/opt/data/matches.parquet
CMD ["python", "app.py"]


# # Create the environment
# RUN pip install panel pymongo odmantic pandas pydantic[email] pyarrow

# ENV LOCAL_DATA_PATH=/opt/data/matches.parquet
# COPY ./tempdata/matches.parquet /opt/data/matches.parquet

0 comments on commit 4a2cf1d

Please sign in to comment.