This commit is contained in:
@@ -3,27 +3,71 @@ services:
|
||||
image: postgis/postgis:18-3.6
|
||||
container_name: history_db
|
||||
restart: unless-stopped
|
||||
env_file:
|
||||
- ./assets/resources/.env
|
||||
environment:
|
||||
POSTGRES_USER: history
|
||||
POSTGRES_PASSWORD: secret
|
||||
POSTGRES_DB: history_map
|
||||
PGDATA: /var/lib/postgresql/data
|
||||
ports:
|
||||
- "5432:5432"
|
||||
- POSTGRES_USER=${POSTGRES_USER}
|
||||
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
|
||||
- POSTGRES_DB=${POSTGRES_DB}
|
||||
- PGDATA=/var/lib/postgresql/data
|
||||
volumes:
|
||||
- ./pg_data:/var/lib/postgresql
|
||||
- pg_data:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U history -d history_map"]
|
||||
test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 5
|
||||
networks:
|
||||
- history-api-project
|
||||
|
||||
cache:
|
||||
image: redis:8.6.1-alpine
|
||||
container_name: history_redis
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- history-api-project
|
||||
|
||||
migrate:
|
||||
image: migrate/migrate
|
||||
container_name: history_migrate
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
env_file:
|
||||
- ./assets/resources/.env
|
||||
volumes:
|
||||
- ./db/migrations:/migrations
|
||||
# Sử dụng sh -c để có thể chạy chuỗi lệnh
|
||||
entrypoint:
|
||||
- sh
|
||||
- -c
|
||||
- |
|
||||
# Lấy URL database từ biến môi trường
|
||||
DB_URL="postgres://$${POSTGRES_USER}:$${POSTGRES_PASSWORD}@db:5432/$${POSTGRES_DB}?sslmode=disable"
|
||||
|
||||
echo "Checking for dirty database..."
|
||||
/migrate -path /migrations -database "$$DB_URL" up || \
|
||||
(echo "Database is dirty, forcing to version 8..." && \
|
||||
/migrate -path /migrations -database "$$DB_URL" force 8 && \
|
||||
/migrate -path /migrations -database "$$DB_URL" up)
|
||||
networks:
|
||||
- history-api-project
|
||||
app:
|
||||
build: .
|
||||
container_name: history_app
|
||||
restart: unless-stopped
|
||||
depends_on:
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
cache:
|
||||
condition: service_started
|
||||
ports:
|
||||
- "6379:6379"
|
||||
- "3344:3344"
|
||||
networks:
|
||||
- history-api-project
|
||||
|
||||
volumes:
|
||||
pg_data:
|
||||
pg_data:
|
||||
|
||||
networks:
|
||||
history-api-project:
|
||||
Reference in New Issue
Block a user