improved dockerfiles and developer setup

This commit is contained in:
Yannic Kilcher
2022-12-17 22:15:01 +01:00
parent edf123e451
commit b45a974287
37 changed files with 78 additions and 55 deletions
+3 -4
View File
@@ -20,13 +20,12 @@ All open source projects begins with people like you. Open source is the belief
Work is organized in the [project board](https://github.com/orgs/LAION-AI/projects/3).
### Python Backend
For a local developer setup, look into the `backend` folder to pull up a local database and backend.
- To get started with development, if you want to work on the backend, have a look at `backend/scripts/backend-development/README.md`.
- If you want to work on the frontend, have a look at `backend/scripts/frontend-development/README.md`.
There is also a minimal implementation of a frontend in the `text-frontend` folder.
We are using Python 3.10
We are using Python 3.10 for the backend.
Check out the [High-Level Protocol Architecture](https://www.notion.so/High-Level-Protocol-Architecture-6f1fd3551da74213b560ead369f132dc)
+11
View File
@@ -0,0 +1,11 @@
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.10
COPY ./requirements.txt /app/requirements.txt
RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt
ENV PORT 8080
COPY ./alembic.ini /alembic.ini
COPY ./alembic /alembic
COPY ./app /app
+3 -1
View File
@@ -3,7 +3,7 @@ from logging.config import fileConfig
import sqlmodel
from alembic import context
from app import models # noqa: F401
from ocgpt import models # noqa: F401
from sqlalchemy import engine_from_config, pool
# this is the Alembic Config object, which provides
@@ -68,6 +68,8 @@ def run_migrations_online() -> None:
context.configure(connection=connection, target_metadata=target_metadata)
with context.begin_transaction():
context.get_context()._ensure_version_table()
connection.execute("LOCK TABLE alembic_version IN ACCESS EXCLUSIVE MODE")
context.run_migrations()
+2 -2
View File
@@ -4,9 +4,9 @@ from pathlib import Path
import alembic.command
import alembic.config
import fastapi
from app.api.v1.api import api_router
from app.config import settings
from loguru import logger
from ocgpt.api.v1.api import api_router
from ocgpt.config import settings
from starlette.middleware.cors import CORSMiddleware
app = fastapi.FastAPI(title=settings.PROJECT_NAME, openapi_url=f"{settings.API_V1_STR}/openapi.json")
@@ -3,12 +3,12 @@ from secrets import token_hex
from typing import Generator
from uuid import UUID
from app.config import settings
from app.database import engine
from app.models import ApiClient
from fastapi import HTTPException, Security
from fastapi.security.api_key import APIKey, APIKeyHeader, APIKeyQuery
from loguru import logger
from ocgpt.config import settings
from ocgpt.database import engine
from ocgpt.models import ApiClient
from sqlmodel import Session
from starlette.status import HTTP_403_FORBIDDEN
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from app.api.v1 import tasks
from fastapi import APIRouter
from ocgpt.api.v1 import tasks
api_router = APIRouter()
api_router.include_router(tasks.router, prefix="/tasks", tags=["tasks"])
@@ -3,13 +3,13 @@ import random
from typing import Any
from uuid import UUID
from app.api import deps
from app.models.db_payload import TaskPayload
from app.prompt_repository import PromptRepository
from app.schemas import protocol as protocol_schema
from fastapi import APIRouter, Depends, HTTPException
from fastapi.security.api_key import APIKey
from loguru import logger
from ocgpt.api import deps
from ocgpt.models.db_payload import TaskPayload
from ocgpt.prompt_repository import PromptRepository
from ocgpt.schemas import protocol as protocol_schema
from sqlmodel import Session
from starlette.status import HTTP_400_BAD_REQUEST
@@ -8,7 +8,8 @@ class Settings(BaseSettings):
PROJECT_NAME: str = "open-chatGPT backend"
API_V1_STR: str = "/api/v1"
POSTGRES_SERVER: str = "localhost:5432"
POSTGRES_HOST: str = "localhost"
POSTGRES_PORT: str = "5432"
POSTGRES_USER: str = "postgres"
POSTGRES_PASSWORD: str = "postgres"
POSTGRES_DB: str = "postgres"
@@ -24,7 +25,8 @@ class Settings(BaseSettings):
scheme="postgresql",
user=values.get("POSTGRES_USER"),
password=values.get("POSTGRES_PASSWORD"),
host=values.get("POSTGRES_SERVER"),
host=values.get("POSTGRES_HOST"),
port=values.get("POSTGRES_PORT"),
path=f"/{values.get('POSTGRES_DB') or ''}",
)
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from app.config import settings
from ocgpt.config import settings
from sqlmodel import create_engine
if settings.DATABASE_URI is None:
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
from typing import Literal
from app.models.payload_column_type import payload_type
from app.schemas import protocol as protocol_schema
from ocgpt.models.payload_column_type import payload_type
from ocgpt.schemas import protocol as protocol_schema
from pydantic import BaseModel
@@ -3,11 +3,11 @@ from datetime import datetime
from typing import Optional
from uuid import UUID, uuid4
import app.models.db_payload as db_payload
from app.models import ApiClient, Person, Post, PostReaction, WorkPackage
from app.models.payload_column_type import PayloadContainer
from app.schemas import protocol as protocol_schema
import ocgpt.models.db_payload as db_payload
from loguru import logger
from ocgpt.models import ApiClient, Person, Post, PostReaction, WorkPackage
from ocgpt.models.payload_column_type import PayloadContainer
from ocgpt.schemas import protocol as protocol_schema
from sqlmodel import Session
View File
-15
View File
@@ -1,15 +0,0 @@
FROM python:3.10
WORKDIR /backend
COPY ./requirements.txt /backend/requirements.txt
RUN pip install --no-cache-dir --upgrade -r /backend/requirements.txt
COPY ./alembic.ini /backend/alembic.ini
COPY ./alembic /backend/alembic
COPY ./app /backend/app
ENV PYTHONPATH=/backend/app
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]
@@ -0,0 +1,5 @@
# Backend Development Setup
Run `docker compose up` to start a database. The default settings are already configured to connect to the database at `localhost:5432`.
Then, run the backend using the `run-local.sh` script. This will start the backend server at `http://localhost:8080`.
@@ -2,10 +2,10 @@
parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
# switch to backend directory
pushd "$parent_path/../"
pushd "$parent_path/../../app"
export ALLOW_ANY_API_KEY=True
uvicorn app.main:app --reload
uvicorn main:app --reload --port 8080 --host 0.0.0.0
popd
-7
View File
@@ -1,7 +0,0 @@
#!/usr/bin/env bash
parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
pushd $parent_path
docker build ../../backend -f ../backend.dockerfile -t laion-ai/ocgpt-backend
popd
-5
View File
@@ -1,5 +0,0 @@
#!/bin/bash
# This script launches a ocgpt-backend docker container stand-alone.
docker run -it --rm -p 127.0.0.1:8000:80/tcp --env POSTGRES_SERVER=host.docker.internal:5432 --env ALLOW_ANY_API_KEY=True --add-host host.docker.internal:host-gateway laion-ai/ocgpt-backend
@@ -0,0 +1,5 @@
# Frontend Development Setup
Run `docker compose up --build` to start a database and the backend server.
Then, point your frontend at `http://localhost:8080` to start developing. During development, any API key will be accepted.
@@ -0,0 +1,26 @@
version: "3.7"
services:
db:
extends:
file: ../backend-development/docker-compose.yaml
service: db
healthcheck:
test: ["CMD", "pg_isready", "-U", "postgres"]
interval: 2s
timeout: 2s
retries: 10
adminer:
extends:
file: ../backend-development/docker-compose.yaml
service: adminer
backend:
build: ../../.
environment:
- POSTGRES_HOST=db
- ALLOW_ANY_API_KEY=True
depends_on:
db:
condition: service_healthy
ports:
- "8080:8080"
+1 -1
View File
@@ -25,7 +25,7 @@ def _render_message(message: dict) -> str:
@app.command()
def main(backend_url: str = "http://127.0.0.1:8000", api_key: str = "DUMMY_KEY"):
def main(backend_url: str = "http://127.0.0.1:8080", api_key: str = "DUMMY_KEY"):
"""Simple REPL frontend."""
def _post(path: str, json: dict) -> dict:
+1 -1
View File
@@ -1,4 +1,4 @@
FASTAPI_URL=http://xamla.com:8000
FASTAPI_URL=http://xamla.com:8080
FASTAPI_KEY=magic_key
DISCORD_CLIENT_ID=your_discord_bot_client_id