Docker Compose 開發環境建置
Infrastructure8 個節點 · 7 條連接infrastructure
視覺化
ex-docker-compose-dev.osop.yaml
# Docker Compose Dev Environment Setup
# Pull images, start services, health check, seed data
osop_version: "2.0"
id: docker-compose-dev
name: "Docker Compose 開發環境建置"
nodes:
- id: pull_images
type: docker
purpose: Pull latest images for all development services
runtime:
action: compose-pull
compose_file: docker-compose.yaml
services: [postgres, redis, elasticsearch, app]
outputs: [pulled_images]
timeout_sec: 300
- id: start_services
type: docker
purpose: Start all services via docker compose
runtime:
action: compose-up
compose_file: docker-compose.yaml
detach: true
inputs: [pulled_images]
outputs: [container_ids, service_ports]
timeout_sec: 120
explain: |
Starts services in detached mode. Port mappings:
- App: 3000
- Postgres: 5432
- Redis: 6379
- Elasticsearch: 9200
- id: health_check_db
type: cli
purpose: Wait for PostgreSQL to accept connections
runtime:
command: >
until docker exec dev-postgres pg_isready -U dev; do sleep 2; done
inputs: [container_ids]
timeout_sec: 60
retry_policy:
max_retries: 10
backoff_sec: 3
- id: health_check_redis
type: cli
purpose: Verify Redis is responding to PING
runtime:
command: docker exec dev-redis redis-cli ping
inputs: [container_ids]
timeout_sec: 30
- id: run_migrations
type: db
purpose: Run database migrations to set up schema
runtime:
engine: postgresql
action: migrate
command: npm run db:migrate
inputs: [container_ids]
outputs: [migration_status]
timeout_sec: 120
- id: seed_data
type: db
purpose: Seed database with development sample data
runtime:
engine: postgresql
action: seed
command: npm run db:seed
inputs: [migration_status]
outputs: [seed_status]
timeout_sec: 60
explain: |
Loads sample users, products, and orders for local development.
Includes admin user with default credentials for testing.
- id: verify_app
type: cli
purpose: Verify the application starts and responds
runtime:
command: curl -sf http://localhost:3000/api/health || exit 1
inputs: [seed_status, service_ports]
outputs: [app_ready]
retry_policy:
max_retries: 5
backoff_sec: 5
timeout_sec: 45
- id: print_info
type: cli
purpose: Display development environment access information
runtime:
command: >
echo "Dev environment ready:
App: http://localhost:3000
API: http://localhost:3000/api
DB: postgresql://dev:dev@localhost:5432/devdb"
inputs: [app_ready]
edges:
- from: pull_images
to: start_services
mode: sequential
# Health checks run in parallel after services start
- from: start_services
to: health_check_db
mode: parallel
- from: start_services
to: health_check_redis
mode: parallel
- from: health_check_db
to: run_migrations
mode: sequential
- from: run_migrations
to: seed_data
mode: sequential
- from: seed_data
to: verify_app
mode: sequential
- from: verify_app
to: print_info
mode: sequential