Module 6 Lesson 2: Staging vs Production
·DevOps

Module 6 Lesson 2: Staging vs Production

The safety net. Learn how to manage multi-tier environments in GitLab to ensure that code is tested in a 'Real' world scenario before it hits your paying customers.

Module 6 Lesson 2: Staging vs Production

In a professional environment, you never deploy directly to the live site. You use a "Multi-Tier" system of environments.

1. The Standard Tier

  1. Development: Your own laptop.
  2. QA (Quality Assurance): Where testers manually click around.
  3. Staging: A PERFECT CLONE of production. (Same database size, same server specs).
  4. Production: The real site where users are.

2. Defining Environments in GitLab

deploy_staging:
  stage: deploy
  environment:
    name: staging
  script:
    - echo "Deploying to STAGING server..."
  rules:
    - if: $CI_COMMIT_BRANCH == "develop"

deploy_prod:
  stage: deploy
  environment:
    name: production
  script:
    - echo "Deploying to PRODUCTION server..."
  rules:
    - if: $CI_COMMIT_BRANCH == "main"
      when: manual

3. Why is Staging Important?

  • The "Full" test: Some bugs only happen when there are 10,000 rows in the database. Staging helps you find these without crashing the live site.
  • Stakeholder Review: Your boss can approve the site in Staging before you "Flip the switch" to Production.

4. Environment-Specific Variables

Remember Module 3? You can scope a variable so it only exists in the "Production" environment.

  • Example: The STRIPE_KEY for Staging is for "Testing Credits." The STRIPE_KEY for Production is for "Real Money." Scoping prevents you from accidentally charging real customers from your Staging environment.

Exercise: The Environmental Audit

  1. Go to your GitLab project -> Operate -> Environments.
  2. Do you see any environments listed?
  3. Add a staging environment to your current pipeline.
  4. If a bug is found in "Staging," should the developer fix it there, or go back to "Development"? (Why?)
  5. Research: What is an "Ephemeral Environment" (or Review app)? How does it differ from a static Staging server?

Summary

Environments are the "Levels" of your game. By partitioning your infrastructure into Staging and Production, you create a safe space for experimentation and a "Sanitized" vault for your users' real data.

Next Lesson: High-availability tactics: Blue-Green vs Canary Releases.

Subscribe to our newsletter

Get the latest posts delivered right to your inbox.

Subscribe on LinkedIn