From 313d8b553d7288193521e53882a60f71c2049ed1 Mon Sep 17 00:00:00 2001 From: vimal-tech-dev Date: Sun, 5 Apr 2026 06:27:40 +0530 Subject: [PATCH] Fix CI/CD pipeline with deploy job Signed-off-by: vimal-tech-dev --- .github/workflows/ci.yml | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3358615..be42599 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: Java CI + Docker Publish Pipeline +name: Java CI + Docker Publish Pipeline + Deploy to VPS on: push: @@ -35,7 +35,8 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - name: Checkout source code + uses: actions/checkout@v4 - name: Log in to GHCR uses: docker/login-action@v3 @@ -50,4 +51,23 @@ jobs: - name: Push Docker image run: | - docker push ghcr.io/vimal-java-dev/vimaltech-contact-api:latest \ No newline at end of file + docker push ghcr.io/vimal-java-dev/vimaltech-contact-api:latest + + deploy: + # ✅ CRITICAL CONDITION (owner repo only) + if: github.event_name == 'push' && github.repository == 'vimal-java-dev/vimaltech-contact-api' + needs: docker + runs-on: ubuntu-latest + + steps: + - name: Deploy to VPS via SSH + uses: appleboy/ssh-action@v1.0.3 + with: + host: ${{ secrets.VPS_HOST }} + username: ${{ secrets.VPS_USER }} + key: ${{ secrets.VPS_SSH_KEY }} + script: | + cd ~/deployments/contact-api + docker pull ghcr.io/vimal-java-dev/vimaltech-contact-api:latest + docker compose up -d + docker image prune -f \ No newline at end of file