Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Java CI + Docker Publish Pipeline
name: Java CI + Docker Publish Pipeline + Deploy to VPS

on:
push:
Expand Down Expand Up @@ -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
Expand All @@ -50,4 +51,23 @@ jobs:

- name: Push Docker image
run: |
docker push ghcr.io/vimal-java-dev/vimaltech-contact-api:latest
docker push ghcr.io/vimal-java-dev/vimaltech-contact-api:latest
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good for auto-deploy to VPS

✅ 3. Proper Dependency Chain

deploy → needs: docker
docker → needs: build

Because,
👉 Guarantees:

  • No deploy if build fails
  • No deploy if image push fails


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
Loading