Merge pull request 'PR Automatica OpenCode: opencode-issue-9' (#10) from opencode-issue-9 into main
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 5s

Reviewed-on: #10
closes #9
This commit was merged in pull request #10.
This commit is contained in:
2026-07-06 06:56:03 +00:00
2 changed files with 104 additions and 0 deletions
+97
View File
@@ -0,0 +1,97 @@
name: Publish Docker Image
on:
workflow_dispatch:
inputs:
proxy_mode:
description: 'Proxy mode (nginx o traefik)'
required: true
default: 'nginx'
type: choice
options:
- nginx
- traefik
push:
tags:
- 'v*'
env:
IMAGE_NAME: ${{ gitea.repository }}
IMAGE_TAG: ${{ gitea.ref_name }}
# Registry (default Docker Hub, cambia con un secret se usi un registry privato)
REGISTRY: ${{ secrets.DOCKER_REGISTRY || 'docker.io' }}
# Modalità proxy
PROXY_MODE: ${{ inputs.proxy_mode || 'nginx' }}
# Container name sulla VPS
CONTAINER_NAME: test-app
# Porta host per modalità nginx
HOST_PORT: ${{ secrets.HOST_PORT || '8080' }}
jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
- name: Deploy to VPS via SSH
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.VPS_HOST }}
username: ${{ secrets.VPS_USER }}
key: ${{ secrets.VPS_SSH_KEY }}
port: ${{ secrets.VPS_PORT || '22' }}
envs: IMAGE_NAME,IMAGE_TAG,REGISTRY,PROXY_MODE,CONTAINER_NAME,HOST_PORT
script: |
set -e
FULL_IMAGE="$REGISTRY/$IMAGE_NAME:$IMAGE_TAG"
echo "=== Pull immagine ==="
echo "$DOCKER_PASSWORD" | docker login "$REGISTRY" -u "$DOCKER_USERNAME" --password-stdin 2>/dev/null || true
docker pull "$FULL_IMAGE"
echo "=== Ferma e rimuovi container esistente ==="
docker stop "$CONTAINER_NAME" 2>/dev/null || true
docker rm "$CONTAINER_NAME" 2>/dev/null || true
echo "=== Avvia container (proxy: $PROXY_MODE) ==="
if [ "$PROXY_MODE" = "traefik" ]; then
docker run -d \
--name "$CONTAINER_NAME" \
--network traefik \
--label "traefik.enable=true" \
--label "traefik.http.routers.$CONTAINER_NAME.rule=Host(\`${{ secrets.DOMAIN }}\`)" \
--label "traefik.http.services.$CONTAINER_NAME.loadbalancer.server.port=80" \
"$FULL_IMAGE"
else
docker run -d \
--name "$CONTAINER_NAME" \
-p "$HOST_PORT:80" \
"$FULL_IMAGE"
fi
echo "=== Pulizia ==="
docker image prune -f
echo "=== Deploy completato ==="
echo "Immagine: $FULL_IMAGE"
echo "Proxy: $PROXY_MODE"
+7
View File
@@ -0,0 +1,7 @@
FROM nginx:stable-alpine
COPY index.html /usr/share/nginx/html/index.html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]