diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 7cb048c..45bf497 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -25,7 +25,6 @@ jobs: run: | docker system prune -a --volumes -f - - name: Build and restart containers + - name: Deploy to Container run: | - # Đảm bảo file .env tồn tại trước khi chạy - docker compose --env-file ./assets/resources/.env up -d --build \ No newline at end of file + docker compose --env-file ./assets/resources/.env up -d --build --remove-orphans \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 34e7149..32aed88 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -28,30 +28,28 @@ services: - 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 + image: migrate/migrate + container_name: history_migrate + depends_on: + db: + condition: service_healthy + env_file: + - ./assets/resources/.env + volumes: + # Sử dụng đường dẫn tuyệt đối biến docker tự hiểu hoặc đảm bảo folder tồn tại + - ./db/migrations:/migrations:ro + entrypoint: + - sh + - -c + - | + DB_URL="postgres://$${POSTGRES_USER}:$${POSTGRES_PASSWORD}@db:5432/$${POSTGRES_DB}?sslmode=disable" + # Thêm ls để debug xem có file không nếu vẫn lỗi + ls /migrations + /migrate -path /migrations -database "$$DB_URL" up || \ + (/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