Retry mil
This commit is contained in:
		
							
								
								
									
										76
									
								
								.drone.yml
									
									
									
									
									
								
							
							
						
						
									
										76
									
								
								.drone.yml
									
									
									
									
									
								
							| @@ -1,16 +1,15 @@ | ||||
|     kind: pipeline | ||||
|     type: docker | ||||
|     name: Build y Deploy | ||||
| kind: pipeline | ||||
| type: docker | ||||
| name: Build y Deploy | ||||
|  | ||||
|     trigger: | ||||
| trigger: | ||||
|   branch: | ||||
|   - main | ||||
|   event: | ||||
|   - push | ||||
|  | ||||
|     steps: | ||||
|     # --- Los pasos de build-and-publish no cambian, ya están bien --- | ||||
|     - name: build-and-publish-backend | ||||
| steps: | ||||
| - name: build-and-publish-backend | ||||
|   image: plugins/docker | ||||
|   settings: | ||||
|     registry: | ||||
| @@ -25,7 +24,7 @@ | ||||
|       - latest | ||||
|       - ${{DRONE_COMMIT_SHA:0:8}} | ||||
|  | ||||
|     - name: build-and-publish-frontend | ||||
| - name: build-and-publish-frontend | ||||
|   image: plugins/docker | ||||
|   settings: | ||||
|     registry: | ||||
| @@ -42,43 +41,50 @@ | ||||
|   depends_on: | ||||
|     - build-and-publish-backend | ||||
|  | ||||
|     # --- ¡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. | ||||
| - name: deploy-to-production | ||||
|   image: alpine:latest | ||||
|   environment: | ||||
|         HOST: | ||||
|           from_secret: PROD_SERVER_HOST | ||||
|         USERNAME: | ||||
|           from_secret: PROD_SERVER_USER | ||||
|         KEY: | ||||
|     SSH_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: | ||||
|     PROD_HOST: | ||||
|       from_secret: PROD_SERVER_HOST | ||||
|     PROD_USER: | ||||
|       from_secret: PROD_SERVER_USER | ||||
|     DB_PASSWORD: | ||||
|       from_secret: DB_SA_PASSWORD_SECRET | ||||
|     JWT_KEY: | ||||
|       from_secret: JWT_KEY_SECRET | ||||
|         REGISTRY_URL: | ||||
|     REGISTRY: | ||||
|       from_secret: REGISTRY_URL | ||||
|     GITEA_USER: | ||||
|       from_secret: GITEA_USER | ||||
|         ACTIONS_PAT: | ||||
|     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 | ||||
|  | ||||
|       # 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 | ||||
|     # 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: | ||||
|     - build-and-publish-frontend | ||||
		Reference in New Issue
	
	Block a user