This repository contains a multi-containerized React application deployed using AWS Elastic Beanstalk. The application uses Docker for containerization of multiple services and TravisCI for CI/CD automation. The project features various services like Nginx, React Client, Node Server, and a Worker Service. The infrastructure utilizes AWS services such as RDS and ElastiCache for database and caching.
- Project Overview
- Technologies Used
- File Structure
- Setup Instructions
- AWS Elastic Beanstalk Deployment
- Security and Networking
- CI/CD Integration
- Resources and Documentation
- Contributing
This project demonstrates how to deploy a full-stack application in a multi-container environment using Docker and AWS Elastic Beanstalk. It integrates several services running in different containers, managed via a docker-compose
configuration. This setup allows easy scalability and modular management of the application’s client, server, and worker processes.
- Multi-container deployment using Docker and AWS Elastic Beanstalk.
- Integrated RDS and ElastiCache for handling data persistence and caching.
- Configurable environment variables for production deployments.
- Secure deployment using IAM roles and Security Groups.
- Automatic deployment using TravisCI.
- React (Frontend)
- Node.js/Express (Backend API)
- Redis (ElastiCache for caching)
- PostgreSQL (RDS for database)
- Nginx (Load balancing and reverse proxy)
- AWS Elastic Beanstalk (Deployment environment)
- TravisCI (CI/CD pipeline)
.
├── client # React frontend application
├── nginx # Nginx configuration for load balancing
├── server # Node.js backend API
├── worker # Worker service for background tasks
├── .travis.yml # Travis CI configuration file
├── Dockerrun.aws.json # AWS Elastic Beanstalk configuration file
├── docker-compose.yml # Docker Compose configuration for production
├── docker-compose-dev.yml # Docker Compose configuration for development
└── package.json # Dependencies and scripts for client and server
- Docker: Ensure Docker is installed on your machine.
- AWS Elastic Beanstalk CLI: Install AWS Elastic Beanstalk CLI to interact with your AWS environments.
- AWS Account: An active AWS account to deploy the application.
- Clone the repository:
git clone https://github.com/firatbezir/multicontainer-docker.git
cd multicontainer-docker
- Start the services locally using Docker Compose:
docker-compose -f docker-compose-dev.yml up --build
- The application will be accessible at http://localhost:3000.
Define environment variables required for the app in your .env
file:
POSTGRES_USER=your_username
POSTGRES_PASSWORD=your_password
REDIS_HOST=redis
-
Create Elastic Beanstalk Environment: Navigate to the AWS Elastic Beanstalk console and create a new environment for a Docker-based application.
-
Add Container Definitions: Edit the
Dockerrun.aws.json
file to define the containers and their memory allocations:
{
"AWSEBDockerrunVersion": 2,
"containerDefinitions": [
{
"name": "client",
"image": "firatbezir/multi-client",
"hostname":"client",
"essential":false,
"memory": 128
},
{
"name": "server",
"image": "firatbezir/multi-server",
"hostname":"api",
"essential":false,
"memory": 128
},
{
"name": "worker",
"image": "firatbezir/multi-worker",
"hostname":"worker",
"essential":false,
"memory": 128
},
{
"name": "nginx",
"image": "firatbezir/multi-nginx",
"hostname":"nginx",
"essential":true,
"portMappings": [
{
"hostPort": 80,
"containerPort": 80
}
],
"links": ["client", "server"],
"memory": 128
}
]
}
-
Database & Caching Setup: Create an RDS PostgreSQL database and an ElastiCache Redis instance from the AWS Management Console.
-
Security Group Configuration: Ensure that the security groups for your RDS and ElastiCache instances allow connections from your Elastic Beanstalk instance.
-
Deploy via TravisCI: Push your changes to the master branch, and TravisCI will automatically trigger the deployment based on the
.travis.yml
configuration.
- VPC and Security Groups: Set up a VPC with appropriate subnets and security groups. Restrict access to the RDS and ElastiCache instances based on IP ranges.
- IAM Roles: Use IAM roles to control access permissions for different AWS resources.
The project is integrated with TravisCI for continuous deployment. You’ll need to configure your AWS credentials in the TravisCI dashboard to automate deployments.
- Add your AWS IAM Keys to TravisCI:
travis encrypt AWS_ACCESS_KEY_ID=your_access_key --add
travis encrypt AWS_SECRET_ACCESS_KEY=your_secret_key --add
- Configure the
.travis.yml
file to handle deployments:
deploy:
provider: elasticbeanstalk
region: "us-west-2"
app: "your-app-name"
env: "your-env-name"
Feel free to fork this repository and submit pull requests. Contributions are welcome!