Skip to content

Commit

Permalink
Fix up postgres setup
Browse files Browse the repository at this point in the history
- run migrations in dev docker compose file
- fix docker install of migrate in different archs
- fix dev docker compose file to launch services in the right order
- add /health endpoint to backend
- add back redis-volume to gitignore to avodi surprises when upgrading
  • Loading branch information
nfcampos committed Mar 20, 2024
1 parent 4ce5152 commit 3735859
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.env
.env.gcp.yaml
postgres-volume/
redis-volume/
backend/ui

# Operating System generated files
Expand Down Expand Up @@ -57,4 +58,4 @@ logs/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
pnpm-debug.log*
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 7 additions & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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" ]
5 changes: 5 additions & 0 deletions backend/app/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
26 changes: 23 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,37 @@ 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:
context: backend
ports:
- "8100:8000" # Backend is accessible on localhost:8100
depends_on:
- postgres
postgres-setup:
condition: service_completed_successfully
env_file:
- .env
volumes:
Expand All @@ -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"

0 comments on commit 3735859

Please sign in to comment.