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