| 
									
										
										
										
											2025-06-15 22:57:24 -03:00
										 |  |  |     kind: pipeline
 | 
					
						
							|  |  |  |     type: docker
 | 
					
						
							|  |  |  |     name: Build y Deploy
 | 
					
						
							| 
									
										
										
										
											2025-06-15 22:18:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-15 22:57:24 -03:00
										 |  |  |     trigger:
 | 
					
						
							|  |  |  |       branch:
 | 
					
						
							|  |  |  |       - main
 | 
					
						
							|  |  |  |       event:
 | 
					
						
							|  |  |  |       - push
 | 
					
						
							| 
									
										
										
										
											2025-06-15 22:18:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-15 22:57:24 -03:00
										 |  |  |     steps:
 | 
					
						
							|  |  |  |     # --- Los pasos de build-and-publish no cambian, ya están bien ---
 | 
					
						
							|  |  |  |     - name: build-and-publish-backend
 | 
					
						
							|  |  |  |       image: plugins/docker
 | 
					
						
							|  |  |  |       settings:
 | 
					
						
							|  |  |  |         registry:
 | 
					
						
							|  |  |  |           from_secret: REGISTRY_URL
 | 
					
						
							|  |  |  |         repo: ${{DRONE_REPO_OWNER}}/${{DRONE_REPO_NAME}}-backend
 | 
					
						
							|  |  |  |         username:
 | 
					
						
							|  |  |  |           from_secret: GITEA_USER
 | 
					
						
							|  |  |  |         password:
 | 
					
						
							|  |  |  |           from_secret: ACTIONS_PAT
 | 
					
						
							|  |  |  |         dockerfile: Backend/GestionIntegral.Api/Dockerfile
 | 
					
						
							|  |  |  |         tags:
 | 
					
						
							|  |  |  |           - latest
 | 
					
						
							|  |  |  |           - ${{DRONE_COMMIT_SHA:0:8}}
 | 
					
						
							| 
									
										
										
										
											2025-06-15 22:18:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-15 22:57:24 -03:00
										 |  |  |     - 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
 | 
					
						
							| 
									
										
										
										
											2025-06-15 22:18:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-15 22:57:24 -03:00
										 |  |  |     # --- ¡LA VERSIÓN FINAL Y CORRECTA! ---
 | 
					
						
							|  |  |  |     - name: deploy-to-production
 | 
					
						
							|  |  |  |       image: appleboy/drone-ssh
 | 
					
						
							|  |  |  |       # Ya no usamos 'settings', el plugin lee los secretos directamente del entorno del paso.
 | 
					
						
							|  |  |  |       environment:
 | 
					
						
							|  |  |  |         HOST:
 | 
					
						
							|  |  |  |           from_secret: PROD_SERVER_HOST
 | 
					
						
							|  |  |  |         USERNAME:
 | 
					
						
							|  |  |  |           from_secret: PROD_SERVER_USER
 | 
					
						
							|  |  |  |         KEY:
 | 
					
						
							|  |  |  |           from_secret: PROD_SERVER_SSH_KEY
 | 
					
						
							|  |  |  |         
 | 
					
						
							|  |  |  |         # Pasamos TODOS los secretos que el script necesita como variables
 | 
					
						
							|  |  |  |         # de entorno al contenedor del plugin.
 | 
					
						
							|  |  |  |         DB_SA_PASSWORD:
 | 
					
						
							|  |  |  |           from_secret: DB_SA_PASSWORD_SECRET
 | 
					
						
							|  |  |  |         JWT_KEY:
 | 
					
						
							|  |  |  |           from_secret: JWT_KEY_SECRET
 | 
					
						
							|  |  |  |         REGISTRY_URL:
 | 
					
						
							|  |  |  |           from_secret: REGISTRY_URL
 | 
					
						
							|  |  |  |         GITEA_USER:
 | 
					
						
							|  |  |  |           from_secret: GITEA_USER
 | 
					
						
							|  |  |  |         ACTIONS_PAT:
 | 
					
						
							|  |  |  |           from_secret: ACTIONS_PAT
 | 
					
						
							| 
									
										
										
										
											2025-06-15 22:52:26 -03:00
										 |  |  |       
 | 
					
						
							| 
									
										
										
										
											2025-06-15 22:57:24 -03:00
										 |  |  |       # El plugin usa 'script' y ahora las variables las tenemos que
 | 
					
						
							|  |  |  |       # pasar como argumentos al script o usarlas directamente.
 | 
					
						
							|  |  |  |       script:
 | 
					
						
							|  |  |  |         # El comando 'export' es crucial para que 'docker compose' los vea
 | 
					
						
							|  |  |  |         - export DB_SA_PASSWORD
 | 
					
						
							|  |  |  |         - export JWT_KEY
 | 
					
						
							|  |  |  |         - echo "Conectando a $HOST como $USERNAME..."
 | 
					
						
							|  |  |  |         - cd /opt/gestion-integral
 | 
					
						
							|  |  |  |         - 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
 |