162 أسطر
5.1 KiB
YAML
162 أسطر
5.1 KiB
YAML
name: Auto Deploy to Ghaymah
|
|
|
|
on:
|
|
push:
|
|
branches: [ main, master ]
|
|
pull_request:
|
|
branches: [ main, master ]
|
|
|
|
env:
|
|
IMAGE_NAME: weather-app
|
|
DOCKER_USERNAME: ahmedgamalyousef
|
|
APP_NAME: weather-app
|
|
APP_PORT: 5000
|
|
|
|
jobs:
|
|
build-test-deploy:
|
|
# name: Build, Test & Deploy
|
|
# runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
# Step 1: Checkout code
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
# # Step 2: Set up Node.js (if your app needs it)
|
|
# - name: Setup Node.js
|
|
# uses: actions/setup-node@v4
|
|
# with:
|
|
# node-version: '18'
|
|
# cache: 'npm'
|
|
|
|
# # Step 3: Install dependencies and test
|
|
# - name: Install dependencies
|
|
# run: npm install
|
|
|
|
# - name: Run tests
|
|
# run: npm test
|
|
|
|
# Step 4: Set up Docker Buildx
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
# Step 5: Login to Docker Hub
|
|
- name: Login to Docker Hub
|
|
uses: docker/login-action@v3
|
|
with:
|
|
username: ${{ secrets.DOCKER_USERNAME }}
|
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
|
|
|
# Step 6: Extract version from git commit
|
|
- name: Get version from commit
|
|
id: version
|
|
run: |
|
|
SHORT_SHA=$(git rev-parse --short HEAD)
|
|
TIMESTAMP=$(date +%Y%m%d%H%M%S)
|
|
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
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
push: true
|
|
tags: |
|
|
${{ steps.version.outputs.IMAGE_TAG }}
|
|
${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:latest
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
labels: |
|
|
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
|
|
org.opencontainers.image.revision=${{ github.sha }}
|
|
|
|
# Step 8: Install Ghaymah CLI
|
|
- name: Install Ghaymah CLI
|
|
run: |
|
|
echo "📥 Installing Ghaymah CLI..."
|
|
curl -sSl https://cli.ghaymah.systems/install.sh | bash
|
|
echo "✅ Ghaymah CLI installed"
|
|
|
|
# Step 9: Configure Ghaymah
|
|
- name: Configure Ghaymah deployment
|
|
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
|
|
run: |
|
|
echo "⚙️ Creating Ghaymah configuration..."
|
|
|
|
# Create .ghaymah.json configuration
|
|
cat > .ghaymah.json << EOF
|
|
{
|
|
"container": {
|
|
"image": "${{ steps.version.outputs.IMAGE_TAG }}",
|
|
"pullSecretName": ""
|
|
},
|
|
"name": "${{ env.APP_NAME }}",
|
|
"ports": [
|
|
{
|
|
"expose": true,
|
|
"number": ${{ env.APP_PORT }}
|
|
}
|
|
],
|
|
"projectId": "${{ secrets.GHAYMAH_PROJECT_ID }}",
|
|
"publicAccess": {
|
|
"baseDomain": "hosted.ghaymah.systems",
|
|
"domain": "auto",
|
|
"enabled": true
|
|
},
|
|
"resourceTier": "t1"
|
|
}
|
|
EOF
|
|
|
|
echo "✅ Configuration file created"
|
|
cat .ghaymah.json
|
|
|
|
# Step 10: Deploy to Ghaymah
|
|
- name: Deploy to Ghaymah
|
|
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
|
|
run: |
|
|
echo "🚀 Deploying to Ghaymah..."
|
|
|
|
# Deploy the application
|
|
gy resource app launch
|
|
|
|
echo "✅ Deployment command completed"
|
|
|
|
# Step 11: Wait and verify deployment
|
|
- name: Verify deployment
|
|
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
|
|
run: |
|
|
echo "⏳ Waiting for deployment to become ready..."
|
|
sleep 45
|
|
|
|
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
|
|
for i in {1..6}; do
|
|
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
|
|
|
|
# Step 12: Deployment summary
|
|
- name: Deployment summary
|
|
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
|
|
run: |
|
|
echo ""
|
|
echo "🎉 DEPLOYMENT SUCCESSFUL!"
|
|
echo "================================"
|
|
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 "================================" |