Welcome to the second project status meeting! In this session, we’ll investigate how our CI/CD pipeline inadvertently hit the production database and refactor it to use a dedicated test instance.Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
The Issue: Tests Pointing at Production
After wrapping up the first three tasks, Alice was pulled into an urgent meeting. Monitoring alerts revealed that the production MongoDB cluster had become sluggish and occasionally unresponsive—right after the team enabled GitLab CI/CD pipelines. Reviewing the pipeline, Alice saw two test jobs both connecting directly to the production database via environment variables:Never run CI tests against your production database. This can lead to performance degradation, data corruption, and security risks.
Why Use a Dedicated Test Database?
Running tests against production can:- Introduce load and latency for real users.
- Accidentally modify or delete critical data.
- Complicate debugging because of shared state.
Using GitLab CI Services
GitLab CI/CD supports services—auxiliary containers that start alongside your job. You can:- Launch a database container (e.g.,
mongo:4.4) - Seed it with test data in
before_script - Point your application to
localhostor the service alias
Services are defined per-job. Each service runs in its own Docker container, linked to the job container.
Refactored Pipeline Configuration
Below is a revised.gitlab-ci.yml that replaces the production connection with a local MongoDB service:
Job Configuration Comparison
| Job | Original DB | Refactored with Services |
|---|---|---|
| unit_testing | Production MongoDB cluster | Local mongo:4.4 service |
| code_coverage | Production MongoDB cluster | Local mongo:4.4 service |