Test con Kaniko

This commit is contained in:
2025-06-16 18:44:51 -03:00
parent fcc2b90f15
commit a434640456

View File

@@ -2,11 +2,6 @@ kind: pipeline
type: docker
name: Build y Deploy
volumes:
- name: dockersock
host:
path: /var/run/docker.sock
trigger:
branch:
- main
@@ -15,48 +10,44 @@ trigger:
steps:
- name: build-and-publish-backend
image: plugins/docker
privileged: true
volumes:
- name: dockersock
path: /var/run/docker.sock
# Cambiamos la imagen a Kaniko
image: gcr.io/kaniko-project/executor:v1.9.0-debug
settings:
registry:
from_secret: REGISTRY_URL
repo: 192.168.4.128:5000/${DRONE_REPO_OWNER}/${DRONE_REPO_NAME,,}-backend
# El destino final de la imagen, incluyendo el registro y la primera tag
destination: 192.168.4.128:5000/${DRONE_REPO_OWNER}/${DRONE_REPO_NAME,,}-backend:latest
# Para añadir más tags, las ponemos en una lista aquí
destinations:
- 192.168.4.128:5000/${DRONE_REPO_OWNER}/${DRONE_REPO_NAME,,}-backend:${DRONE_COMMIT_SHA:0:8}
# El Dockerfile que se va a usar
dockerfile: Backend/GestionIntegral.Api/Dockerfile
# El contexto de la construcción (la raíz del repo)
context: .
# Credenciales para el registro (Kaniko las usa para el push)
username:
from_secret: GITEA_USER
password:
from_secret: ACTIONS_PAT
dockerfile: Backend/GestionIntegral.Api/Dockerfile
tags:
- latest
- ${DRONE_COMMIT_SHA:0:8}
# Flag para permitir la conexión a un registro inseguro (HTTP)
insecure: true
- name: build-and-publish-frontend
image: plugins/docker
privileged: true
volumes:
- name: dockersock
path: /var/run/docker.sock
image: gcr.io/kaniko-project/executor:v1.9.0-debug
settings:
registry:
from_secret: REGISTRY_URL
repo: 192.168.4.128:5000/${DRONE_REPO_OWNER}/${DRONE_REPO_NAME,,}-frontend
destination: 192.168.4.128:5000/${DRONE_REPO_OWNER}/${DRONE_REPO_NAME,,}-frontend:latest
destinations:
- 192.168.4.128:5000/${DRONE_REPO_OWNER}/${DRONE_REPO_NAME,,}-frontend:${DRONE_COMMIT_SHA:0:8}
dockerfile: Frontend/Dockerfile
context: .
username:
from_secret: GITEA_USER
password:
from_secret: ACTIONS_PAT
dockerfile: Frontend/Dockerfile
tags:
- latest
- ${DRONE_COMMIT_SHA:0:8}
insecure: true
depends_on:
- build-and-publish-backend
- name: deploy-to-production
# Este paso no cambia en absoluto
image: alpine:latest
environment:
SSH_KEY:
@@ -76,29 +67,21 @@ steps:
GITEA_PAT:
from_secret: ACTIONS_PAT
commands:
# Preparar el entorno SSH
- apk add --no-cache openssh-client
- mkdir -p ~/.ssh
- echo "$SSH_KEY" > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- ssh-keyscan -H $PROD_HOST >> ~/.ssh/known_hosts
# Ejecutar comandos remotos
- |
ssh $PROD_USER@$PROD_HOST << 'EOF'
echo "--- CONECTADO AL SERVIDOR DE PRODUCCIÓN ---"
cd /opt/gestion-integral
# Exportamos las variables que necesita el docker-compose de la app
export DB_SA_PASSWORD="${DB_PASSWORD}"
export JWT_KEY="${JWT_KEY}"
# Login, pull y deploy
docker login ${REGISTRY} -u ${GITEA_USER} -p ${GITEA_PAT}
docker compose pull
docker compose up -d
docker image prune -af
echo "--- DESPLIEGUE COMPLETADO ---"
EOF
depends_on: