Retry mil
This commit is contained in:
		
							
								
								
									
										160
									
								
								.drone.yml
									
									
									
									
									
								
							
							
						
						
									
										160
									
								
								.drone.yml
									
									
									
									
									
								
							| @@ -1,84 +1,90 @@ | |||||||
|     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: | ||||||
|     # --- Los pasos de build-and-publish no cambian, ya están bien --- | - name: build-and-publish-backend | ||||||
|     - name: build-and-publish-backend |   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}}-backend | ||||||
|         repo: ${{DRONE_REPO_OWNER}}/${{DRONE_REPO_NAME}}-backend |     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 | ||||||
|         dockerfile: Backend/GestionIntegral.Api/Dockerfile |     tags: | ||||||
|         tags: |       - latest | ||||||
|           - latest |       - ${{DRONE_COMMIT_SHA:0:8}} | ||||||
|           - ${{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 VERSIÓN FINAL Y CORRECTA! --- | - name: deploy-to-production | ||||||
|     - name: deploy-to-production |   image: alpine:latest | ||||||
|       image: appleboy/drone-ssh |   environment: | ||||||
|       # Ya no usamos 'settings', el plugin lee los secretos directamente del entorno del paso. |     SSH_KEY: | ||||||
|       environment: |       from_secret: PROD_SERVER_SSH_KEY | ||||||
|         HOST: |     PROD_HOST: | ||||||
|           from_secret: PROD_SERVER_HOST |       from_secret: PROD_SERVER_HOST | ||||||
|         USERNAME: |     PROD_USER: | ||||||
|           from_secret: PROD_SERVER_USER |       from_secret: PROD_SERVER_USER | ||||||
|         KEY: |     DB_PASSWORD: | ||||||
|           from_secret: PROD_SERVER_SSH_KEY |       from_secret: DB_SA_PASSWORD_SECRET | ||||||
|  |     JWT_KEY: | ||||||
|  |       from_secret: JWT_KEY_SECRET | ||||||
|  |     REGISTRY: | ||||||
|  |       from_secret: REGISTRY_URL | ||||||
|  |     GITEA_USER: | ||||||
|  |       from_secret: GITEA_USER | ||||||
|  |     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 | ||||||
|  |  | ||||||
|         # Pasamos TODOS los secretos que el script necesita como variables |     # Ejecutar comandos remotos | ||||||
|         # de entorno al contenedor del plugin. |     - | | ||||||
|         DB_SA_PASSWORD: |       ssh $PROD_USER@$PROD_HOST << 'EOF' | ||||||
|           from_secret: DB_SA_PASSWORD_SECRET |         echo "--- CONECTADO AL SERVIDOR DE PRODUCCIÓN ---" | ||||||
|         JWT_KEY: |         cd /opt/gestion-integral | ||||||
|           from_secret: JWT_KEY_SECRET |  | ||||||
|         REGISTRY_URL: |  | ||||||
|           from_secret: REGISTRY_URL |  | ||||||
|         GITEA_USER: |  | ||||||
|           from_secret: GITEA_USER |  | ||||||
|         ACTIONS_PAT: |  | ||||||
|           from_secret: ACTIONS_PAT |  | ||||||
|          |          | ||||||
|       # El plugin usa 'script' y ahora las variables las tenemos que |         # Exportamos las variables que necesita el docker-compose de la app | ||||||
|       # pasar como argumentos al script o usarlas directamente. |         export DB_SA_PASSWORD="${DB_PASSWORD}" | ||||||
|       script: |         export JWT_KEY="${JWT_KEY}" | ||||||
|         # 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: |         # Login, pull y deploy | ||||||
|         - build-and-publish-frontend |         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