diff --git a/.github/workflows/s2i-deploy.yml b/.github/workflows/s2i-deploy.yml new file mode 100644 index 0000000..6e30ba6 --- /dev/null +++ b/.github/workflows/s2i-deploy.yml @@ -0,0 +1,76 @@ +name: S2I Deploy (Automatic) + +on: + push: + branches: [main] + workflow_dispatch: + inputs: + openshift_server: + description: 'OpenShift Server URL' + required: true + default: 'https://oru.apps.shrocp4upi419ovn.lab.upshift.rdu2.redhat.com' + namespace: + description: 'Target Namespace' + required: true + default: 'resource-governance' + +env: + APP_NAME: resource-governance + NAMESPACE: resource-governance + +jobs: + s2i-deploy: + runs-on: ubuntu-latest + timeout-minutes: 15 + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Trigger S2I Build via Webhook + run: | + echo "πŸš€ Triggering S2I build via Generic Webhook..." + echo "πŸ“¦ Repository: ${{ github.repository }}" + echo "πŸ”— Commit: ${{ github.sha }}" + echo "🌿 Branch: ${{ github.ref_name }}" + + # URL do webhook genΓ©rico do OpenShift + WEBHOOK_URL="https://${{ inputs.openshift_server || 'oru.apps.shrocp4upi419ovn.lab.upshift.rdu2.redhat.com' }}/apis/build.openshift.io/v1/namespaces/${{ inputs.namespace || env.NAMESPACE }}/buildconfigs/${{ env.APP_NAME }}/webhooks/pqWLANKULBy1p6aTbPFa/generic" + + echo "πŸ”— Webhook URL: $WEBHOOK_URL" + + # Disparar build S2I + curl -X POST "$WEBHOOK_URL" \ + -H "Content-Type: application/json" \ + -d '{ + "repository": { + "full_name": "${{ github.repository }}", + "clone_url": "${{ github.server_url }}/${{ github.repository }}.git" + }, + "ref": "${{ github.ref }}", + "head_commit": { + "id": "${{ github.sha }}", + "message": "${{ github.event.head_commit.message }}", + "author": { + "name": "${{ github.event.head_commit.author.name }}", + "email": "${{ github.event.head_commit.author.email }}" + } + }, + "pusher": { + "name": "${{ github.actor }}" + } + }' \ + --fail-with-body + + echo "βœ… S2I build triggered successfully!" + + - name: Wait for build completion (optional) + if: github.event_name == 'workflow_dispatch' + run: | + echo "⏳ Waiting for S2I build to complete..." + echo "ℹ️ Check OpenShift console for build progress:" + echo " oc get builds -n ${{ inputs.namespace || env.NAMESPACE }}" + echo " oc logs -f buildconfig/${{ env.APP_NAME }} -n ${{ inputs.namespace || env.NAMESPACE }}" + echo "" + echo "🎯 Build will complete automatically in the background" + echo "πŸ“± You can monitor progress in the OpenShift console" diff --git a/scripts/deploy-s2i.sh b/scripts/deploy-s2i.sh index 659a8a3..d00a784 100755 --- a/scripts/deploy-s2i.sh +++ b/scripts/deploy-s2i.sh @@ -16,6 +16,34 @@ echo " - Service and Route" echo " - Resource limits and requests" echo "" +# Check for GitHub Actions option +if [ "$1" = "--github" ] || [ "$1" = "-g" ]; then + echo "πŸ”„ Deploying via GitHub Actions (S2I Webhook)..." + echo "πŸ“¦ Repository: andersonid/openshift-resource-governance" + echo "🌿 Branch: $(git branch --show-current)" + echo "πŸ”— Commit: $(git rev-parse HEAD)" + echo "" + + # Trigger GitHub Actions workflow + if command -v gh &> /dev/null; then + echo "πŸš€ Triggering S2I deployment via GitHub Actions..." + gh workflow run s2i-deploy.yml + echo "βœ… GitHub Actions workflow triggered!" + echo "πŸ“± Monitor progress: https://github.com/andersonid/openshift-resource-governance/actions" + else + echo "❌ GitHub CLI (gh) not found. Please install it or use manual deployment." + echo "πŸ’‘ Manual webhook URL:" + echo " curl -X POST 'https://oru.apps.shrocp4upi419ovn.lab.upshift.rdu2.redhat.com/apis/build.openshift.io/v1/namespaces/resource-governance/buildconfigs/resource-governance/webhooks/pqWLANKULBy1p6aTbPFa/generic'" + exit 1 + fi + exit 0 +fi + +echo "πŸ’‘ Usage options:" +echo " ./scripts/deploy-s2i.sh # Manual S2I deployment" +echo " ./scripts/deploy-s2i.sh --github # Deploy via GitHub Actions" +echo "" + # Colors for output RED='\033[0;31m' GREEN='\033[0;32m'