Add .env-example file and update configuration for environment variables
- Created .env-example for environment variable setup - Updated README to reflect changes in .env file creation - Modified config.py to include new environment variables and DATABASE_URL property - Enhanced database.py with connect and disconnect functions - Updated main.py to manage database connection lifecycle - Adjusted compose.yaml for consistent environment variable usage
This commit is contained in:
20
compose.yaml
20
compose.yaml
@ -1,14 +1,12 @@
|
||||
services:
|
||||
api:
|
||||
restart: unless-stopped
|
||||
container_name: api_${postgres_db}
|
||||
container_name: api_${POSTGRES_DB}
|
||||
build: .
|
||||
env_file:
|
||||
- .env
|
||||
ports:
|
||||
- "${api_port}:8000"
|
||||
environment:
|
||||
DATABASE_URL: postgresql+asyncpg://${postgres_user}:${postgres_password}@db:${db_port}/${postgres_db}
|
||||
- "${API_PORT}:8000"
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
@ -17,20 +15,20 @@ services:
|
||||
|
||||
db:
|
||||
image: postgres:18-alpine
|
||||
container_name: postgres_${postgres_db}
|
||||
container_name: postgres_${POSTGRES_DB}
|
||||
restart: unless-stopped
|
||||
shm_size: 128mb
|
||||
ports:
|
||||
- ${db_port}:5432
|
||||
#ports: #Not needed as the API container will connect to the DB container using the internal Docker network. Uncomment if you want to access the database from outside the Docker network.
|
||||
# - 5432:5432
|
||||
volumes:
|
||||
- ./postgresData:/var/lib/postgresql/data
|
||||
- ./Create.sql:/docker-entrypoint-initdb.d/Create.sql
|
||||
environment:
|
||||
POSTGRES_USER: ${postgres_user}
|
||||
POSTGRES_PASSWORD: ${postgres_password}
|
||||
POSTGRES_DB: ${postgres_db}
|
||||
POSTGRES_USER: ${POSTGRES_USER}
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
||||
POSTGRES_DB: ${POSTGRES_DB}
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U ${postgres_user} -d ${postgres_db}"]
|
||||
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
|
||||
Reference in New Issue
Block a user