74 lines
2.1 KiB
YAML
74 lines
2.1 KiB
YAML
# Example docker-compose.agent.yml for running the generated clone
|
|
# Copy and adapt this file to your project's needs
|
|
#
|
|
# Key things to customize:
|
|
# - POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_DB (database credentials)
|
|
# - The dump file name in db-init (e.g., postgres_backup.dump)
|
|
# - Volume mounts for your app structure
|
|
|
|
services:
|
|
db:
|
|
image: postgres:16
|
|
ports:
|
|
- "5433:5432"
|
|
environment:
|
|
POSTGRES_USER: myuser
|
|
POSTGRES_PASSWORD: mypassword
|
|
POSTGRES_DB: mydb
|
|
volumes:
|
|
- postgres_data_agent:/var/lib/postgresql/data
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U myuser -d mydb"]
|
|
interval: 5s
|
|
timeout: 5s
|
|
retries: 10
|
|
|
|
db-init:
|
|
image: postgres:16
|
|
depends_on:
|
|
db:
|
|
condition: service_healthy
|
|
volumes:
|
|
- .:/data:ro
|
|
environment:
|
|
PGPASSWORD: mypassword
|
|
command: >
|
|
sh -c "
|
|
TABLE_COUNT=$$(psql -h db -U myuser -d mydb -tAc \"SELECT COUNT(*) FROM information_schema.tables WHERE table_schema='public';\" | tr -d '[:space:]');
|
|
if [ \"$$TABLE_COUNT\" = \"0\" ] && [ -f /data/postgres_backup.dump ]; then
|
|
echo 'Empty database and dump file found. Restoring...';
|
|
pg_restore -h db -U myuser -d mydb --no-owner --clean --if-exists /data/postgres_backup.dump 2>&1 || echo 'Restore completed';
|
|
else
|
|
echo 'Database already initialized or no dump file found. TABLE_COUNT=$$TABLE_COUNT';
|
|
fi"
|
|
|
|
app:
|
|
build:
|
|
context: .
|
|
dockerfile: Dockerfile
|
|
ports:
|
|
- "3000:3000"
|
|
volumes:
|
|
- ./app:/app/app
|
|
- ./components:/app/components
|
|
- ./lib:/app/lib
|
|
- ./public:/app/public
|
|
- ./styles:/app/styles
|
|
environment:
|
|
NODE_ENV: development
|
|
DB_HOST: db
|
|
DB_PORT: 5432
|
|
DB_USER: myuser
|
|
DB_PASSWORD: mypassword
|
|
DB_DATABASE: mydb
|
|
DATABASE_URL: postgresql://myuser:mypassword@db:5432/mydb
|
|
NEXT_PUBLIC_API_URL: ""
|
|
depends_on:
|
|
db:
|
|
condition: service_healthy
|
|
db-init:
|
|
condition: service_completed_successfully
|
|
|
|
volumes:
|
|
postgres_data_agent:
|