matching_app/template/docker-compose.dev.yml
2025-05-02 15:12:18 +07:00

81 lines
2.7 KiB
YAML

version: '3.8'
# Development Environment Docker Compose
# Usage: docker-compose -f template/docker-compose.dev.yml up --build
services:
# Application Service (Matching App)
app:
# Build from the Dockerfile in the project root
build:
context: .. # Context is the parent directory where Dockerfile resides
dockerfile: Dockerfile # Explicitly specify the Dockerfile name
# You could target a specific 'dev' stage here if you create one in Dockerfile for hot-reloading
# target: development
container_name: matching_app_dev
# Mount the source code for local development
# Changes in your local code will reflect inside the container
volumes:
- ..:/app
# Use a named volume for Go modules cache to speed up builds
- go_modules:/go/pkg/mod
# Environment variables from .env file (create .env in project root)
env_file:
- ../.env # Assumes .env file is in the project root (one level up)
ports:
# Map local port 8080 to container port 8080 (adjust if your app uses a different port)
- "8080:8080"
depends_on:
db: # Ensure the database is ready before starting the app
condition: service_healthy
# Command to run the application (consider using a tool like Air for live reloading)
# Sử dụng go run cho phát triển:
command: go run ./cmd/server/main.go
# Example using the built binary (if build stage creates it):
# command: /app/matching-app
restart: unless-stopped
# Database Service (PostgreSQL)
db:
image: postgres:15-alpine # Using alpine variant for smaller size
container_name: matching_db_dev
environment:
# Read DB credentials directly from .env file
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: matching_app
volumes:
# Persist database data using a named volume
- db_data_dev:/var/lib/postgresql/data
# Mount local migrations to initialize DB on first run
- ../migrations:/docker-entrypoint-initdb.d
ports:
# Map local port 5433 to container port 5432 to avoid conflict with local postgres
- "5433:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${DB_USER} -d ${DB_NAME}"]
interval: 5s
timeout: 5s
retries: 5
restart: unless-stopped
# Resource limits suitable for development
deploy:
resources:
limits:
cpus: '0.5'
memory: 512M
# Database Admin Tool (Adminer)
adminer:
image: adminer
container_name: matching_adminer_dev
ports:
- "8081:8080" # Map local port 8081 to container port 8080
depends_on:
- db
restart: always
volumes:
db_data_dev: # Named volume for development DB data
go_modules: # Named volume for Go modules cache