Agregamos el ssh-debug #8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI/CD - Maven + Docker + Deploy | |
| on: | |
| push: | |
| branches: ["master"] | |
| workflow_dispatch: | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '21' | |
| distribution: 'temurin' | |
| cache: maven | |
| - name: Build with Maven | |
| run: mvn clean package -DskipTests | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Build Docker image | |
| run: docker build -t nheinroth27/spring-boot-app-prueba:latest . | |
| - name: Push Docker image | |
| run: docker push nheinroth27/spring-boot-app-prueba:latest | |
| deploy: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Mostrar fingerprint de la clave privada cargada como secreto | |
| run: | | |
| echo "$DROPLET_SSH_KEY" > id_rsa | |
| chmod 600 id_rsa | |
| ssh-keygen -lf id_rsa | |
| env: | |
| DROPLET_SSH_KEY: ${{ secrets.DROPLET_SSH_KEY }} | |
| - name: Probar conexión SSH desde Actions | |
| uses: appleboy/ssh-action@v1.0.0 | |
| with: | |
| host: ${{ secrets.DROPLET_IP }} | |
| username: ${{ secrets.DROPLET_USER }} | |
| key: ${{ secrets.DROPLET_SSH_KEY }} | |
| script: echo "✅ Conexión SSH exitosa desde GitHub Actions" | |
| - name: Deploy en el Droplet | |
| uses: appleboy/ssh-action@v1.0.0 | |
| with: | |
| host: ${{ secrets.DROPLET_IP }} | |
| username: ${{ secrets.DROPLET_USER }} | |
| key: ${{ secrets.DROPLET_SSH_KEY }} | |
| script: | | |
| docker stop spring-prueba || true | |
| docker rm spring-prueba || true | |
| docker pull nheinroth27/spring-boot-app-prueba:latest | |
| docker run -d --name spring-prueba -p 8080:8080 nheinroth27/spring-boot-app-prueba:latest |