name: Build & Deploy on: push: branches: [main] workflow_dispatch: jobs: build-and-deploy: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Login to Gitea Registry uses: docker/login-action@v3 with: registry: git.mancinas.io username: ${{ secrets.REGISTRY_USER }} password: ${{ secrets.REGISTRY_TOKEN }} - name: Build and push Docker image uses: docker/build-push-action@v5 with: context: . push: true tags: git.mancinas.io/rmancinas/ascii-art-app:latest cache-from: type=gha cache-to: type=gha,mode=max - name: Deploy to Portainer via API run: | # Get current service spec SERVICE_URL="${{ secrets.PORTAINER_API }}/endpoints/2/docker/services/ascii-art-app_ascii-art-app" SPEC=$(curl -sk "$SERVICE_URL" -H "Authorization: Bearer ${{ secrets.PORTAINER_TOKEN }}") # Update version to force redeploy VERSION=$(echo "$SPEC" | jq -r '.Version.Index') UPDATED_SPEC=$(echo "$SPEC" | jq '.Spec | .TaskTemplate.ForceUpdate += 1') # Redeploy curl -sk -X POST "$SERVICE_URL/update?version=$VERSION" \ -H "Authorization: Bearer ${{ secrets.PORTAINER_TOKEN }}" \ -H "Content-Type: application/json" \ -d "$UPDATED_SPEC"