This project demonstrates a modernized CI/CD pipeline using Jenkins, Docker, and Node.js.
Stack:
- Runtime: Node.js 20 (Alpine)
- Database: MongoDB 6.0
- Testing: Mocha, Chai, Supertest
- Infrastructure: Docker Compose, Jenkins Pipeline
- Docker Desktop (or Engine) installed.
- Node.js (v18+ recommended for local dev, though app runs in Docker).
- Jenkins (can be run locally or via container).
Runs the application stack (App + MongoDB) locally using Docker Compose. A reliable run.sh script is provided.
# Start the environment and seed the database
./run.shThis will:
- Build the Node.js image.
- Start MongoDB (v6.0) and the Node app.
- Execute the seed script (
seeds/seed.js) to populate the database.
Access the app at: http://localhost:3000
If you prefer running commands manually:
# Start services
docker-compose up -d --build
# Run tests
npm testEnsure Jenkins is installed and running. If you are on Ubuntu, you can use the provided setup.sh to install Docker if it's not present.
Install the following plugins via Manage Jenkins > Plugins:
- Docker Pipeline
- Docker
- Pipeline
- Git
- NodeJS (optional if running builds inside Docker agents)
- Go to
Manage Jenkins > Credentials. - Add a new credential of type Username with password.
- ID:
dockerhub(matches theJenkinsfile). - Enter your Docker Hub username and password.
The Jenkinsfile defines the pipeline stages:
- Cloning Git: Pulls code from the repository.
- Building Docker Image: Builds the image tagged with the Jenkins
BUILD_NUMBER. - Deploying: Pushes the image to your configured registry (default:
naistangz/docker_automation). - Cleanup: Removes local artifacts to save space.
Edit the environment block in Jenkinsfile to match your updates:
environment {
registry = "your-dockerhub-username/repo-name"
registryCredential = "dockerhub"
}If Jenkins cannot access the Docker socket:
sudo usermod -aG docker jenkins
sudo systemctl restart jenkinsEnsure the container name in docker-compose.yml matches DB_HOST.
- Correct:
mongodb://mongo:27017/posts - Why: Docker Compose uses service names as hostnames.