Deployment configurations and CI/CD pipelines for the Domain Monitoring System.
This repository contains Ansible playbooks and Jenkinsfile for deploying the Domain Monitoring System. It automates the build, test, and deployment process across development and production environments.
domain-monitor-deploy/
├── ansible/
│ ├── ansible.cfg # Ansible configuration
│ ├── inventory_aws_ec2.yaml # Dynamic AWS inventory
│ ├── Jenkinsfile # CI/CD pipeline definition
│ └── playbook.yaml # Main Ansible playbook
├── .gitignore # Git ignore file
└── README.md # This documentation
The Ansible playbook automates the deployment of the Domain Monitoring System to AWS EC2 instances. It's triggered by the Jenkins pipeline and executed from the ansible agent EC2 instance.
Key components:
ansible.cfg
: Configuration for Ansible behaviorinventory_aws_ec2.yaml
: Dynamic inventory to discover AWS instances by tagsplaybook.yaml
: Main deployment tasks
The Jenkinsfile defines a CI/CD pipeline with the following stages:
- Clean Workspace
- Clone Repository
- Build Docker Images
- Start Application Stack
- Service Check
- Selenium Tests
- Push Images to Registry
The CI/CD pipeline integrates automated testing to ensure application quality before deployment. The pipeline uses tests from the domain-monitor-tests repository.
The Jenkinsfile includes a dedicated testing stage:
stage('Selenium Test') {
steps {
script {
sh """
# Start Selenium container with host network
docker run --network host \
-d \
--name selenium-test \
-e APP_URL=http://localhost:8080 \
-e WAIT_TIMEOUT=30 \
-e PYTHONUNBUFFERED=1 \
razielrey/selenium-tests:latest
sleep 10
# Run tests with output
if ! docker exec selenium-test python3 -u run_tests.py; then
echo "Selenium tests failed - collecting debug info"
docker logs selenium-test
docker logs fe-app-${BUILD_TAG}
docker logs be-app-${BUILD_TAG}
exit 1
fi
"""
}
}
}
The pipeline uses a Docker container (razielrey/selenium-tests
) that contains:
- The test framework from the domain-monitor-tests repository
- Chrome browser and WebDriver for UI testing
- Python test dependencies
- Setup: The pipeline starts frontend and backend containers to be tested
- Test Execution: The Selenium container runs against these services
- Verification: The
run_tests.py
script executes the core test suite - Results: A non-zero exit code fails the pipeline and prevents deployment
The automated tests verify:
- User authentication (registration, login)
- Domain management functionality
- Scheduler operations
- Basic UI interactions
Test logs and results are:
- Captured in the Jenkins console output
- Available in the test_logs directory within the container
- Archived as build artifacts in case of failures
If tests fail:
- Debug information is collected from all containers
- The pipeline stops, preventing deployment of potentially faulty code
- Developers receive notifications about the failure
The test container can be configured with environment variables:
APP_URL
: URL of the application to testWAIT_TIMEOUT
: Custom timeout for UI elementsPYTHONUNBUFFERED
: Ensures immediate log output
New tests are integrated by:
- Adding test files to the domain-monitor-tests repository
- Updating the
run_tests.py
script to include new test cases - Building a new version of the Selenium test container
For performance testing:
- The Locust test file (
locustfile.py
) in the test repository can be used - Performance tests are typically run manually or as a separate job
- Results are evaluated to identify performance regressions
- Terraform infrastructure deployed (from domain-monitor-infra)
- AWS EC2 instances running
- Jenkins server configured with proper credentials
This repository is part of an automated CI/CD process:
- Changes pushed to the main repositories trigger the Jenkins pipeline
- Jenkins builds Docker images for frontend and backend
- Images are tested in a staging environment
- Ansible deploys the tested images to production servers
If needed, you can manually trigger the Ansible deployment:
- SSH into the Ansible agent EC2 instance
- Clone this repository
- Run the Ansible playbook:
cd domain-monitor-deploy/ansible ansible-playbook -i inventory_aws_ec2.yaml playbook.yaml
The main playbook (playbook.yaml
) performs the following tasks:
- Sets up common configurations across all hosts
- Configures server roles based on AWS EC2 tags:
- Jenkins server configuration
- Docker agents for building containers
- Production servers for hosting the application
The Jenkins pipeline (Jenkinsfile
) automates:
- Building frontend and backend Docker images
- Running tests to verify functionality
- Deploying tested images to production servers
Key environment variables:
DOCKER_CREDENTIALS_ID
: For Docker Hub authenticationFE_IMAGE
: Frontend image repositoryBE_IMAGE
: Backend image repository
This deployment repository works in conjunction with other repositories:
- Terraform (in domain-monitor-infra) provisions the EC2 instances
- EC2 instances are tagged with specific roles (jenkins, agent, production)
- The Ansible inventory uses these tags to target specific instances
- The deployment pipeline runs on the jenkins instance and uses the agent instance
- Tests are maintained in the domain-monitor-tests repository
- The Selenium test container is built from the test repository code
- Tests are executed as part of the CI/CD pipeline before deployment
- Test results determine whether deployment proceeds
This repository is designed to be cloned and executed by the Ansible agent role defined in the infrastructure repository:
-
The infrastructure repository contains an ansible_agent role at:
domain-monitor-infra/ansible/roles/ansible_agent/
-
When the ansible_agent role runs, it:
- Clones this repository to the agent EC2 instance
- Sets up the necessary credentials and permissions
- Makes the playbook available for execution from the Jenkins pipeline
-
The Jenkins pipeline then triggers the playbook execution on the agent via SSH or the Jenkins Ansible plugin
This connection ensures that the infrastructure setup and application deployment remain synchronized and follow the Infrastructure as Code principles.
- Check that EC2 instances are running
- Verify security groups allow SSH access
- Ensure the inventory file correctly identifies hosts
- Check Jenkins console output for specific error messages
- Verify Docker credentials are correctly configured
- Ensure EC2 instances have sufficient resources
- Review test logs for specific failure details
- Check if the Selenium container can access the application
- Verify that test dependencies are correctly installed
- Fork the repository
- Create a feature branch:
git checkout -b feature/my-feature
- Commit your changes:
git commit -am 'Add my feature'
- Push to the branch:
git push origin feature/my-feature
- Submit a pull request