From c36a8c92067d18498c81c3d5f4aa5fad344840b1 Mon Sep 17 00:00:00 2001 From: ahmedgamalyousef Date: Mon, 20 Oct 2025 23:12:08 +0300 Subject: [PATCH] Updating CICD Workflow & Creating .ghaymah.json --- .ghaymah.json | 17 ++++++++ .github/workflows/ci.yml | 33 --------------- .github/workflows/cicd.yml | 82 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+), 33 deletions(-) create mode 100644 .ghaymah.json delete mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/cicd.yml diff --git a/.ghaymah.json b/.ghaymah.json new file mode 100644 index 0000000..44261d6 --- /dev/null +++ b/.ghaymah.json @@ -0,0 +1,17 @@ +{ + "id": "712236a8-9f84-41bf-a8e8-08455a63a53e", + "name": "building-api-and-monitoring-logs", + "projectId": "9bf7b7b1-dd1d-48e5-bf06-52130c641683", + "ports": [ + { + "expose": true, + "number": 5000 + } + ], + "publicAccess": { + "enabled": true, + "domain": "auto" + }, + "resourceTier": "t1", + "dockerFileName": "Dockerfile" +} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 4a7ea9c..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: CI - Fruit API - -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - -jobs: - build-and-test: - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: "3.10" - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt - - - name: Run API in background - run: | - python fruit_api.py & - sleep 5 - - - name: Run API tests - run: | - chmod +x test_api.sh - ./test_api.sh diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml new file mode 100644 index 0000000..19d2ed3 --- /dev/null +++ b/.github/workflows/cicd.yml @@ -0,0 +1,82 @@ +name: CI/CD Pipeline of Fruit API + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + + +# ----------------------------- +# ๐Ÿงช 1. Test job +# ----------------------------- + +jobs: + build-and-test: + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.10" + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + - name: Run API in background + run: | + python fruit_api.py & + sleep 5 + + - name: Run API tests + run: | + chmod +x test_api.sh + ./test_api.sh + + + +# ----------------------------- +# ๐Ÿณ 2. Build and Push Docker Image +# ----------------------------- + build_and_push_image: + needs: test + steps: + - name: ๐Ÿ“ฆ Checkout Code + uses: actions/checkout@v5.0.0 + + - name: ๐Ÿ” Login to DockerHub + uses: docker/login-action@v3.6.0 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: ๐Ÿณ Build and Push Docker Image + uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: ahmedgamalyousef/firstcicd:latest + + +# ----------------------------- +# โ˜๏ธ 3. Deploy to Ghaymah Cloud +# ----------------------------- + deploy: + needs: build_and_push_image + steps: + - name: ๐Ÿ“ฆ Checkout Code + uses: actions/checkout@v5.0.0 + + - name: ๐ŸŒฉ๏ธ Install Ghaymah CLI + run: curl -sSl https://cli.ghaymah.systems/install.sh | bash + + - name: ๐Ÿ” Login to Ghaymah Cloud + run: $HOME/ghaymah/bin/gy auth login --email "${{ secrets.GHAYMAH_EMAIL }}" --password "${{ secrets.GHAYMAH_PW }}" + + - name: ๐Ÿš€ Deploy Application + run: $HOME/ghaymah/bin/gy resource app launch +