Skip to content

Commit 7ea538d

Browse files
committed
Fix: Make depends_on Swarm-compatible and add restart policies
1 parent f172d04 commit 7ea538d

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

docker-stack-Swarm.yml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version: "3.8"
33
services:
44
db:
55
image: mcr.microsoft.com/azure-sql-edge:latest
6-
container_name: ecom_sql_db
6+
# ملاحظة: container_name يتم تجاهله في Swarm، الـ Stack يعطيه اسماً تلقائياً
77
environment:
88
- ACCEPT_EULA=Y
99
- MSSQL_SA_PASSWORD=${MSSQL_PASSWORD:-YourStrongPassword123!}
@@ -14,7 +14,6 @@ services:
1414
- sql_data:/var/opt/mssql/data
1515
networks:
1616
- ecom_network
17-
# [Point 3] Health Check لضمان أن قاعدة البيانات جاهزة قبل اتصال الـ Backend
1817
healthcheck:
1918
test:
2019
[
@@ -24,32 +23,35 @@ services:
2423
interval: 10s
2524
timeout: 5s
2625
retries: 5
26+
deploy:
27+
restart_policy:
28+
condition: on-failure
2729

2830
backend:
29-
# [Point 1] إضافة الـ Image Tag الخاص بـ GHCR
3031
image: ghcr.io/developerziad/ecom-backend:latest
3132
build:
3233
context: .
3334
dockerfile: Dockerfile
3435
environment:
3536
- ASPNETCORE_ENVIRONMENT=Production
3637
- ASPNETCORE_URLS=http://+:8080
37-
# [Point 2] استخدام متغيرات البيئة بدلاً من كتابة النصوص برمجياً
3838
- ConnectionStrings__DefaultConnection=Server=db;Database=EcomStoreDB;User Id=sa;Password=${MSSQL_PASSWORD:-YourStrongPassword123!};TrustServerCertificate=True
3939
ports:
4040
- "5000:8080"
41+
# [التصحيح]: في Swarm الـ depends_on يجب أن تكون قائمة أسماء فقط
4142
depends_on:
42-
db:
43-
condition: service_healthy # لن يعمل الـ Backend حتى ينجح الـ Health check الخاص بالـ DB
43+
- db
4444
networks:
4545
- ecom_network
4646
deploy:
47-
replicas: 2 # ميزة Swarm: تشغيل نسختين لضمان عدم توقف المتجر
47+
replicas: 2
4848
restart_policy:
4949
condition: on-failure
50+
delay: 5s
51+
max_attempts: 3
52+
window: 120s
5053

5154
frontend:
52-
# [Point 1] إضافة الـ Image Tag الخاص بـ GHCR
5355
image: ghcr.io/developerziad/ecom-frontend:latest
5456
build:
5557
context: ./EcomFront
@@ -65,10 +67,13 @@ services:
6567
update_config:
6668
parallelism: 1
6769
delay: 10s
70+
restart_policy:
71+
condition: on-failure
6872

6973
networks:
7074
ecom_network:
71-
driver: overlay # في Swarm نستخدم overlay لربط الحاويات عبر عقد مختلفة
75+
driver: overlay
76+
attachable: true # يسمح للحاويات العادية بالاتصال بالشبكة إذا لزم الأمر
7277

7378
volumes:
7479
sql_data:

0 commit comments

Comments
 (0)