Skip to content

Commit

Permalink
Merge pull request #48 from princeton-ddss/44-create-dockerfile-to-co…
Browse files Browse the repository at this point in the history
…ntainerize

44 create dockerfile
  • Loading branch information
cswaney authored Sep 19, 2024
2 parents ad8e970 + a1f509b commit 0f346d7
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 3 deletions.
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2024 Colin Swaney and The Trustees of Princeton University

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
68 changes: 68 additions & 0 deletions deploy/dev/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
ARG PYTHON_BUILDER_IMAGE=3.11-slim-bookworm

FROM python:${PYTHON_BUILDER_IMAGE} AS python-base
ENV PIP_DEFAULT_TIMEOUT=100 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
PIP_NO_CACHE_DIR=1 \
PIP_ROOT_USER_ACTION=ignore \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PYTHONFAULTHANDLER=1 \
PYTHONHASHSEED=random \
LANG=C.UTF-8 \
LC_ALL=C.UTF-8
RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y --no-install-recommends git tini \
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /root/.cache \
&& rm -rf /var/apt/lists/* \
&& rm -rf /var/cache/apt/* \
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false\
&& mkdir -p /workspace/app \
&& pip install --quiet -U pip wheel setuptools virtualenv

FROM python-base AS build-base
ENV PATH="/workspace/app/.venv/bin:/usr/local/bin:$PATH"
RUN apt-get install -y --no-install-recommends build-essential curl \
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /root/.cache \
&& rm -rf /var/apt/lists/* \
&& rm -rf /var/cache/apt/* \
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false

WORKDIR /workspace/app
COPY pyproject.toml README.md .pre-commit-config.yaml LICENSE ./
# COPY scripts ./scripts/
# COPY public ./public/
# COPY resources ./resources/
RUN python -m venv /workspace/app/.venv

FROM build-base AS prod-image
ARG ENV_SECRETS="runtime-secrets"
ENV PATH="/workspace/app/.venv/bin:$PATH" \
VIRTUAL_ENV="/workspace/app/.venv" \
ENV_SECRETS="${ENV_SECRETS}" \
PIP_DEFAULT_TIMEOUT=100 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
PIP_NO_CACHE_DIR=1 \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PYTHONFAULTHANDLER=1 \
PYTHONHASHSEED=random
WORKDIR /workspace/app
COPY docs/ docs/
COPY tests/ tests/
COPY src/ src/
RUN pip install -e .
STOPSIGNAL SIGINT
EXPOSE 8000
ENV BLACKFISH_HOST="0.0.0.0"
ENV BLACKFISH_PORT="8000"
ENV BLACKFISH_HOME_DIR="/data"
ENTRYPOINT ["tini","--" ]
CMD [ "blackfish", "start", "--reload"]

VOLUME /workspace/app
66 changes: 66 additions & 0 deletions deploy/prod/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
ARG PYTHON_BUILDER_IMAGE=3.11-slim-bookworm

FROM python:${PYTHON_BUILDER_IMAGE} AS python-base
ENV PIP_DEFAULT_TIMEOUT=100 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
PIP_NO_CACHE_DIR=1 \
PIP_ROOT_USER_ACTION=ignore \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PYTHONFAULTHANDLER=1 \
PYTHONHASHSEED=random \
LANG=C.UTF-8 \
LC_ALL=C.UTF-8
RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y --no-install-recommends git tini \
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /root/.cache \
&& rm -rf /var/apt/lists/* \
&& rm -rf /var/cache/apt/* \
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false\
&& mkdir -p /workspace/app \
&& pip install --quiet -U pip wheel setuptools virtualenv

FROM python-base AS build-base
ENV PATH="/workspace/app/.venv/bin:/usr/local/bin:$PATH"
RUN apt-get install -y --no-install-recommends build-essential curl \
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /root/.cache \
&& rm -rf /var/apt/lists/* \
&& rm -rf /var/cache/apt/* \
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false

WORKDIR /workspace/app
COPY pyproject.toml README.md .pre-commit-config.yaml LICENSE ./
# COPY scripts ./scripts/
# COPY public ./public/
# COPY resources ./resources/
RUN python -m venv /workspace/app/.venv

FROM build-base AS prod-image
ARG ENV_SECRETS="runtime-secrets"
ENV PATH="/workspace/app/.venv/bin:$PATH" \
VIRTUAL_ENV="/workspace/app/.venv" \
ENV_SECRETS="${ENV_SECRETS}" \
PIP_DEFAULT_TIMEOUT=100 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
PIP_NO_CACHE_DIR=1 \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PYTHONFAULTHANDLER=1 \
PYTHONHASHSEED=random
WORKDIR /workspace/app
COPY docs/ docs/
COPY tests/ tests/
COPY src/ src/
RUN pip install -e .
STOPSIGNAL SIGINT
EXPOSE 8000
ENV BLACKFISH_HOST="0.0.0.0"
ENV BLACKFISH_PORT="8000"
ENV BLACKFISH_HOME_DIR="/data"
ENTRYPOINT ["tini","--" ]
CMD [ "blackfish", "start"]
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dependencies = [
"click",
"colorlog",
"fabric",
"huggingface_hub",
"huggingface_hub>=0.25",
"jinja2",
"litestar",
"log_symbols",
Expand Down
2 changes: 1 addition & 1 deletion src/app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class BlackfishConfig:

def __init__(self):
self.BLACKFISH_HOST = os.getenv("BLACKFISH_HOST", DEFAULT_HOST)
self.BLACKFISH_PORT = os.getenv("BLACKFISH_PORT", DEFAULT_PORT)
self.BLACKFISH_PORT = int(os.getenv("BLACKFISH_PORT", DEFAULT_PORT))
self.BLACKFISH_HOME_DIR = os.getenv("BLACKFISH_HOME_DIR", DEFAULT_HOME_DIR)
self.BLACKFISH_DEBUG = os.getenv("BLACKFISH_DEBUG", DEFAULT_DEBUG)
self.BLACKFISH_PROFILES = {}
Expand Down
2 changes: 1 addition & 1 deletion src/app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import socket
from typing import Optional
from huggingface_hub import ModelCard, list_repo_commits
from huggingface_hub.utils._errors import RepositoryNotFoundError
from huggingface_hub.errors import RepositoryNotFoundError
from fabric.connection import Connection
from app.config import BlackfishProfile, SlurmRemote, LocalProfile
from app.logger import logger
Expand Down

0 comments on commit 0f346d7

Please sign in to comment.