This repository contains the code and configuration for a web application running on AWS Fargate with a MySQL database hosted on AWS RDS. The repository is structured to facilitate local development using Docker Compose and deployment to AWS using Terraform.
- Project Structure
- Local Setup Guide
- Building the AWS Fargate Environment with Terraform
- Important Files
- License
.
├── LICENSE
├── backend
│ ├── Dockerfile
│ ├── app.py
│ ├── requirements.txt
│ └── ...
├── docker-compose.yml
├── frontend
│ ├── Dockerfile
│ ├── src
│ └── ...
├── init.sql
├── terraform
│ ├── main.tf
│ ├── variables.tf
│ ├── outputs.tf
│ └── ...
├── tests
│ ├── Dockerfile.test
│ ├── requirements.txt
│ ├── test_app.py
│ └── ...
-
backend/: Contains the Flask backend application, its Dockerfile, and dependencies.
app.py
: The main application file for the Flask backend.requirements.txt
: Python dependencies for the backend application.Dockerfile
: Dockerfile to containerize the backend application.
-
frontend/: Contains the frontend application and its Dockerfile.
src
: Source code of the Vue.js application.vue.config.js
: Configuration file for Vue CLI.Dockerfile
: Dockerfile for the Vue.js application.
-
init.sql: SQL script to initialize the MySQL database with the required schema and seed data.
-
terraform/: Contains Terraform configuration files for deploying the application to AWS Fargate.
main.tf
: Main Terraform configuration file.variables.tf
: Defines input variables for Terraform.outputs.tf
: Defines outputs from the Terraform configuration.
-
docker-compose.yml: Docker Compose file to set up the local development environment.
-
tests/: Contains the test setup for the application.
Dockerfile.test
: Dockerfile for the test environment.requirements.txt
: Python dependencies for the tests.test_app.py
: Test script to validate the frontend and backend functionality.
- Docker
- Docker Compose
-
Clone the repository:
git clone https://github.com/lkravi/fargate-web-app.git cd fargate-web-app
-
Ensure MySQL is not running locally (to avoid port conflicts):
sudo systemctl stop mysql
-
Build and run the containers:
docker-compose up --build
-
Access the application:
- Frontend:
http://localhost:8080
- Backend:
http://localhost:5001
- Frontend:
The MySQL container will automatically run the init.sql
script located in the root directory, initializing the database with the required schema and seed data.
- AWS CLI configured with appropriate credentials.
- Terraform installed.
-
Navigate to the terraform directory:
cd terraform
-
Initialize Terraform:
terraform init
-
Create a
terraform.tfvars
file:cat <<EOF > terraform.tfvars region = "us-east-1" vpc_cidr = "10.0.0.0/16" public_subnets = ["10.0.1.0/24"] private_subnets = ["10.0.2.0/24"] db_user = "tf_rds_user1" db_password = "your_password" db_master_user = "master_user" db_master_password = "master_password" EOF
-
Apply the Terraform configuration:
terraform apply
-
Verify the deployment:
- After the Terraform apply completes, check the AWS Management Console to verify the resources have been created.
- Access the application via the ALB DNS name provided in the Terraform outputs.
This project is licensed under the GNU GENERAL PUBLIC LICENSE. See the LICENSE file for details.
By following this guide, you should be able to set up the application locally for development and deploy it to AWS using Terraform. The provided configurations and scripts aim to streamline both local development and cloud deployment processes.