deploy on the cloud and made some refactory on files
هذا الالتزام موجود في:
@@ -1,30 +1,32 @@
|
||||
name: CI/CD - Build, Push, Deploy (Ghaymah)
|
||||
|
||||
# يعمل تلقائيًا عند الدفع لفرع main، أو يدويًا لأي فرع/بيئة عبر workflow_dispatch
|
||||
# Runs automatically on pushes to the main branch, or manually for any branch/environment via workflow_dispatch
|
||||
on:
|
||||
push:
|
||||
branches: ["main"]
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
image_tag:
|
||||
description: "وسم اختياري إضافي للصورة (افتراضيًا: git SHA)"
|
||||
description: "Optional extra image tag (default: git SHA)"
|
||||
required: false
|
||||
default: ""
|
||||
|
||||
# صلاحيات أقل ما يمكن (least privilege)
|
||||
# Least privilege permissions
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
env:
|
||||
# عنوان سجل الحاويات الخاص بغيمة - عدّله حسب مشروعك
|
||||
GHAYMAH_REGISTRY: registry.ghaymah.systems
|
||||
# Docker Hub registry address
|
||||
DOCKER_HUB_REGISTRY: docker.io
|
||||
GHAYMAH_NAMESPACE: my-team
|
||||
IMAGE_NAME: sample-api
|
||||
PROJECT_STAGING_NAME: sample-api-staging
|
||||
PROJECT_PRODUCTION_NAME: sample-api-production
|
||||
|
||||
jobs:
|
||||
# ---------------------------------------------------------------------
|
||||
# 1) بناء الصورة واختبارها ورفعها إلى Ghaymah Container Registry
|
||||
# 1) Build the image, test it, and push it to Docker Hub
|
||||
# ---------------------------------------------------------------------
|
||||
build-and-push:
|
||||
name: Build & Push Image
|
||||
@@ -33,7 +35,7 @@ jobs:
|
||||
image_ref: ${{ steps.vars.outputs.image_ref }}
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v5.0.0
|
||||
|
||||
- name: Set image tag variables
|
||||
id: vars
|
||||
@@ -41,18 +43,18 @@ jobs:
|
||||
SHORT_SHA=$(echo "${GITHUB_SHA}" | cut -c1-7)
|
||||
TAG="${{ github.event.inputs.image_tag }}"
|
||||
if [ -z "$TAG" ]; then TAG="$SHORT_SHA"; fi
|
||||
IMAGE_REF="${GHAYMAH_REGISTRY}/${GHAYMAH_NAMESPACE}/${IMAGE_NAME}:${TAG}"
|
||||
IMAGE_REF="${DOCKER_HUB_REGISTRY}/${GHAYMAH_NAMESPACE}/${IMAGE_NAME}:${TAG}"
|
||||
echo "image_ref=${IMAGE_REF}" >> "$GITHUB_OUTPUT"
|
||||
echo "Building: ${IMAGE_REF}"
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
# تسجيل الدخول إلى سجل حاويات غيمة عبر بيانات اعتماد مخزّنة كـ GitHub Secrets
|
||||
# Log in to Docker Hub using credentials stored as GitHub Secrets
|
||||
- name: Log in to Ghaymah Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.GHAYMAH_REGISTRY }}
|
||||
registry: ${{ env.DOCKER_HUB_REGISTRY }}
|
||||
username: ${{ secrets.GHAYMAH_REGISTRY_USER }}
|
||||
password: ${{ secrets.GHAYMAH_REGISTRY_TOKEN }}
|
||||
|
||||
@@ -64,11 +66,11 @@ jobs:
|
||||
load: true
|
||||
tags: |
|
||||
${{ steps.vars.outputs.image_ref }}
|
||||
${{ env.GHAYMAH_REGISTRY }}/${{ env.GHAYMAH_NAMESPACE }}/${{ env.IMAGE_NAME }}:latest
|
||||
${{ env.DOCKER_HUB_REGISTRY }}/${{ env.GHAYMAH_NAMESPACE }}/${{ env.IMAGE_NAME }}:latest
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
|
||||
# اختبار سريع للتأكد أن /health يستجيب قبل الرفع للسجل (بوابة جودة أساسية)
|
||||
# Quick smoke test to confirm /health responds before pushing
|
||||
- name: Smoke test the built image
|
||||
run: |
|
||||
docker run -d --name smoke -p 8080:8080 ${{ steps.vars.outputs.image_ref }}
|
||||
@@ -86,10 +88,10 @@ jobs:
|
||||
push: true
|
||||
tags: |
|
||||
${{ steps.vars.outputs.image_ref }}
|
||||
${{ env.GHAYMAH_REGISTRY }}/${{ env.GHAYMAH_NAMESPACE }}/${{ env.IMAGE_NAME }}:latest
|
||||
${{ env.DOCKER_HUB_REGISTRY }}/${{ env.GHAYMAH_NAMESPACE }}/${{ env.IMAGE_NAME }}:latest
|
||||
|
||||
# ---------------------------------------------------------------------
|
||||
# 2) نشر تلقائي على STAGING فور نجاح البناء - بدون موافقة يدوية
|
||||
# 2) Automatic deployment to STAGING right after a successful build - no manual approval
|
||||
# ---------------------------------------------------------------------
|
||||
deploy-staging:
|
||||
name: Deploy to Staging
|
||||
@@ -97,62 +99,64 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
environment:
|
||||
name: staging
|
||||
url: https://sample-api-staging.ghaymah.systems
|
||||
steps:
|
||||
- name: Install Ghaymah CLI
|
||||
run: |
|
||||
curl -fsSL https://cli.ghaymah.systems/install.sh | sh
|
||||
ghaymah --version
|
||||
gy version
|
||||
|
||||
- name: Authenticate Ghaymah CLI
|
||||
run: ghaymah auth login --token "${{ secrets.GHAYMAH_API_TOKEN }}"
|
||||
run: gy auth login -e "${{ secrets.GHAYMAH_Email }}" -p "${{ secrets.GHAYMAH_PASSWORD }}"
|
||||
|
||||
- name: Deploy image to staging service
|
||||
run: |
|
||||
ghaymah deploy \
|
||||
--service sample-api-staging \
|
||||
--image "${{ needs.build-and-push.outputs.image_ref }}" \
|
||||
--env staging \
|
||||
--wait
|
||||
- name: create project
|
||||
run: gy resource project create -s .name=${{ env.PROJECT_STAGING_NAME }} || true
|
||||
|
||||
- name: Verify staging health
|
||||
- name: get project id
|
||||
id: get_project_id
|
||||
run: |
|
||||
curl -sf https://sample-api-staging.ghaymah.systems/health
|
||||
echo "PROJECT_ID=$(gy resource project get | grep -oP '"id"\s*:\s*"\K[^"]+')" >> $GITHUB_ENV
|
||||
|
||||
- name: initialize application in Ghaymah
|
||||
run: gy resource app init . -p ${{ env.PROJECT_ID }}
|
||||
|
||||
- name: Deploy Application to Staging
|
||||
run: |
|
||||
gy resource app launch
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------
|
||||
# 3) نشر على PRODUCTION - يتطلب موافقة يدوية (Manual Approval)
|
||||
# الموافقة تُنفَّذ عبر GitHub Environment "production" المحمي بمراجعين
|
||||
# مطلوبين (Required Reviewers) من إعدادات المستودع، وليس بكود مخصص.
|
||||
# 3) Deploy to PRODUCTION - requires manual approval
|
||||
# Approval is handled by the protected GitHub Environment "production"
|
||||
# with Required Reviewers in repository settings, not by custom code.
|
||||
# ---------------------------------------------------------------------
|
||||
deploy-production:
|
||||
name: Deploy to Production (Manual Approval Required)
|
||||
needs: [build-and-push, deploy-staging]
|
||||
runs-on: ubuntu-latest
|
||||
environment:
|
||||
name: production # <-- هذا السطر يفعّل بوابة الموافقة اليدوية المضبوطة في إعدادات المستودع
|
||||
url: https://sample-api.ghaymah.systems
|
||||
name: production # This line enables the manual approval gate configured in repository settings
|
||||
steps:
|
||||
- name: Install Ghaymah CLI
|
||||
run: |
|
||||
curl -fsSL https://cli.ghaymah.systems/install.sh | sh
|
||||
ghaymah --version
|
||||
gy version
|
||||
|
||||
- name: Authenticate Ghaymah CLI
|
||||
run: ghaymah auth login --token "${{ secrets.GHAYMAH_API_TOKEN }}"
|
||||
run: gy auth login -e "${{ secrets.GHAYMAH_Email }}" -p "${{ secrets.GHAYMAH_PASSWORD }}"
|
||||
|
||||
- name: Deploy image to production service
|
||||
run: |
|
||||
ghaymah deploy \
|
||||
--service sample-api-production \
|
||||
--image "${{ needs.build-and-push.outputs.image_ref }}" \
|
||||
--env production \
|
||||
--strategy rolling \
|
||||
--wait
|
||||
|
||||
- name: Verify production health
|
||||
run: |
|
||||
curl -sf https://sample-api.ghaymah.systems/health
|
||||
- name: create project
|
||||
run: gy resource project create -s .name=${{ env.PROJECT_PRODUCTION_NAME }} || true
|
||||
|
||||
- name: Post-deploy smoke check on /metrics
|
||||
- name: get project id
|
||||
id: get_project_id
|
||||
run: |
|
||||
curl -sf https://sample-api.ghaymah.systems/metrics
|
||||
echo "PROJECT_ID=$(gy resource project get | grep -oP '"id"\s*:\s*"\K[^"]+')" >> $GITHUB_ENV
|
||||
|
||||
- name: initialize application in Ghaymah
|
||||
run: gy resource app init . -p ${{ env.PROJECT_ID }}
|
||||
|
||||
- name: Deploy Application to Production
|
||||
run: |
|
||||
gy resource app launch
|
||||
|
||||
|
||||
المرجع في مشكلة جديدة
حظر مستخدم