From 7de27f79fe4ebfd28aea647ad03d7ce3a0e16677 Mon Sep 17 00:00:00 2001 From: OpenCode Bot Date: Mon, 6 Jul 2026 06:16:28 +0000 Subject: [PATCH] OpenCode (big-pickle): opencode-issue-9 --- .gitea/workflows/publish.yml | 97 ++++++++++++++++++++++++++++++++++++ Dockerfile | 7 +++ 2 files changed, 104 insertions(+) create mode 100644 .gitea/workflows/publish.yml create mode 100644 Dockerfile diff --git a/.gitea/workflows/publish.yml b/.gitea/workflows/publish.yml new file mode 100644 index 0000000..b8bf137 --- /dev/null +++ b/.gitea/workflows/publish.yml @@ -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" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6452f22 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM nginx:stable-alpine + +COPY index.html /usr/share/nginx/html/index.html + +EXPOSE 80 + +CMD ["nginx", "-g", "daemon off;"]