deploy on the cloud and made some refactory on files

هذا الالتزام موجود في:
2026-07-27 18:37:20 +03:00
الأصل 80980bbf16
التزام 91d8581c6e
15 ملفات معدلة مع 210 إضافات و102 حذوفات

عرض الملف

@@ -0,0 +1,17 @@
{
"id": "bdf396c2-fdf8-45ef-9066-1486d9b4d512",
"name": "q1-deploy-monitor",
"projectId": "150648a2-a09a-4387-a3af-35f966a28292",
"ports": [
{
"expose": true,
"number": 8080
}
],
"publicAccess": {
"enabled": true,
"domain": "auto"
},
"resourceTier": "t1",
"dockerFileName": "Dockerfile"
}

عرض الملف

@@ -8,8 +8,10 @@
├── Dockerfile
├── requirements.txt
├── .dockerignore
├── .ghaymah.json
├── app/
│ └── main.py # تطبيق Flask + /health + /metrics
├── demo/
├── health-check.sh # سكربت مراقبة بلغة bash (فحص كل 30 ثانية)
├── health-check.py
└── dashboard.html # لوحة مراقبة (HTML/CSS/JS) تعمل من المتصفح مباشرة
@@ -25,35 +27,7 @@ curl http://localhost:8080/health
curl http://localhost:8080/metrics
```
## 2) النشر على ghaymah.systems
منصة الحاويات في Ghaymah تدعم النشر إما عبر ربط مستودع Git (بناء تلقائي من الـ Dockerfile) أو عبر دفع صورة جاهزة إلى سجل الحاويات الخاص بها. الخطوات العامة:
1. سجّل الدخول إلى console الخاص بـ **ghaymah.systems**.
2. من قسم **Containers**، اختر **New Service / Deploy Container**.
3. اختر مصدر النشر:
- **Git Repository**: اربط المستودع الذي يحتوي هذا المشروع (يجب أن يحتوي على `Dockerfile` في الجذر) — المنصة تبني الصورة تلقائيًا من الـ Dockerfile.
- **أو Container Registry**: ابنِ وادفع الصورة يدويًا:
```bash
docker build -t <registry>/<namespace>/sample-api:1.0 .
docker push <registry>/<namespace>/sample-api:1.0
```
ثم أدخل مسار الصورة هذا عند إنشاء الخدمة.
4. اضبط إعدادات الخدمة:
- **Port**: `8080` (نفس المنفذ في `EXPOSE` وفي `PORT` env).
- **Health Check Path**: `/health` (المنصة تستخدمه لمعرفة جاهزية الحاوية).
- **Environment Variables**: أضف `PORT=8080` إن احتاج الأمر.
- **Resources**: ابدأ بأصغر خطة (0.5 vCPU / 256-512MB) كافية لهذا التطبيق التجريبي.
5. اضغط **Deploy**. بعد اكتمال النشر ستحصل على رابط عام مثل:
`https://sample-api-xxxx.ghaymah.systems`
6. تحقق من النشر:
```bash
curl https://sample-api-xxxx.ghaymah.systems/health
```
> ملاحظة: أسماء الأزرار والحقول الدقيقة قد تختلف قليلًا حسب نسخة الواجهة الحالية على `ghaymah.systems` — الخطوات أعلاه تعكس تدفق العمل القياسي لمنصات الحاويات (Container-as-a-Service)، راجع `docs.ghaymah.cloud` لأي تفاصيل محدّثة.
## 3) تشغيل سكربت المراقبة
## 2) تشغيل سكربت المراقبة
بعد النشر، شغّل سكربت المراقبة موجّهًا إلى الرابط العام للتطبيق:
@@ -62,8 +36,8 @@ curl http://localhost:8080/metrics
python health-check.py --url https://sample-api-xxxx.ghaymah.systems --interval 30
# أو bash
chmod +x monitor.sh
./monitor.sh https://sample-api-xxxx.ghaymah.systems 30
chmod +x health-check.sh
./health-check.sh https://sample-api-xxxx.ghaymah.systems 30
```
السكربت يقوم بـ:
@@ -74,7 +48,7 @@ chmod +x monitor.sh
يمكن تشغيله كخدمة نظام دائمة (systemd) أو كحاوية منفصلة (sidecar) بجانب التطبيق نفسه.
## 4) لوحة المراقبة (Dashboard)
## 3) لوحة المراقبة (Dashboard)
افتح `dashboard.html` مباشرة في المتصفح (لا يحتاج خادمًا، ملف ثابت واحد):
@@ -90,7 +64,7 @@ chmod +x monitor.sh
اللوحة تستدعي `/metrics` كل 5 ثوانٍ عبر `fetch()` مباشرة من المتصفح؛ التطبيق (`main.py`) يضيف ترويسة `Access-Control-Allow-Origin: *` لذلك لا حاجة لخادم وسيط.
## ملاحظات إنتاجية (Production Notes)
## 4) ملاحظات إنتاجية (Production Notes)
- التطبيق يعمل بمستخدم غير جذري (`non-root user`) داخل الحاوية.
- يُستخدم `gunicorn` كخادم WSGI إنتاجي بدلاً من خادم التطوير المدمج في Flask.
- `HEALTHCHECK` مضمّن في الـ Dockerfile نفسه، بالإضافة إلى فحص خارجي (`health-check.py`) — طبقتا مراقبة مستقلتان.

ثنائية
q1-deploy-monitor/demo/dashboard.png Normal file

ملف ثنائي غير معروض.

بعد

العرض:  |  الارتفاع:  |  الحجم: 90 KiB

ثنائية
q1-deploy-monitor/demo/ghaymah.png Normal file

ملف ثنائي غير معروض.

بعد

العرض:  |  الارتفاع:  |  الحجم: 231 KiB

ثنائية
q1-deploy-monitor/demo/sample-api.png Normal file

ملف ثنائي غير معروض.

بعد

العرض:  |  الارتفاع:  |  الحجم: 22 KiB

عرض الملف

@@ -7,8 +7,8 @@ logs status + response time, and writes the latest result to a JSON
file (status.json) that can be consumed by other tools or dashboards.
Usage:
python health-check.py --url https://your-app.ghaymah.systems
python health-check.py --url https://your-app.ghaymah.systems --interval 30
python health-check.py --url https://q1-deploy-monitor-cad54f6feeb3.hosted.ghaymah.systems/
python health-check.py --url https://q1-deploy-monitor-cad54f6feeb3.hosted.ghaymah.systems/ --interval 30
"""
import argparse

عرض الملف

@@ -1,7 +1,7 @@
#!/usr/bin/env bash
#
# Simple bash health monitor - polls /health every 30s.
# Usage: ./monitor.sh https://your-app.ghaymah.systems [interval_seconds]
# Usage: ./health-check.sh https://q1-deploy-monitor-cad54f6feeb3.hosted.ghaymah.systems/ [interval_seconds]
set -euo pipefail