š Repository Structure
The project follows a modular structure to separate the frontend, backend, and configuration files:
MEAN-CRUD-APP/
āāā backend/
ā āāā Dockerfile
ā āāā (backend code)
āāā frontend/
ā āāā Dockerfile
ā āāā (frontend code)
āāā docker-compose.yml # Local development
āāā docker-compose.server.yml # Server/AWS deployment
āāā Jenkinsfile.docker-push # CI: Build and push images to DockerHub
āāā Jenkinsfile.deploy-app # CD: Deploy application on server
āāā nginx-default.conf # Nginx reverse proxy config file
āāā README.md
āļø Steps for Deployment on the AWS Server
Here is the step-by-step process for setting up the automated deployment environment:
1. Provision EC2 Instance
-
Launch an EC2 instance (e.g., in the default VPC).
-
Crucial Step: Configure the security group to allow inbound traffic on the following ports:
-
22(SSH) -
80(HTTP) -
443(HTTPS) -
8080(Backend Service) -
8081(Application Access) -
9090(Jenkins)
-
2. Install Required Software
-
Install Jenkins, Docker, and Docker Compose on the EC2 server.
-
Verify that Jenkins is accessible on port
9090.
3. Configure Jenkins
-
Install necessary plugins in Jenkins.
-
Configure GitHub credentials and Docker Hub credentials.
-
Set up GitHub webhook integration to trigger pipelines automatically upon code changes.
4. Set Up Docker and Docker Compose
- Prepare the server environment to use Docker and Docker Compose for managing the application's containers: Frontend, Backend, and MongoDB.
5. MongoDB with Persistent Storage
-
Run the MongoDB database within a Docker container.
-
Utilize a persistent volume to ensure that application data is never lost during container updates or redeployment.
6. Implement CI Pipeline (Jenkinsfile.docker-push)
-
The CI pipeline is responsible for detection and build:
-
Detects changes pushed to the GitHub repository (frontend or backend).
-
Builds the respective container image (frontend or backend).
-
Pushes the new image to Docker Hub.
-
Removes the local image to conserve server space.
-
7. Implement CD Pipeline (Jenkinsfile.deploy-app)
-
The CD pipeline handles the deployment:
-
Monitors Docker Hub for new image pushes.
-
Pulls the newly pushed image.
-
Removes any existing running containers.
-
Deploys the updated version automatically using
docker-compose.server.yml.
-
8. Configure Nginx for Reverse Proxy
-
Use the
nginx-default.conffile to configure Nginx as a reverse proxy. -
This setup allows the final application to be accessible directly via the server's IP on ports 80 (HTTP) and 443 (HTTPS), hiding the application's internal ports.
9. Access the Application
-
The final application is accessible via the EC2 public IP or domain name on ports 80/443.
-
Jenkins remains accessible on port
9090for CI/CD management.
š» Local Testing Steps (Quick Start)
Before deploying to the server, you can quickly test the containerized setup locally:
1. Clone the Repository
Bash
git clone <https://github.com/iabhishekpratap/mean-crud-app>
cd mean-crud-app
2. Build and Start the Application
Use docker-compose.yml (for local development) to build and start all services in detached mode:
Bash
docker-compose up --build -d
3. Verify Container Status
Check if the frontend, backend, and MongoDB containers are running:
Bash
docker-compose ps
4. Access the Application
Open your web browser and navigate to:
http://localhost:8081
5. Test Functionality
Verify the basic CRUD (Create, Read, Update, Delete) operations through the application's UI.
Cleanup
To stop and remove all containers, networks, and persistent volumes:
Bash
docker-compose down -v
š ļø Support
For any issues or further documentation, refer to:
-
Docker and Docker Compose documentation
-
Jenkins documentation
-
MongoDB documentation