Git & GitHub
/Advanced
Automated Deployments
Definition
The final stage of CI/CD where code that has passed all automated tests is programmatically pushed to production environments without human intervention.
Explain Like I'm New
Writing a GitHub Action that logs into your DigitalOcean server via SSH, pulls the latest code, restarts the Docker containers, and updates the database, all automatically when code is merged to `main`.
Real World Example
A DevOps engineer setting up a pipeline that builds a Docker image, pushes it to AWS Elastic Container Registry, and updates the Kubernetes cluster.
Common Use Cases
- •Enterprise deployment pipelines
- •Containerized applications (Docker)
Terminal Output
bash / terminal
# .github/workflows/deploy-vps.yml
name: Deploy to Production Server
on:
push:
branches: [ main ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: SSH and Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_IP }}
username: root
key: ${{ secrets.SERVER_SSH_KEY }}
script: |
cd /var/www/my-app
git pull origin main
npm install
npm run build
pm2 restart my-app
Interview Questions
basic
- Why do we use GitHub Secrets for Automated Deployments?
intermediate
- What happens if the automated deployment script fails halfway through?