diff --git a/.gitignore b/.gitignore index 0ee44775..ae1c1eed 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *.env .env.gcp.yaml postgres-volume/ +redis-volume/ backend/ui # Operating System generated files @@ -57,4 +58,4 @@ logs/ npm-debug.log* yarn-debug.log* yarn-error.log* -pnpm-debug.log* \ No newline at end of file +pnpm-debug.log* diff --git a/Dockerfile b/Dockerfile index af28f025..bc626e68 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,9 +15,13 @@ RUN yarn build # Backend Dockerfile FROM python:3.11 +ARG TARGETOS +ARG TARGETARCH +ARG TARGETVARIANT + # Install system dependencies RUN apt-get update && apt-get install -y libmagic1 && rm -rf /var/lib/apt/lists/* -RUN wget -O golang-migrate.deb https://github.com/golang-migrate/migrate/releases/download/v4.17.0/migrate.linux-amd64.deb \ +RUN wget -O golang-migrate.deb https://github.com/golang-migrate/migrate/releases/download/v4.17.0/migrate.${TARGETOS}-${TARGETARCH}${TARGETVARIANT}.deb \ && dpkg -i golang-migrate.deb \ && rm golang-migrate.deb diff --git a/backend/Dockerfile b/backend/Dockerfile index 075fa2af..6d264c51 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,9 +1,13 @@ # Backend Dockerfile FROM python:3.11 +ARG TARGETOS +ARG TARGETARCH +ARG TARGETVARIANT + # Install system dependencies RUN apt-get update && apt-get install -y libmagic1 && rm -rf /var/lib/apt/lists/* -RUN wget -O golang-migrate.deb https://github.com/golang-migrate/migrate/releases/download/v4.17.0/migrate.linux-amd64.deb \ +RUN wget -O golang-migrate.deb https://github.com/golang-migrate/migrate/releases/download/v4.17.0/migrate.${TARGETOS}-${TARGETARCH}${TARGETVARIANT}.deb \ && dpkg -i golang-migrate.deb \ && rm golang-migrate.deb @@ -23,4 +27,6 @@ RUN poetry config virtualenvs.create false \ # Copy the rest of application code COPY . . +HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --start-interval=1s --retries=3 CMD [ "curl", "-f", "http://localhost:8000/health" ] + ENTRYPOINT [ "uvicorn", "app.server:app", "--host", "0.0.0.0" ] diff --git a/backend/app/server.py b/backend/app/server.py index 72c1e2cf..3213cf2f 100644 --- a/backend/app/server.py +++ b/backend/app/server.py @@ -29,6 +29,11 @@ def ingest_files(files: list[UploadFile], config: str = Form(...)) -> None: return ingest_runnable.batch([file.file for file in files], config) +@app.get("/health") +async def health() -> dict: + return {"status": "ok"} + + ui_dir = str(ROOT / "ui") if os.path.exists(ui_dir): diff --git a/docker-compose.yml b/docker-compose.yml index 86e59501..6d59cb42 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,12 +3,28 @@ version: "3" services: postgres: image: pgvector/pgvector:pg16 + healthcheck: + test: pg_isready -U $POSTGRES_USER + start_interval: 1s + start_period: 5s + interval: 5s + retries: 5 ports: - - "5432:5432" + - "5433:5432" env_file: - .env volumes: - ./postgres-volume:/var/lib/postgresql/data + postgres-setup: + image: migrate/migrate + depends_on: + postgres: + condition: service_healthy + volumes: + - ./backend/migrations:/migrations + env_file: + - .env + command: ["-path", "/migrations", "-database", "postgres://$POSTGRES_USER:$POSTGRES_PASSWORD@postgres:$POSTGRES_PORT/$POSTGRES_DB?sslmode=disable", "up"] backend: container_name: opengpts-backend build: @@ -16,7 +32,8 @@ services: ports: - "8100:8000" # Backend is accessible on localhost:8100 depends_on: - - postgres + postgres-setup: + condition: service_completed_successfully env_file: - .env volumes: @@ -29,9 +46,12 @@ services: container_name: opengpts-frontend build: context: frontend + depends_on: + backend: + condition: service_healthy volumes: - ./frontend/src:/frontend/src ports: - "5173:5173" # Frontend is accessible on localhost:5173 environment: - VITE_BACKEND_URL: "http://opengpts-backend:8000" + VITE_BACKEND_URL: "http://backend:8000"