Creating Github Action CI/CD Workflow
فشلت بعض الفحوصات
Deploy Weather App to Ghaymah / test (push) Successful in 9s
Deploy Weather App to Ghaymah / Deploy to Ghaymah (push) Has been cancelled
Deploy Weather App to Ghaymah / Build and Push Docker Image (push) Has been cancelled

هذا الالتزام موجود في:
ahmedgamalyousef
2025-10-07 20:45:57 +03:00
الأصل 8dc2fd9030
التزام 2fcab25675

153
.github/workflows/cicd.yaml مباع Normal file
عرض الملف

@@ -0,0 +1,153 @@
name: Deploy Weather App to Ghaymah
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
env:
IMAGE_NAME: weather-app
DOCKER_USERNAME: ahmedgamalyousef
jobs:
test:
# name: Test Application
# runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
# - name: Set up Node.js
# uses: actions/setup-node@v4
# with:
# node-version: '18'
# cache: 'npm'
# - name: Install dependencies
# run: npm install
# - name: Run tests
# run: npm test
build-and-push:
name: Build and Push Docker Image
runs-on: ubuntu-latest
needs: test
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract version from commit
id: version
run: |
SHORT_SHA=$(git rev-parse --short HEAD)
echo "VERSION=${SHORT_SHA}" >> $GITHUB_OUTPUT
echo "Using version: ${SHORT_SHA}"
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.VERSION }}
${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Save version info
run: |
echo "${{ steps.version.outputs.VERSION }}" > version.txt
echo "Built image: ${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.VERSION }}"
deploy:
name: Deploy to Ghaymah
runs-on: ubuntu-latest
needs: build-and-push
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download version info
uses: actions/download-artifact@v4
with:
name: version-info
path: ./
- name: Read version
id: version
run: |
VERSION=$(cat version.txt)
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
echo "Deploying version: ${VERSION}"
- name: Install Ghaymah CLI
run: |
curl -fsSL https://cli.ghaymah.systems/install.sh | sh
echo "${{ secrets.GHAYMAH_CONFIG }}" > ~/.ghaymah/config.yaml
- name: Create Ghaymah configuration
run: |
cat > .ghaymah.json << EOF
{
"container": {
"image": "docker.io/${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.VERSION }}",
"pullSecretName": ""
},
"name": "${{ vars.APP_NAME || 'weather-app' }}",
"ports": [
{
"expose": true,
"number": ${{ vars.APP_PORT || 5000 }}
}
],
"projectId": "${{ secrets.GHAYMAH_PROJECT_ID }}",
"publicAccess": {
"baseDomain": "hosted.ghaymah.systems",
"domain": "auto",
"enabled": true
},
"resourceTier": "t1"
}
EOF
- name: Deploy to Ghaymah
run: |
gy resource app launch
env:
GHAYMAH_ACCESS_TOKEN: ${{ secrets.GHAYMAH_ACCESS_TOKEN }}
- name: Wait for deployment and health check
run: |
echo "⏳ Waiting for deployment to become ready..."
sleep 60
APP_URL="https://${{ vars.APP_NAME || 'weather-app' }}.hosted.ghaymah.systems"
echo "🌐 Application URL: $APP_URL"
# Health check (optional)
if command -v curl > /dev/null; then
echo "🔍 Performing health check..."
curl -f --retry 5 --retry-delay 10 "$APP_URL" || echo "⚠️ Health check failed, but deployment completed"
fi
- name: Notify deployment
run: |
echo "🎉 Deployment completed successfully!"
echo "📱 App: ${{ vars.APP_NAME || 'weather-app' }}"
echo "🐳 Image: ${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.VERSION }}"
echo "🌐 URL: https://${{ vars.APP_NAME || 'weather-app' }}.hosted.ghaymah.systems"