CI/CD Pipeline for NGINX on Docker — Phase 5: Automated Deployments with Jenkins
by Frank Doka
CI/CD Pipeline for NGINX on Docker — Phase 5: Automated Deployments with Jenkins
Phase 5 ties the entire stack together: one Git push triggers infrastructure provisioning, server configuration, container deployment, and a smoke test — fully automated.
Jenkins Pipeline Stages
- Checkout — Pull the latest code from the Git repository.
- Terraform Apply — Provision or update the EC2 infrastructure. If the instance already exists and nothing changed, Terraform skips it.
- Ansible Playbook — Using the Ansible plugin, Jenkins runs the configuration playbook. Dynamic inventory discovers the current EC2 instance, SSHs in, and ensures Docker is installed and the latest container image is running.
- Smoke Test — A basic HTTP check against the deployed instance confirms NGINX is responding with a 200 status code.
If any stage fails, the pipeline stops and the build is marked red.
How It Works
Jenkins runs locally and watches the Git repository. On each push to main, it triggers the pipeline automatically. No manual SSH, no clicking through consoles, no remembering which commands to run in which order.
Project Takeaways
Building this pipeline taught me how four independent tools — Docker, Terraform, Ansible, and Jenkins — compose into a single automated delivery system. Each tool owns exactly one responsibility, and Jenkins orchestrates the handoffs. The result: push code, get a verified deployment.