![google-labs-jules[bot]](/assets/img/avatar_default.png)
This commit introduces changes to ensure that Alembic database migrations are automatically applied when the backend Docker container starts. Key changes: - Added `be/entrypoint.sh`: This script first runs `alembic upgrade head` to apply any pending migrations and then executes the main container command (e.g., starting Uvicorn). - Modified `be/Dockerfile`: - The `entrypoint.sh` script is copied into the image and made executable. - The Docker `ENTRYPOINT` is set to this script, ensuring migrations run before the application starts. - Updated `docker-compose.yml`: - The `DATABASE_URL` for the `backend` service has been set to the Neon database URL you provided. - Verified `be/alembic/env.py`: Confirmed that it correctly sources the `DATABASE_URL` from environment variables for Alembic to use. These changes address the issue where migrations were not being run, preventing the application from starting correctly.
71 lines
2.2 KiB
YAML
71 lines
2.2 KiB
YAML
services:
|
|
db:
|
|
image: postgres:17 # Use a specific PostgreSQL version
|
|
container_name: postgres_db
|
|
environment:
|
|
POSTGRES_USER: xxx # Define DB user
|
|
POSTGRES_PASSWORD: xxx # Define DB password
|
|
POSTGRES_DB: xxx # Define Database name
|
|
volumes:
|
|
- postgres_data:/var/lib/postgresql/data # Persist data using a named volume
|
|
ports:
|
|
- "5432:5432" # Expose PostgreSQL port to host (optional, for direct access)
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
|
|
interval: 10s
|
|
timeout: 5s
|
|
retries: 5
|
|
start_period: 10s
|
|
restart: unless-stopped
|
|
|
|
backend:
|
|
container_name: fastapi_backend
|
|
build:
|
|
context: ./be # Path to the directory containing the Dockerfile
|
|
dockerfile: Dockerfile
|
|
volumes:
|
|
# Mount local code into the container for development hot-reloading
|
|
# The code inside the container at /app will mirror your local ./be directory
|
|
- ./be:/app
|
|
ports:
|
|
- "8000:8000" # Map container port 8000 to host port 8000
|
|
environment:
|
|
# Pass the database URL to the backend container
|
|
# Uses the service name 'db' as the host, and credentials defined above
|
|
# IMPORTANT: Use the correct async driver prefix if your app needs it!
|
|
- DATABASE_URL=postgresql+asyncpg://mitlist_owner:npg_p0SkmyJ6BPWO@ep-small-sound-a9ketcef-pooler.gwc.azure.neon.tech/testnewmig
|
|
- GEMINI_API_KEY=xxx
|
|
- SECRET_KEY=xxx
|
|
# Add other environment variables needed by the backend here
|
|
# - SOME_OTHER_VAR=some_value
|
|
depends_on:
|
|
db:
|
|
# Wait for the db service to be healthy before starting backend
|
|
condition: service_healthy
|
|
command: [
|
|
"uvicorn",
|
|
"app.main:app",
|
|
"--host",
|
|
"0.0.0.0",
|
|
"--port",
|
|
"8000",
|
|
"--reload",
|
|
] # Override CMD for development reload
|
|
restart: unless-stopped
|
|
|
|
frontend:
|
|
container_name: vite_frontend
|
|
build:
|
|
context: ./fe
|
|
dockerfile: Dockerfile
|
|
ports:
|
|
- "80:80"
|
|
depends_on:
|
|
- backend
|
|
restart: unless-stopped
|
|
|
|
volumes:
|
|
# Define named volumes for data persistence
|
|
postgres_data:
|
|
pgadmin_data:
|