CI/CD Pipeline Basics
Continuous Integration (CI) and Continuous Deployment (CD) are practices that automate the building, testing, and deployment of software. They enable teams to deliver code changes frequently and reliably.
The CI/CD Pipeline
CI/CD PIPELINE
==============
Developer Git Repo CI Server Production
| | | |
| 1. Push Code | | |
|------------->| | |
| | 2. Trigger | |
| |-------------->| |
| | | |
| | 3. Build | |
| | (compile, | |
| | install) | |
| | | |
| | 4. Test | |
| | (unit, | |
| | integ.) | |
| | | |
| | 5. Deploy | |
| | (staging) | |
| | | |
| | 6. Approve | |
| | |-------------->|
| | | 7. Deploy |
| | | (prod) |
Continuous Integration
CI PRINCIPLES
=============
1. Commit to mainline frequently
- At least once per day
2. Every commit triggers an automated build
- Compile code
- Run tests
- Check code quality
3. Fix broken builds immediately
- Broken build = top priority
4. Keep the build fast
- Aim for under 10 minutes
Benefits:
+ Catch integration issues early
+ Reduce merge conflicts
+ Always have a working codebase
+ Faster feedback loop
Continuous Deployment
CD PIPELINE STAGES
==================
Build --> Test --> Staging --> Approval --> Production
| | | | |
v v v v v
Compile Run all Deploy to Manual/ Deploy to
& pack tests test env Auto users
Deployment Strategies:
- Blue/Green: Two identical environments, swap traffic
- Canary: Gradually roll out to small user percentage
- Rolling: Update instances one at a time
Popular CI/CD Tools
- GitHub Actions: Integrated with GitHub repos
- GitLab CI/CD: Built into GitLab
- Jenkins: Self-hosted, highly customizable
- CircleCI: Cloud-based, fast builds
- Travis CI: Simple setup for open source
Key Takeaways
- CI automates building and testing on every commit
- CD automates deployment to production
- Pipelines provide visibility into the deployment process
- Start simple and add stages as your team matures