Fix workflow to match gitea-actions-portainer-deploy skill pattern
Build and Deploy / Build Image (push) Failing after 9s
Build and Deploy / Deploy to Portainer (push) Has been skipped

This commit is contained in:
Ricardo Mancinas
2026-07-11 20:59:36 -07:00
parent aadd136592
commit 947ad44da5
2 changed files with 59 additions and 36 deletions
+58 -35
View File
@@ -1,48 +1,71 @@
name: Build & Deploy name: Build and Deploy
on: on:
push: push:
branches: [main] branches: [main]
paths:
- "**"
- "Dockerfile"
- "docker-compose.yml"
workflow_dispatch: workflow_dispatch:
env:
REGISTRY: git.mancinas.io
REPO_NAME: ascii-art-app
jobs: jobs:
build-and-deploy: build:
runs-on: ubuntu-latest name: Build Image
runs-on: docker
container:
image: docker:27-dind
options: --privileged
permissions:
contents: read
packages: write
steps: steps:
- name: Checkout code - uses: actions/checkout@v4
uses: actions/checkout@v4 - uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Gitea Registry
uses: docker/login-action@v3
with: with:
registry: git.mancinas.io registry: ${{ env.REGISTRY }}
username: ${{ secrets.REGISTRY_USER }} username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_TOKEN }} password: ${{ secrets.REGISTRY_PASSWORD }}
- id: meta
- name: Build and push Docker image uses: docker/metadata-action@v5
uses: docker/build-push-action@v5 with:
images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.REPO_NAME }}
tags: |
type=ref,event=branch
type=raw,value=latest,enable={{is_default_branch}}
- uses: docker/build-push-action@v5
with: with:
context: . context: .
file: Dockerfile
push: true push: true
tags: git.mancinas.io/rmancinas/ascii-art-app:latest tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha labels: ${{ steps.meta.outputs.labels }}
cache-to: type=gha,mode=max platforms: linux/amd64
- name: Deploy to Portainer via API deploy:
run: | name: Deploy to Portainer
# Get current service spec needs: [build]
SERVICE_URL="${{ secrets.PORTAINER_API }}/endpoints/2/docker/services/ascii-art-app_ascii-art-app" runs-on: docker
SPEC=$(curl -sk "$SERVICE_URL" -H "Authorization: Bearer ${{ secrets.PORTAINER_TOKEN }}") container:
image: node:18-alpine
# Update version to force redeploy if: github.ref == 'refs/heads/main' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch')
VERSION=$(echo "$SPEC" | jq -r '.Version.Index') steps:
UPDATED_SPEC=$(echo "$SPEC" | jq '.Spec | .TaskTemplate.ForceUpdate += 1') - uses: actions/checkout@v4
- uses: cssnr/portainer-stack-deploy-action@v1
# Redeploy with:
curl -sk -X POST "$SERVICE_URL/update?version=$VERSION" \ url: ${{ secrets.PORTAINER_URL }}
-H "Authorization: Bearer ${{ secrets.PORTAINER_TOKEN }}" \ token: ${{ secrets.PORTAINER_API_KEY }}
-H "Content-Type: application/json" \ name: ${{ secrets.PORTAINER_STACK_NAME }}
-d "$UPDATED_SPEC" file: docker-compose.yml
type: file
pull_image: true
endpoint_id: ${{ secrets.PORTAINER_ENDPOINT_ID }}
env_data: |
{
"IMAGE": "${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.REPO_NAME }}:latest"
}
+1 -1
View File
@@ -2,7 +2,7 @@ version: '3.8'
services: services:
ascii-art-app: ascii-art-app:
image: git.mancinas.io/rmancinas/ascii-art-app:latest image: ${IMAGE:-git.mancinas.io/rmancinas/ascii-art-app:latest}
deploy: deploy:
replicas: 1 replicas: 1
restart_policy: restart_policy: