Creating Github Action CI/CD Workflow
فشلت بعض الفحوصات
Auto Deploy to Ghaymah / build-test-deploy (push) Failing after 3m21s
فشلت بعض الفحوصات
Auto Deploy to Ghaymah / build-test-deploy (push) Failing after 3m21s
هذا الالتزام موجود في:
143
.github/workflows/cicd.yaml
مباع
143
.github/workflows/cicd.yaml
مباع
@@ -1,4 +1,4 @@
|
|||||||
name: Deploy Weather App to Ghaymah
|
name: Auto Deploy to Ghaymah
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
@@ -9,111 +9,94 @@ on:
|
|||||||
env:
|
env:
|
||||||
IMAGE_NAME: weather-app
|
IMAGE_NAME: weather-app
|
||||||
DOCKER_USERNAME: ahmedgamalyousef
|
DOCKER_USERNAME: ahmedgamalyousef
|
||||||
|
APP_NAME: weather-app
|
||||||
|
APP_PORT: 5000
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
build-test-deploy:
|
||||||
# name: Test Application
|
# name: Build, Test & Deploy
|
||||||
# runs-on: ubuntu-latest
|
# runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
# Step 1: Checkout code
|
||||||
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
# - name: Set up Node.js
|
# # Step 2: Set up Node.js (if your app needs it)
|
||||||
|
# - name: Setup Node.js
|
||||||
# uses: actions/setup-node@v4
|
# uses: actions/setup-node@v4
|
||||||
# with:
|
# with:
|
||||||
# node-version: '18'
|
# node-version: '18'
|
||||||
# cache: 'npm'
|
# cache: 'npm'
|
||||||
|
|
||||||
|
# # Step 3: Install dependencies and test
|
||||||
# - name: Install dependencies
|
# - name: Install dependencies
|
||||||
# run: npm install
|
# run: npm install
|
||||||
|
|
||||||
# - name: Run tests
|
# - name: Run tests
|
||||||
# run: npm test
|
# run: npm test
|
||||||
|
|
||||||
build-and-push:
|
# Step 4: Set up Docker Buildx
|
||||||
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
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
- name: Log in to Docker Hub
|
# Step 5: Login to Docker Hub
|
||||||
|
- name: Login to Docker Hub
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKER_USERNAME }}
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
|
|
||||||
- name: Extract version from commit
|
# Step 6: Extract version from git commit
|
||||||
|
- name: Get version from commit
|
||||||
id: version
|
id: version
|
||||||
run: |
|
run: |
|
||||||
SHORT_SHA=$(git rev-parse --short HEAD)
|
SHORT_SHA=$(git rev-parse --short HEAD)
|
||||||
echo "VERSION=${SHORT_SHA}" >> $GITHUB_OUTPUT
|
TIMESTAMP=$(date +%Y%m%d%H%M%S)
|
||||||
echo "Using version: ${SHORT_SHA}"
|
echo "VERSION=${SHORT_SHA}-${TIMESTAMP}" >> $GITHUB_OUTPUT
|
||||||
|
echo "IMAGE_TAG=${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${SHORT_SHA}-${TIMESTAMP}" >> $GITHUB_OUTPUT
|
||||||
|
echo "🔨 Building version: ${SHORT_SHA}-${TIMESTAMP}"
|
||||||
|
|
||||||
|
# Step 7: Build and push Docker image
|
||||||
- name: Build and push Docker image
|
- name: Build and push Docker image
|
||||||
uses: docker/build-push-action@v5
|
uses: docker/build-push-action@v5
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
push: true
|
push: true
|
||||||
tags: |
|
tags: |
|
||||||
${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.VERSION }}
|
${{ steps.version.outputs.IMAGE_TAG }}
|
||||||
${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:latest
|
${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:latest
|
||||||
cache-from: type=gha
|
cache-from: type=gha
|
||||||
cache-to: type=gha,mode=max
|
cache-to: type=gha,mode=max
|
||||||
|
labels: |
|
||||||
|
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
|
||||||
|
org.opencontainers.image.revision=${{ github.sha }}
|
||||||
|
|
||||||
- name: Save version info
|
# Step 8: Install Ghaymah CLI
|
||||||
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
|
- name: Install Ghaymah CLI
|
||||||
run: |
|
run: |
|
||||||
|
echo "📥 Installing Ghaymah CLI..."
|
||||||
curl -fsSL https://cli.ghaymah.systems/install.sh | sh
|
curl -fsSL https://cli.ghaymah.systems/install.sh | sh
|
||||||
echo "${{ secrets.GHAYMAH_CONFIG }}" > ~/.ghaymah/config.yaml
|
echo "✅ Ghaymah CLI installed"
|
||||||
|
|
||||||
- name: Create Ghaymah configuration
|
# Step 9: Configure Ghaymah
|
||||||
|
- name: Configure Ghaymah deployment
|
||||||
|
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
|
||||||
run: |
|
run: |
|
||||||
|
echo "⚙️ Creating Ghaymah configuration..."
|
||||||
|
|
||||||
|
# Create .ghaymah.json configuration
|
||||||
cat > .ghaymah.json << EOF
|
cat > .ghaymah.json << EOF
|
||||||
{
|
{
|
||||||
"container": {
|
"container": {
|
||||||
"image": "docker.io/${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.VERSION }}",
|
"image": "${{ steps.version.outputs.IMAGE_TAG }}",
|
||||||
"pullSecretName": ""
|
"pullSecretName": ""
|
||||||
},
|
},
|
||||||
"name": "${{ vars.APP_NAME || 'weather-app' }}",
|
"name": "${{ env.APP_NAME }}",
|
||||||
"ports": [
|
"ports": [
|
||||||
{
|
{
|
||||||
"expose": true,
|
"expose": true,
|
||||||
"number": ${{ vars.APP_PORT || 5000 }}
|
"number": ${{ env.APP_PORT }}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"projectId": "${{ secrets.GHAYMAH_PROJECT_ID }}",
|
"projectId": "${{ secrets.GHAYMAH_PROJECT_ID }}",
|
||||||
@@ -125,29 +108,55 @@ jobs:
|
|||||||
"resourceTier": "t1"
|
"resourceTier": "t1"
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
echo "✅ Configuration file created"
|
||||||
|
cat .ghaymah.json
|
||||||
|
|
||||||
|
# Step 10: Deploy to Ghaymah
|
||||||
- name: Deploy to Ghaymah
|
- name: Deploy to Ghaymah
|
||||||
|
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
|
||||||
run: |
|
run: |
|
||||||
|
echo "🚀 Deploying to Ghaymah..."
|
||||||
|
|
||||||
|
# Deploy the application
|
||||||
gy resource app launch
|
gy resource app launch
|
||||||
env:
|
|
||||||
GHAYMAH_ACCESS_TOKEN: ${{ secrets.GHAYMAH_ACCESS_TOKEN }}
|
echo "✅ Deployment command completed"
|
||||||
|
|
||||||
- name: Wait for deployment and health check
|
# Step 11: Wait and verify deployment
|
||||||
|
- name: Verify deployment
|
||||||
|
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
|
||||||
run: |
|
run: |
|
||||||
echo "⏳ Waiting for deployment to become ready..."
|
echo "⏳ Waiting for deployment to become ready..."
|
||||||
sleep 60
|
sleep 45
|
||||||
APP_URL="https://${{ vars.APP_NAME || 'weather-app' }}.hosted.ghaymah.systems"
|
|
||||||
echo "🌐 Application URL: $APP_URL"
|
|
||||||
|
|
||||||
# Health check (optional)
|
APP_URL="https://${{ env.APP_NAME }}.hosted.ghaymah.systems"
|
||||||
|
echo "🌐 Your updated app is available at: $APP_URL"
|
||||||
|
|
||||||
|
# Try to check if app is responding
|
||||||
|
echo "🔍 Checking application health..."
|
||||||
if command -v curl > /dev/null; then
|
if command -v curl > /dev/null; then
|
||||||
echo "🔍 Performing health check..."
|
for i in {1..6}; do
|
||||||
curl -f --retry 5 --retry-delay 10 "$APP_URL" || echo "⚠️ Health check failed, but deployment completed"
|
if curl -s -f --max-time 10 "$APP_URL" > /dev/null; then
|
||||||
|
echo "✅ Application is healthy and responding!"
|
||||||
|
break
|
||||||
|
else
|
||||||
|
echo "⏱️ Attempt $i: Application not ready yet, waiting 10 seconds..."
|
||||||
|
sleep 10
|
||||||
|
fi
|
||||||
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Notify deployment
|
# Step 12: Deployment summary
|
||||||
|
- name: Deployment summary
|
||||||
|
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
|
||||||
run: |
|
run: |
|
||||||
echo "🎉 Deployment completed successfully!"
|
echo ""
|
||||||
echo "📱 App: ${{ vars.APP_NAME || 'weather-app' }}"
|
echo "🎉 DEPLOYMENT SUCCESSFUL!"
|
||||||
echo "🐳 Image: ${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.VERSION }}"
|
echo "================================"
|
||||||
echo "🌐 URL: https://${{ vars.APP_NAME || 'weather-app' }}.hosted.ghaymah.systems"
|
echo "📱 Application: ${{ env.APP_NAME }}"
|
||||||
|
echo "🐳 Image: ${{ steps.version.outputs.IMAGE_TAG }}"
|
||||||
|
echo "🌐 URL: https://${{ env.APP_NAME }}.hosted.ghaymah.systems"
|
||||||
|
echo "🔗 Commit: ${{ github.sha }}"
|
||||||
|
echo "👤 Triggered by: ${{ github.actor }}"
|
||||||
|
echo "================================"
|
||||||
المرجع في مشكلة جديدة
حظر مستخدم