Skip to content

Commit

Permalink
feat: add docker to front and backend
Browse files Browse the repository at this point in the history
  • Loading branch information
ibiscp committed Mar 2, 2023
1 parent 1f63b31 commit 3cff280
Show file tree
Hide file tree
Showing 18 changed files with 375 additions and 3,596 deletions.
54 changes: 2 additions & 52 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,59 +1,9 @@
# `python-base` sets up all our shared environment variables
FROM python:3.10-slim

# python
ENV PYTHONUNBUFFERED=1 \
# prevents python creating .pyc files
PYTHONDONTWRITEBYTECODE=1 \
\
# pip
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100 \
\
# poetry
# https://python-poetry.org/docs/configuration/#using-environment-variables
POETRY_VERSION=1.3.2 \
# make poetry install to this location
POETRY_HOME="/opt/poetry" \
# make poetry create the virtual environment in the project's root
# it gets named `.venv`
POETRY_VIRTUALENVS_IN_PROJECT=true \
# do not ask any interactive question
POETRY_NO_INTERACTION=1 \
\
# paths
# this is where our requirements + virtual environment will live
PYSETUP_PATH="/opt/pysetup" \
VENV_PATH="/opt/pysetup/.venv"

# prepend poetry and venv to path
ENV PATH="$POETRY_HOME/bin:$VENV_PATH/bin:$PATH"

RUN apt-get update \
&& apt-get install --no-install-recommends -y \
# deps for installing poetry
curl \
# deps for building python deps
build-essential libpq-dev

# install poetry - respects $POETRY_VERSION & $POETRY_HOME
RUN curl -sSL https://install.python-poetry.org | python3 -

# copy project requirement files here to ensure they will be cached.
WORKDIR $PYSETUP_PATH
COPY poetry.lock pyproject.toml ./

# install runtime deps - uses $POETRY_VIRTUALENVS_IN_PROJECT internally
RUN poetry install --only-root
RUN poetry add "git+https://github.com/ibiscp/langchain.git@ibis"

WORKDIR /app

ENV PATH="/opt/pysetup/.venv/bin:$PATH"

COPY src/ .
COPY --from=frontend_build /app/build/ /

EXPOSE 80

CMD [ "uvicorn", "--host", "0.0.0.0", "--port", "80", "app:app" ]
# CMD [ "langchain" ]
6 changes: 4 additions & 2 deletions build_and_push
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#! /bin/bash

docker build -t logspace/frontend_build -f build.Dockerfile .
poetry remove langchain
docker build -t ibiscp/expert:v0.0.15 . && docker push ibiscp/expert:v0.0.15
poetry add --editable ../langchain
VERSION=$(toml get --toml-path pyproject.toml tool.poetry.version)
docker build --build-arg VERSION=$VERSION -t ibiscp/langflow:$VERSION . && docker push ibiscp/langflow:$VERSION
poetry add --editable ../../../langchain
Empty file removed docker-compose.yml
Empty file.
14 changes: 14 additions & 0 deletions langflow/backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM logspace/backend_build as backend_build

FROM python:3.10-slim
WORKDIR /app

RUN apt-get update && apt-get install git -y

COPY --from=backend_build /app/dist/*.whl /app/
RUN pip install langflow-0.0.17-py3-none-any.whl
RUN rm *.whl

EXPOSE 80

CMD [ "uvicorn", "--host", "0.0.0.0", "--port", "80", "langflow.backend.app:app" ]
9 changes: 1 addition & 8 deletions langflow/backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ def create_app():
app = FastAPI()

origins = [
"http://localhost",
"http://localhost:8080",
"http://localhost:3000",
"*",
]

app.add_middleware(
Expand All @@ -30,8 +28,3 @@ def create_app():


app = create_app()

if __name__ == "__main__":
import uvicorn

uvicorn.run(app, host="0.0.0.0", port=5003)
54 changes: 54 additions & 0 deletions langflow/backend/build.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# `python-base` sets up all our shared environment variables
FROM python:3.10-slim

# python
ENV PYTHONUNBUFFERED=1 \
# prevents python creating .pyc files
PYTHONDONTWRITEBYTECODE=1 \
\
# pip
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100 \
\
# poetry
# https://python-poetry.org/docs/configuration/#using-environment-variables
POETRY_VERSION=1.4.0 \
# make poetry install to this location
POETRY_HOME="/opt/poetry" \
# make poetry create the virtual environment in the project's root
# it gets named `.venv`
POETRY_VIRTUALENVS_IN_PROJECT=true \
# do not ask any interactive question
POETRY_NO_INTERACTION=1 \
\
# paths
# this is where our requirements + virtual environment will live
PYSETUP_PATH="/opt/pysetup" \
VENV_PATH="/opt/pysetup/.venv"

# prepend poetry and venv to path
ENV PATH="$POETRY_HOME/bin:$VENV_PATH/bin:$PATH"

RUN apt-get update \
&& apt-get install --no-install-recommends -y \
# deps for installing poetry
curl \
# deps for building python deps
build-essential libpq-dev

# install poetry - respects $POETRY_VERSION & $POETRY_HOME
RUN curl -sSL https://install.python-poetry.org | python3 -

# copy project requirement files here to ensure they will be cached.
WORKDIR /app
COPY poetry.lock pyproject.toml ./

# install runtime deps - uses $POETRY_VIRTUALENVS_IN_PROJECT internally
RUN poetry install --without dev
RUN poetry add "git+https://github.com/ibiscp/langchain.git#ibis"

COPY *.py langflow/backend/
RUN rm langflow/backend/dev.py

RUN poetry build
8 changes: 8 additions & 0 deletions langflow/backend/build_and_push
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#! /bin/bash

poetry remove langchain
docker build -t logspace/backend_build -f build.Dockerfile .
VERSION=$(toml get --toml-path pyproject.toml tool.poetry.version)
docker build --build-arg VERSION=$VERSION -t logspace/langflow_backend:$VERSION .
# docker push logspace/langflow_backend:$VERSION
# poetry add --editable ../../../langchain
10 changes: 10 additions & 0 deletions langflow/backend/dev.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import uvicorn
import sys
from pathlib import Path

path = Path(__file__)
sys.path.append(str(path.parent.parent.parent))

from app import app

uvicorn.run(app, host="0.0.0.0", port=5003)
Loading

0 comments on commit 3cff280

Please sign in to comment.