Git & GitHub Course
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?

Flash Cards

Question

Why use secrets?

Click to reveal answer
Answer

Because the GitHub Action runner needs passwords, SSH keys, or API tokens to log into your production servers (like AWS or Azure). You can't hardcode these in the YAML file.

Question

Fails halfway?

Click to reveal answer
Answer

A good CD pipeline uses 'Blue/Green deployments' or 'Rollbacks'. If the deployment fails, the load balancer keeps pointing users to the old, working version of the server, and alerts the engineering team.