diff --git a/.forgejo/workflows/build-and-validate.yaml b/.forgejo/workflows/build-and-validate.yaml new file mode 100644 index 0000000..eb9f679 --- /dev/null +++ b/.forgejo/workflows/build-and-validate.yaml @@ -0,0 +1,53 @@ +name: Build and Publish Docker Image + +on: + pull_request: + branches: + - main + +jobs: + build-and-validate: + name: Build and Validate + runs-on: ubuntu + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Validate PR Title + run: | + PR_TITLE="${{ github.event.pull_request.title }}" + echo "PR Title: $PR_TITLE" + + # Check if PR title starts with valid prefix + if [[ "$PR_TITLE" =~ ^(Release|Feature|Hotfix|Bugfix)/ ]]; then + echo "✅ PR title is valid: $PR_TITLE" + else + echo "❌ PR title must start with one of: Release/, Feature/, Hotfix/, or Bugfix/" + echo "Current title: $PR_TITLE" + exit 1 + fi + + - name: Build Docker Image + run: | + docker build --build-arg VERSION=test --build-arg BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") -t threejs-test:test . + + - name: Validate Image + run: | + docker run --rm -d --name test-container -p 8080:80 threejs-test:test + sleep 2 + curl -f http://localhost:8080 || exit 1 + docker stop test-container + + - name: Job Summary + if: success() + run: | + SUMMARY_FILE="${FORGEJO_STEP_SUMMARY}" + cat >> "$SUMMARY_FILE" << 'EOF' + ## ✅ Build and Validation Complete + + - ✅ Docker image built successfully + - ✅ Image validated (container started and HTTP check passed) + + The image is ready for deployment. + EOF + cat "$SUMMARY_FILE" \ No newline at end of file diff --git a/.forgejo/workflows/ci.yaml b/.forgejo/workflows/publish-and-deploy.yaml similarity index 88% rename from .forgejo/workflows/ci.yaml rename to .forgejo/workflows/publish-and-deploy.yaml index 9fd1e03..3bf30d3 100644 --- a/.forgejo/workflows/ci.yaml +++ b/.forgejo/workflows/publish-and-deploy.yaml @@ -1,65 +1,14 @@ name: Build and Publish Docker Image on: - pull_request: - branches: - - main push: branches: - main jobs: - build-and-validate: - name: Build and Validate - runs-on: ubuntu - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Validate PR Title - if: github.event_name == 'pull_request' - run: | - PR_TITLE="${{ github.event.pull_request.title }}" - echo "PR Title: $PR_TITLE" - - # Check if PR title starts with valid prefix - if [[ "$PR_TITLE" =~ ^(Release|Feature|Hotfix|Bugfix)/ ]]; then - echo "✅ PR title is valid: $PR_TITLE" - else - echo "❌ PR title must start with one of: Release/, Feature/, Hotfix/, or Bugfix/" - echo "Current title: $PR_TITLE" - exit 1 - fi - - - name: Build Docker Image - run: | - docker build --build-arg VERSION=test --build-arg BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") -t threejs-test:test . - - - name: Validate Image - run: | - docker run --rm -d --name test-container -p 8080:80 threejs-test:test - sleep 2 - curl -f http://localhost:8080 || exit 1 - docker stop test-container - - - name: Job Summary - if: success() - run: | - SUMMARY_FILE="${FORGEJO_STEP_SUMMARY}" - cat >> "$SUMMARY_FILE" << 'EOF' - ## ✅ Build and Validation Complete - - - ✅ Docker image built successfully - - ✅ Image validated (container started and HTTP check passed) - - The image is ready for deployment. - EOF - publish: name: Publish to Registry runs-on: ubuntu - needs: build-and-validate - if: github.event_name == 'push' steps: - name: Checkout uses: actions/checkout@v4 @@ -297,38 +246,6 @@ jobs: echo "✅ Successfully committed and pushed version update to $VERSION" fi - - name: Trigger Portainer Deployment - if: success() - run: | - VERSION="${{ steps.version.outputs.version }}" - WEBHOOK_URL="${{ secrets.PORTAINER_WEBHOOK_URL }}" - - if [[ -z "$WEBHOOK_URL" ]]; then - echo "⚠️ Warning: PORTAINER_WEBHOOK_URL secret not set, skipping webhook call" - exit 0 - fi - - echo "🚀 Triggering Portainer deployment for version $VERSION" - - # Call Portainer webhook to trigger stack update - HTTP_CODE=$(curl -s -o /tmp/webhook_response.txt -w "%{http_code}" -X POST "$WEBHOOK_URL" \ - -H "Content-Type: application/json" \ - --max-time 30) - - if [[ "$HTTP_CODE" -ge 200 && "$HTTP_CODE" -lt 300 ]]; then - echo "✅ Successfully triggered Portainer deployment (HTTP $HTTP_CODE)" - if [[ -f /tmp/webhook_response.txt ]]; then - echo "Response: $(cat /tmp/webhook_response.txt)" - fi - else - echo "⚠️ Warning: Webhook call returned HTTP $HTTP_CODE" - if [[ -f /tmp/webhook_response.txt ]]; then - echo "Response: $(cat /tmp/webhook_response.txt)" - fi - # Don't fail the workflow if webhook fails - exit 0 - fi - - name: Job Summary if: success() run: | @@ -369,4 +286,39 @@ jobs: docker pull git.jusemon.com/jusemon/threejs-test:latest \`\`\` EOF + cat "$SUMMARY_FILE" + deploy: + name: Deploy to Portainer + runs-on: ubuntu + needs: publish + steps: + - name: Trigger Portainer Deployment + run: | + WEBHOOK_URL="${{ secrets.PORTAINER_WEBHOOK_URL }}" + + if [[ -z "$WEBHOOK_URL" ]]; then + echo "⚠️ Warning: PORTAINER_WEBHOOK_URL secret not set, skipping webhook call" + exit 0 + fi + + echo "🚀 Triggering Portainer deployment for latest version" + + # Call Portainer webhook to trigger stack update + HTTP_CODE=$(curl -s -o /tmp/webhook_response.txt -w "%{http_code}" -X POST "$WEBHOOK_URL" \ + -H "Content-Type: application/json" \ + --max-time 30) + + if [[ "$HTTP_CODE" -ge 200 && "$HTTP_CODE" -lt 300 ]]; then + echo "✅ Successfully triggered Portainer deployment (HTTP $HTTP_CODE)" + if [[ -f /tmp/webhook_response.txt ]]; then + echo "Response: $(cat /tmp/webhook_response.txt)" + fi + else + echo "⚠️ Warning: Webhook call returned HTTP $HTTP_CODE" + if [[ -f /tmp/webhook_response.txt ]]; then + echo "Response: $(cat /tmp/webhook_response.txt)" + fi + # Don't fail the workflow if webhook fails + exit 0 + fi