
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
- Development: Your own laptop.
- QA (Quality Assurance): Where testers manually click around.
- Staging: A PERFECT CLONE of production. (Same database size, same server specs).
- 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_KEYfor Staging is for "Testing Credits." TheSTRIPE_KEYfor Production is for "Real Money." Scoping prevents you from accidentally charging real customers from your Staging environment.
Exercise: The Environmental Audit
- Go to your GitLab project -> Operate -> Environments.
- Do you see any environments listed?
- Add a
stagingenvironment to your current pipeline. - If a bug is found in "Staging," should the developer fix it there, or go back to "Development"? (Why?)
- 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.