80 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			YAML
		
	
	
	
	
	
			
		
		
	
	
			80 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			YAML
		
	
	
	
	
	
| kind: pipeline
 | |
| type: docker
 | |
| name: Build y Deploy
 | |
| 
 | |
| trigger:
 | |
|   branch:
 | |
|   - main
 | |
|   event:
 | |
|   - push
 | |
| 
 | |
| steps:
 | |
| - name: build-and-publish-backend
 | |
|   image: plugins/docker
 | |
|   settings:
 | |
|     # El registro es la IP pública para que Docker pueda subir la imagen
 | |
|     registry:
 | |
|       from_secret: REGISTRY_URL
 | |
|     # El repo se construye con el dueño y nombre del repo en Gitea
 | |
|     repo: ${{DRONE_REPO_OWNER}}/${{DRONE_REPO_NAME}}-backend
 | |
|     # El usuario y la contraseña (PAT) para el login
 | |
|     username:
 | |
|       from_secret: GITEA_USER
 | |
|     password:
 | |
|       from_secret: ACTIONS_PAT
 | |
|     # El Dockerfile a usar
 | |
|     dockerfile: Backend/GestionIntegral.Api/Dockerfile
 | |
|     # Las etiquetas
 | |
|     tags:
 | |
|       - latest
 | |
|       - ${{DRONE_COMMIT_SHA:0:8}}
 | |
| 
 | |
| - name: build-and-publish-frontend
 | |
|   image: plugins/docker
 | |
|   settings:
 | |
|     registry:
 | |
|       from_secret: REGISTRY_URL
 | |
|     repo: ${{DRONE_REPO_OWNER}}/${{DRONE_REPO_NAME}}-frontend
 | |
|     username:
 | |
|       from_secret: GITEA_USER
 | |
|     password:
 | |
|       from_secret: ACTIONS_PAT
 | |
|     dockerfile: Frontend/Dockerfile
 | |
|     tags:
 | |
|       - latest
 | |
|       - ${{DRONE_COMMIT_SHA:0:8}}
 | |
|   depends_on:
 | |
|     - build-and-publish-backend
 | |
| 
 | |
| # --- ¡LA SECCIÓN FINAL Y CORRECTA! ---
 | |
| - name: deploy-to-production
 | |
|   image: appleboy/drone-ssh
 | |
|   settings:
 | |
|     host:
 | |
|       from_secret: PROD_SERVER_HOST
 | |
|     username:
 | |
|       from_secret: PROD_SERVER_USER
 | |
|     key:
 | |
|       from_secret: PROD_SERVER_SSH_KEY
 | |
|     
 | |
|     # --- ¡LA SINTAXIS CORRECTA! ---
 | |
|     # Le pasamos los secretos como variables de entorno al script
 | |
|     env_vars:
 | |
|       - DB_SA_PASSWORD=${DB_SA_PASSWORD_SECRET}
 | |
|       - JWT_KEY=${JWT_KEY_SECRET}
 | |
|       - REGISTRY_URL=${REGISTRY_URL}
 | |
|       - GITEA_USER=${GITEA_USER}
 | |
|       - ACTIONS_PAT=${ACTIONS_PAT}
 | |
| 
 | |
|     # El plugin usa 'script', no 'commands'.
 | |
|     script:
 | |
|       - cd /opt/gestion-integral
 | |
|       - export DB_SA_PASSWORD # Las variables ya están en el entorno, solo las exportamos
 | |
|       - export JWT_KEY
 | |
|       - docker login $REGISTRY_URL -u $GITEA_USER -p $ACTIONS_PAT
 | |
|       - docker compose pull
 | |
|       - docker compose up -d
 | |
|       - docker image prune -af
 | |
|       
 | |
|   depends_on:
 | |
|     - build-and-publish-frontend |