1+ # .github/workflows/deploy.yml
12name : Deploy to Staging VM
23
34on :
5+ # This section defines when the workflow will run.
46 push :
57 branches :
6- - staging
8+ - staging # Trigger on every push to the "staging" branch.
79
810jobs :
911 deploy :
12+ # The job will run on a fresh virtual machine provided by GitHub.
1013 runs-on : ubuntu-latest
1114 steps :
15+ # This is the main step that does the work.
1216 - name : Deploy over SSH
17+ # It uses a pre-made Action from the community to simplify SSH.
1318 uses : appleboy/ssh-action@master
1419 with :
20+ # These values are securely pulled from your GitHub Secrets.
1521 host : ${{ secrets.VM_HOST }}
1622 username : ${{ secrets.VM_USER }}
1723 key : ${{ secrets.VM_SSH_PRIVATE_KEY }}
18- port : 22
19- script : |
20- echo "🔐 Reinjecting public key..."
21- mkdir -p ~/.ssh
22- echo "${{ secrets.VM_SSH_PUBLIC_KEY }}" >> ~/.ssh/authorized_keys
23- chmod 700 ~/.ssh
24- chmod 600 ~/.ssh/authorized_keys
2524
26- echo "🚀 Starting deployment..."
25+ # This is the script that the Action will run on your VM.
26+ script : |
27+ # Change to your project's directory on the VM.
2728 cd ~/sentient
29+
30+ # Pull the latest changes from the staging branch on GitHub.
2831 git pull origin staging
2932
33+ # Navigate into the server directory where your docker-compose file is.
3034 cd src/server
35+
36+ # Stop and remove the old containers.
3137 docker-compose down
38+
39+ # Build new images if the Dockerfile has changed, and start the new containers in the background.
3240 docker-compose up --build -d
3341
34- echo "🧹 Cleaning up old images..."
42+ # Optional: This cleans up any old, unused Docker images to save disk space.
3543 docker image prune -af
0 commit comments