Va
This commit is contained in:
		
							
								
								
									
										154
									
								
								.drone.yml
									
									
									
									
									
								
							
							
						
						
									
										154
									
								
								.drone.yml
									
									
									
									
									
								
							| @@ -1,80 +1,84 @@ | |||||||
| kind: pipeline |     kind: pipeline | ||||||
| type: docker |     type: docker | ||||||
| name: Build y Deploy |     name: Build y Deploy | ||||||
|  |  | ||||||
| trigger: |     trigger: | ||||||
|   branch: |       branch: | ||||||
|   - main |       - main | ||||||
|   event: |       event: | ||||||
|   - push |       - push | ||||||
|  |  | ||||||
| steps: |     steps: | ||||||
| - name: build-and-publish-backend |     # --- Los pasos de build-and-publish no cambian, ya están bien --- | ||||||
|   image: plugins/docker |     - name: build-and-publish-backend | ||||||
|   settings: |       image: plugins/docker | ||||||
|     # El registro es la IP pública para que Docker pueda subir la imagen |       settings: | ||||||
|     registry: |         registry: | ||||||
|       from_secret: REGISTRY_URL |           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 | ||||||
|     repo: ${{DRONE_REPO_OWNER}}/${{DRONE_REPO_NAME}}-backend |         username: | ||||||
|     # El usuario y la contraseña (PAT) para el login |           from_secret: GITEA_USER | ||||||
|     username: |         password: | ||||||
|       from_secret: GITEA_USER |           from_secret: ACTIONS_PAT | ||||||
|     password: |         dockerfile: Backend/GestionIntegral.Api/Dockerfile | ||||||
|       from_secret: ACTIONS_PAT |         tags: | ||||||
|     # El Dockerfile a usar |           - latest | ||||||
|     dockerfile: Backend/GestionIntegral.Api/Dockerfile |           - ${{DRONE_COMMIT_SHA:0:8}} | ||||||
|     # Las etiquetas |  | ||||||
|     tags: |  | ||||||
|       - latest |  | ||||||
|       - ${{DRONE_COMMIT_SHA:0:8}} |  | ||||||
|  |  | ||||||
| - name: build-and-publish-frontend |     - name: build-and-publish-frontend | ||||||
|   image: plugins/docker |       image: plugins/docker | ||||||
|   settings: |       settings: | ||||||
|     registry: |         registry: | ||||||
|       from_secret: REGISTRY_URL |           from_secret: REGISTRY_URL | ||||||
|     repo: ${{DRONE_REPO_OWNER}}/${{DRONE_REPO_NAME}}-frontend |         repo: ${{DRONE_REPO_OWNER}}/${{DRONE_REPO_NAME}}-frontend | ||||||
|     username: |         username: | ||||||
|       from_secret: GITEA_USER |           from_secret: GITEA_USER | ||||||
|     password: |         password: | ||||||
|       from_secret: ACTIONS_PAT |           from_secret: ACTIONS_PAT | ||||||
|     dockerfile: Frontend/Dockerfile |         dockerfile: Frontend/Dockerfile | ||||||
|     tags: |         tags: | ||||||
|       - latest |           - latest | ||||||
|       - ${{DRONE_COMMIT_SHA:0:8}} |           - ${{DRONE_COMMIT_SHA:0:8}} | ||||||
|   depends_on: |       depends_on: | ||||||
|     - build-and-publish-backend |         - build-and-publish-backend | ||||||
|  |  | ||||||
| # --- ¡LA SECCIÓN FINAL Y CORRECTA! --- |     # --- ¡LA VERSIÓN FINAL Y CORRECTA! --- | ||||||
| - name: deploy-to-production |     - name: deploy-to-production | ||||||
|   image: appleboy/drone-ssh |       image: appleboy/drone-ssh | ||||||
|   settings: |       # Ya no usamos 'settings', el plugin lee los secretos directamente del entorno del paso. | ||||||
|     host: |       environment: | ||||||
|       from_secret: PROD_SERVER_HOST |         HOST: | ||||||
|     username: |           from_secret: PROD_SERVER_HOST | ||||||
|       from_secret: PROD_SERVER_USER |         USERNAME: | ||||||
|     key: |           from_secret: PROD_SERVER_USER | ||||||
|       from_secret: PROD_SERVER_SSH_KEY |         KEY: | ||||||
|      |           from_secret: PROD_SERVER_SSH_KEY | ||||||
|     # --- ¡LA SINTAXIS CORRECTA! --- |          | ||||||
|     # Le pasamos los secretos como variables de entorno al script |         # Pasamos TODOS los secretos que el script necesita como variables | ||||||
|     env_vars: |         # de entorno al contenedor del plugin. | ||||||
|       - DB_SA_PASSWORD=${DB_SA_PASSWORD_SECRET} |         DB_SA_PASSWORD: | ||||||
|       - JWT_KEY=${JWT_KEY_SECRET} |           from_secret: DB_SA_PASSWORD_SECRET | ||||||
|       - REGISTRY_URL=${REGISTRY_URL} |         JWT_KEY: | ||||||
|       - GITEA_USER=${GITEA_USER} |           from_secret: JWT_KEY_SECRET | ||||||
|       - ACTIONS_PAT=${ACTIONS_PAT} |         REGISTRY_URL: | ||||||
|  |           from_secret: REGISTRY_URL | ||||||
|     # El plugin usa 'script', no 'commands'. |         GITEA_USER: | ||||||
|     script: |           from_secret: GITEA_USER | ||||||
|       - cd /opt/gestion-integral |         ACTIONS_PAT: | ||||||
|       - export DB_SA_PASSWORD # Las variables ya están en el entorno, solo las exportamos |           from_secret: ACTIONS_PAT | ||||||
|       - 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: |       # El plugin usa 'script' y ahora las variables las tenemos que | ||||||
|     - build-and-publish-frontend |       # 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 | ||||||
		Reference in New Issue
	
	Block a user