From 6b0383be50bd0bfbdfd3bd618a200997a0d9da54 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 16 Aug 2023 15:38:43 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=A6=20chore(deploy):=20add=20deploymen?= =?UTF-8?q?t=20files=20and=20configurations=20for=20Docker=20Compose=20set?= =?UTF-8?q?up?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/backend.env | 18 ++++++++ deploy/base.Dockerfile | 87 +++++++++++++++++++++++++++++++++++++++ deploy/celeryworker.env | 8 ++++ deploy/db.env | 3 ++ deploy/docker-compose.yml | 83 +++++++++++++++++++++++++++++++++++++ deploy/flower.env | 5 +++ deploy/frontend.env | 3 ++ deploy/pgadmin.env | 2 + deploy/startup-backend.sh | 6 +++ 9 files changed, 215 insertions(+) create mode 100644 deploy/backend.env create mode 100644 deploy/base.Dockerfile create mode 100644 deploy/celeryworker.env create mode 100644 deploy/db.env create mode 100644 deploy/docker-compose.yml create mode 100644 deploy/flower.env create mode 100644 deploy/frontend.env create mode 100644 deploy/pgadmin.env create mode 100755 deploy/startup-backend.sh diff --git a/deploy/backend.env b/deploy/backend.env new file mode 100644 index 000000000..d9cbdc1dc --- /dev/null +++ b/deploy/backend.env @@ -0,0 +1,18 @@ +# Database configuration +DB_USER=langflow +DB_PASSWORD=langflow +DB_HOST=db +DB_PORT=5432 +DB_NAME=langflow + +# Logging configuration +LOG_LEVEL=debug + +# Cache configuration +LANGFLOW_CACHE_TYPE=redis + +# Redis configuration +LANGFLOW_REDIS_HOST=queue +LANGFLOW_REDIS_PORT=6379 +LANGFLOW_REDIS_DB=0 +LANGFLOW_REDIS_EXPIRE=3600 \ No newline at end of file diff --git a/deploy/base.Dockerfile b/deploy/base.Dockerfile new file mode 100644 index 000000000..1be280163 --- /dev/null +++ b/deploy/base.Dockerfile @@ -0,0 +1,87 @@ + + +# syntax=docker/dockerfile:1 +# Keep this syntax directive! It's used to enable Docker BuildKit + +# Based on https://github.com/python-poetry/poetry/discussions/1879?sort=top#discussioncomment-216865 +# but I try to keep it updated (see history) + +################################ +# PYTHON-BASE +# Sets up all our shared environment variables +################################ +FROM python:3.10-slim as python-base + +# python +ENV PYTHONUNBUFFERED=1 \ + # prevents python creating .pyc files + PYTHONDONTWRITEBYTECODE=1 \ + \ + # pip + PIP_DISABLE_PIP_VERSION_CHECK=on \ + PIP_DEFAULT_TIMEOUT=100 \ + \ + # poetry + # https://python-poetry.org/docs/configuration/#using-environment-variables + POETRY_VERSION=1.5.1 \ + # 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" + + +################################ +# BUILDER-BASE +# Used to build deps + create our virtual environment +################################ +FROM python-base as builder-base +RUN apt-get update \ + && apt-get install --no-install-recommends -y \ + # deps for installing poetry + curl \ + # deps for building python deps + build-essential + +# install poetry - respects $POETRY_VERSION & $POETRY_HOME +# The --mount will mount the buildx cache directory to where +# Poetry and Pip store their cache so that they can re-use it +RUN --mount=type=cache,target=/root/.cache \ + 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 ./ +COPY ./src/backend ./src/backend +# Copy README.md to the build context +COPY ./README.md ./ +# install runtime deps - uses $POETRY_VIRTUALENVS_IN_PROJECT internally +RUN --mount=type=cache,target=/root/.cache \ + poetry install --without dev --extras deploy + + +################################ +# DEVELOPMENT +# Image used during development / testing +################################ +FROM python-base as development +WORKDIR $PYSETUP_PATH + +# copy in our built poetry + venv +COPY --from=builder-base $POETRY_HOME $POETRY_HOME +COPY --from=builder-base $PYSETUP_PATH $PYSETUP_PATH + +# quicker install as runtime deps are already installed +RUN --mount=type=cache,target=/root/.cache \ + poetry install --with=dev --extras deploy diff --git a/deploy/celeryworker.env b/deploy/celeryworker.env new file mode 100644 index 000000000..bbc6aa8c1 --- /dev/null +++ b/deploy/celeryworker.env @@ -0,0 +1,8 @@ +LANGFLOW_CACHE_TYPE=redis +LANGFLOW_REDIS_HOST=queue +LANGFLOW_REDIS_PORT=6379 +LANGFLOW_REDIS_DB=0 +LANGFLOW_REDIS_EXPIRE=3600 +BROKER_URL=redis://queue:6379/0 +RESULT_BACKEND=redis://queue:6379/0 +C_FORCE_ROOT="true # ! Only for development" diff --git a/deploy/db.env b/deploy/db.env new file mode 100644 index 000000000..64e9ce762 --- /dev/null +++ b/deploy/db.env @@ -0,0 +1,3 @@ +POSTGRES_USER=langflow +POSTGRES_PASSWORD=langflow +POSTGRES_DB=langflow diff --git a/deploy/docker-compose.yml b/deploy/docker-compose.yml new file mode 100644 index 000000000..293115182 --- /dev/null +++ b/deploy/docker-compose.yml @@ -0,0 +1,83 @@ +version: "3" + +services: + backend: + build: + context: ../ + dockerfile: base.Dockerfile + # user: your-non-root-user # Make sure your Dockerfile creates this user + depends_on: + - queue + - db + env_file: + - ./backend.env + ports: + - "7860:7860" + volumes: + - ./:/app + - ./startup-backend.sh:/startup-backend.sh # Ensure the paths match + command: /startup-backend.sh # Fixed the path + + db: + image: postgres:15.4 + env_file: + - ./db.env + ports: + - "5432:5432" + + pgadmin: + image: dpage/pgadmin4 + env_file: + - ./pgadmin.env + ports: + - "5050:80" + depends_on: + - db + volumes: + - ./pgadmin:/var/lib/pgadmin + + queue: + image: redis:6.2.5 # Use a specific version + ports: + - "6379:6379" + + celeryworker: + # user: your-non-root-user + depends_on: + - queue + env_file: + - ./celeryworker.env + build: + context: ../ + dockerfile: base.Dockerfile + command: celery -A langflow.worker.celery_app worker --loglevel=INFO + + flower: + # user: your-non-root-user + networks: + - default + depends_on: + - queue + build: + context: ../ + dockerfile: base.Dockerfile + env_file: + - ./flower.env + command: celery -A langflow.worker.celery_app --broker=redis://queue:6379/0 flower --port=5555 + ports: + - "5555:5555" + + frontend: + # user: your-non-root-user + build: + context: ../src/frontend + dockerfile: Dockerfile + args: + - BACKEND_URL=http://backend:7860 + depends_on: + - backend + env_file: + - ./frontend.env + ports: + - "80:80" + restart: on-failure diff --git a/deploy/flower.env b/deploy/flower.env new file mode 100644 index 000000000..df742505f --- /dev/null +++ b/deploy/flower.env @@ -0,0 +1,5 @@ +LANGFLOW_CACHE_TYPE=redis +LANGFLOW_REDIS_HOST=queue +LANGFLOW_REDIS_PORT=6379 +LANGFLOW_REDIS_DB=0 +LANGFLOW_REDIS_EXPIRE=3600 diff --git a/deploy/frontend.env b/deploy/frontend.env new file mode 100644 index 000000000..ca56a25a7 --- /dev/null +++ b/deploy/frontend.env @@ -0,0 +1,3 @@ + +VITE_PROXY_TARGET=http://backend:7860/api/ +BACKEND_URL=http://backend:7860 diff --git a/deploy/pgadmin.env b/deploy/pgadmin.env new file mode 100644 index 000000000..7ef01290b --- /dev/null +++ b/deploy/pgadmin.env @@ -0,0 +1,2 @@ +PGADMIN_DEFAULT_EMAIL=admin@admin.com +PGADMIN_DEFAULT_PASSWORD=admin diff --git a/deploy/startup-backend.sh b/deploy/startup-backend.sh new file mode 100755 index 000000000..cf63444b5 --- /dev/null +++ b/deploy/startup-backend.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +export LANGFLOW_DATABASE_URL="postgresql://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}" + +# Your command to start the backend +exec uvicorn --factory langflow.main:create_app --host 0.0.0.0 --port 7860 --reload --log-level ${LOG_LEVEL:-info}