commit 917cc312625d45ceab744476d977f415724d6c1f Author: admin Date: Mon Nov 23 18:11:31 2026 +0000 demo: app + workflow diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml new file mode 100644 index 0000000..86acb4e --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,84 @@ +# Ejemplo de pipeline: build -> push al registry de Gitea -> deploy por SSH. +# +# Copia este archivo a la raíz de TU repo como .gitea/workflows/ci.yml +# (Gitea 1.24+ también acepta .github/workflows/). +# +# Secretos a definir en el repo (Settings -> Actions -> Secrets): +# REGISTRY_TOKEN token de acceso de un usuario con permiso de packages +# DEPLOY_SSH_KEY clave privada ed25519 para el servidor destino +# DEPLOY_HOST usuario@servidor (ej. deploy@10.0.0.5) +# +# Notas: +# - runs-on: linux -> label del runner definido en RUNNER_LABELS +# - ${{ gitea.* }} -> contexto nativo de Gitea (github.* también funciona) +# - gitea.server_url trae esquema (https://...), así que el registry se +# deriva en un step quitando el esquema (docker login no lo acepta). +# ----------------------------------------------------------------------------- +name: ci + +on: + push: + branches: [main] + tags: ["v*"] + pull_request: + +jobs: + build: + runs-on: linux + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Resolver registry e imagen + run: | + REG="${{ gitea.server_url }}" + REG="${REG#*://}" + REG="${REG%/}" + echo "REGISTRY=${REG}" >> "$GITHUB_ENV" + echo "IMAGE=${REG}/${{ gitea.repository }}" >> "$GITHUB_ENV" + echo "registry=${REG}" + echo "repo=${{ gitea.repository }} ref=${{ gitea.ref }} sha=${{ gitea.sha }}" + + - name: Entorno + run: | + docker version --format 'daemon {{.Server.Version}}' + docker buildx version || true + + - name: Login al registry de Gitea + run: | + echo "${{ secrets.REGISTRY_TOKEN }}" \ + | docker login "$REGISTRY" -u "${{ gitea.actor }}" --password-stdin + + - name: Build y push + run: | + SHORT="$(echo "${{ gitea.sha }}" | cut -c1-7)" + docker build \ + --label "org.opencontainers.image.revision=${{ gitea.sha }}" \ + --label "org.opencontainers.image.source=${{ gitea.server_url }}/${{ gitea.repository }}" \ + -t "${IMAGE}:${SHORT}" \ + -t "${IMAGE}:latest" . + docker push "${IMAGE}:${SHORT}" + docker push "${IMAGE}:latest" + + - name: Trivy (opcional) + continue-on-error: true + run: | + docker run --rm -v /var/run/docker.sock:/var/run/docker.sock \ + aquasec/trivy:latest image --exit-code 0 --quiet "${IMAGE}:latest" + + deploy: + needs: build + if: gitea.ref == 'refs/heads/main' + runs-on: linux + steps: + - name: Deploy por SSH + env: + SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }} + TARGET: ${{ secrets.DEPLOY_HOST }} + run: | + install -d -m 700 ~/.ssh + printf '%s\n' "$SSH_KEY" > ~/.ssh/id_ed25519 + chmod 600 ~/.ssh/id_ed25519 + ssh -o StrictHostKeyChecking=accept-new "$TARGET" \ + 'cd /srv/app && docker compose pull && docker compose up -d' diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..57f3f8e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +# App de ejemplo para probar el pipeline de Gitea Actions. +# El workflow en .gitea/workflows/ci.yml construye esta imagen, la publica +# en el registry de Gitea y (opcionalmente) la despliega por SSH. +FROM nginx:1.27-alpine +COPY index.html /usr/share/nginx/html/index.html +EXPOSE 80 +HEALTHCHECK --interval=30s --timeout=3s CMD wget -qO- http://127.0.0.1/ >/dev/null || exit 1 diff --git a/index.html b/index.html new file mode 100644 index 0000000..2e9970f --- /dev/null +++ b/index.html @@ -0,0 +1,18 @@ + + + + + desplegado por Gitea Actions + + + +
+

Hola desde el CI

+

Imagen construida y publicada por act_runner.

+
+ +