Module 6 Lesson 1: Introduction to Automated Deployment
·DevOps

Module 6 Lesson 1: Introduction to Automated Deployment

Cross the finish line. Learn the fundamentals of push-button and fully automated deployments to servers, clouds, and clusters.

Module 6 Lesson 1: Automated Deployment

Deployment is the final "D" in CI/CD. It is the moment when your code leaves the "Safe" environment of the Runner and enters the "Wild" world of the Internet.

1. What is Automated Deployment?

Instead of a developer using an FTP client to "Upload" files, the GitLab Runner uses a script to:

  1. Log in to the server (via SSH or API).
  2. Stop the old version of the app.
  3. Pull the new Docker image or copy the new files.
  4. Start the new version.
  5. Check if it's healthy.

2. Using SSH in GitLab CI

To deploy to a standard Linux server, you need to "Trust" the runner.

deploy-job:
  stage: deploy
  before_script:
    # Setup the SSH key from a variable
    - eval $(ssh-agent -s)
    - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
  script:
    - ssh user@server.com "cd /app && docker-compose up -d --pull"

3. Deployment "Triggers"

You don't always want to deploy on every commit.

  • Auto-Deploy to Staging: Every time code is merged to main.
  • Manual-Deploy to Production: Only when a senior engineer clicks the "Play" button in GitLab (Review Module 3, Lesson 5).

4. Why Automate?

  1. Repeatability: The deployment script is exactly the same every time.
  2. Safety: The script can automatically "Stop" if a pre-deployment check fails.
  3. Speed: You can deploy to 100 servers in parallel in the same time it takes to deploy to one.

Exercise: The SSH Handshake

  1. Research: Why should you NEVER put your SSH Private Key in the .gitlab-ci.yml file? (Review Module 3, Lesson 2).
  2. Imagine you have 10 servers. How would you modify the SSH script to loop through them?
  3. What is a "Bastion Host" (or Jumpbox), and why might your runner need to use one?
  4. Write a simple deploy job in YAML that only prints "Simulated Deployment to Server X" and is restricted to the main branch.

Summary

Automated deployment turns your "Launch Day" into "Just another Tuesday." By removing the manual stress of uploading files and restarting servers, you ensure that your code reaches your users as fast as possible with zero human error.

Next Lesson: Proving the code: Environments: Staging vs Production.

Subscribe to our newsletter

Get the latest posts delivered right to your inbox.

Subscribe on LinkedIn