name: Build and Deploy to Ghaymah on: # Run automatically when code is pushed to the main branch push: branches: - main # Allow manual workflow execution from GitHub Actions workflow_dispatch: env: # Replace with the official Ghaymah Container Registry URL REGISTRY: registry.ghaymah.systems # Docker image name IMAGE_NAME: ghaymah-api jobs: # ------------------------------------------------------- # Build the Docker image and push it to the registry # ------------------------------------------------------- build-and-push: runs-on: ubuntu-latest permissions: contents: read packages: write steps: # Check out the repository source code - name: Checkout code uses: actions/checkout@v4 # Enable Docker Buildx for advanced builds and caching - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 # Authenticate with the container registry - name: Log in to Ghaymah Container Registry uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ secrets.GHAYMAH_USERNAME }} password: ${{ secrets.GHAYMAH_TOKEN }} # Build the Docker image and push it to the registry - name: Build and push Docker image uses: docker/build-push-action@v6 with: # Path containing the Dockerfile context: ./q1-deploy-monitor # Push the image after a successful build push: true # Publish two image tags: # - latest # - commit SHA for traceability tags: | ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} # Enable Docker layer caching cache-from: type=gha cache-to: type=gha,mode=max # ------------------------------------------------------- # Deploy the application to the staging environment # ------------------------------------------------------- deploy-staging: needs: build-and-push runs-on: ubuntu-latest # GitHub Environment environment: staging steps: # Install the Ghaymah CLI # Replace with the official installation command if different - name: Install Ghaymah CLI run: | curl -sSL https://get.ghaymah.systems/cli/install.sh | sh echo "$HOME/.ghaymah/bin" >> $GITHUB_PATH # Deploy the application to staging # Replace the commands below with the official CLI syntax if needed - name: Deploy to Staging env: GHAYMAH_TOKEN: ${{ secrets.GHAYMAH_TOKEN }} run: | ghaymah login --token $GHAYMAH_TOKEN ghaymah deploy \ --image ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} \ --name api-staging \ --port 5000 \ --env FLASK_ENV=staging \ --replicas 1 # ------------------------------------------------------- # Deploy the application to the production environment # ------------------------------------------------------- deploy-production: needs: deploy-staging runs-on: ubuntu-latest # Configure this environment with required reviewers # to enable manual approval before deployment environment: production steps: # Install the Ghaymah CLI - name: Install Ghaymah CLI run: | curl -sSL https://get.ghaymah.systems/cli/install.sh | sh echo "$HOME/.ghaymah/bin" >> $GITHUB_PATH # Deploy the application to production # This job runs only after manual approval - name: Deploy to Production env: GHAYMAH_TOKEN: ${{ secrets.GHAYMAH_TOKEN }} run: | ghaymah login --token $GHAYMAH_TOKEN ghaymah deploy \ --image ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} \ --name api-production \ --port 5000 \ --env FLASK_ENV=production \ --replicas 3 \ --health-check /health