diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml new file mode 100644 index 0000000..a03c277 --- /dev/null +++ b/.gitea/workflows/deploy.yml @@ -0,0 +1,48 @@ +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" diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..5991777 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,18 @@ +version: '3.8' + +services: + ascii-art-app: + image: git.mancinas.io/rmancinas/ascii-art-app:latest + deploy: + replicas: 1 + restart_policy: + condition: on-failure + delay: 5s + max_attempts: 3 + ports: + - "8182:5000" + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:5000/"] + interval: 30s + timeout: 10s + retries: 3