This commit is contained in:
@@ -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'
|
||||
@@ -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
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
<!doctype html>
|
||||
<html lang="es">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>desplegado por Gitea Actions</title>
|
||||
<style>
|
||||
body { font-family: system-ui, sans-serif; display: grid; place-items: center;
|
||||
height: 100vh; margin: 0; background: #0d1117; color: #e6edf3; }
|
||||
code { background: #161b22; padding: .2rem .4rem; border-radius: 4px; color: #58a6ff; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<h1>Hola desde el CI</h1>
|
||||
<p>Imagen construida y publicada por <code>act_runner</code>.</p>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user