Skip to content

Commit f2b8ea4

Browse files
committed
fix: depends on
1 parent 07289c9 commit f2b8ea4

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

docker-compose.template.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ services:
77
restart: unless-stopped
88
volumes:
99
- ./userbot/modules:/app/userbot/modules
10-
# 'depends_on' ensures the database is ready before the userbot starts.
11-
# This will be removed by setup.py if an external database is used.
10+
# 'depends_on' теперь ждет, пока сервис 'db' станет "здоровым" (healthy),
11+
# а не просто запустится. Это решает проблему race condition.
1212
depends_on:
13-
- db
14-
# The command no longer needs --accounts, as the bot runs all enabled accounts from the DB
13+
db:
14+
condition: service_healthy
1515
command: ["python3", "-m", "userbot"]
1616

1717
db:
@@ -24,10 +24,15 @@ services:
2424
volumes:
2525
- postgres_data:/var/lib/postgresql/data
2626
ports:
27-
# Exposes the database port to the host machine.
28-
# Format is HOST_PORT:CONTAINER_PORT
2927
- "${DB_PORT}:5432"
3028
restart: unless-stopped
29+
# Healthcheck проверяет, готова ли база данных принимать соединения,
30+
# прежде чем позволить зависимым сервисам (userbot) стартовать.
31+
healthcheck:
32+
test: ["CMD-SHELL", "pg_isready -U ${DB_USER} -d ${DB_NAME}"]
33+
interval: 5s
34+
timeout: 5s
35+
retries: 5
3136

3237
volumes:
3338
postgres_data:

docs/getting-started/installation.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ cd my_debot
2121

2222
#### Шаг 2: Создайте файл `docker-compose.yml`
2323

24-
Внутри папки `my_debot` создайте файл с именем `docker-compose.yml` и скопируйте в него следующее содержимое:
24+
Внутри папки `my_debot` создайте файл с именем `docker-compose.yml` и скопируйте в него следующее содержимое. Он уже включает проверку готовности базы данных (`healthcheck`) для стабильного запуска.
2525

2626
```yaml
2727
services:
@@ -36,7 +36,8 @@ services:
3636
# Эта папка будет создана на вашем хосте для хранения модулей
3737
- ./userbot/modules:/app/userbot/modules
3838
depends_on:
39-
- db
39+
db:
40+
condition: service_healthy
4041
command: ["python3", "-m", "userbot"]
4142

4243
db:
@@ -51,6 +52,11 @@ services:
5152
ports:
5253
- "${DB_PORT}:5432"
5354
restart: unless-stopped
55+
healthcheck:
56+
test: ["CMD-SHELL", "pg_isready -U ${DB_USER} -d ${DB_NAME}"]
57+
interval: 5s
58+
timeout: 5s
59+
retries: 5
5460

5561
volumes:
5662
postgres_data:

scripts/setup.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,26 +94,27 @@ def main():
9494
with open(template_path, "r") as f:
9595
compose_template = f.read()
9696

97-
userbot_service_definition = "build: ." if deploy_type == "source" else f"image: {prompt_user('Enter Docker image', 'debotcommunity/debot:latest')}"
97+
userbot_service_definition = "build: ." if deploy_type == "source" else f"image: whn0thacked/debot:latest"
9898
compose_content = compose_template.replace("${USERBOT_SERVICE_DEFINITION}", userbot_service_definition)
9999

100100
if not use_docker_db:
101-
compose_content = re.sub(r'\s*depends_on:\s+- db', '', compose_content)
101+
# Remove the 'db' service and dependencies on it
102+
compose_content = re.sub(r'^\s*depends_on:.*?service_healthy\s*$', '', compose_content, flags=re.DOTALL | re.MULTILINE)
102103
compose_content = re.sub(r'^\s*db:.*?(?=\n\S|\Z)', '', compose_content, flags=re.DOTALL | re.MULTILINE)
103-
if 'postgres_data:' in compose_content and 'userbot:' not in compose_content:
104-
compose_content = re.sub(r'^\s*volumes:\s*postgres_data:', '', compose_content, flags=re.MULTILINE)
104+
# Remove the volumes key if it's now empty and only contains postgres_data
105+
compose_content = re.sub(r'^\s*volumes:\s*\n\s*postgres_data:\s*$', '', compose_content, flags=re.MULTILINE)
105106

106107
compose_file_path = project_root / "docker-compose.yml"
107108
with open(compose_file_path, "w") as f:
108109
f.write(compose_content.strip() + "\n")
109110
print(f"✅ Docker Compose file generated: {compose_file_path}")
110111

111112
print("\n--- Setup Complete! ---")
112-
print("To start the userbot, run: 'docker-compose up -d'")
113+
print("To start the userbot, run: 'docker compose up -d'")
113114
print("To add your first account, use the management script:")
114-
print(f"\n docker-compose exec userbot python3 -m scripts.manage_account add <account_name>\n")
115+
print(f"\n docker compose exec userbot python3 -m scripts.manage_account add <account_name>\n")
115116
print("After adding an account, restart the bot to activate the new session:")
116-
print("\n docker-compose restart userbot\n")
117+
print("\n docker compose restart userbot\n")
117118

118119
if __name__ == "__main__":
119120
main()

0 commit comments

Comments
 (0)