Giter VIP home page Giter VIP logo

fargate-web-app's Introduction

Fargate Web App with RDS MySQL

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.

Architecture Diagram

alt text

Table of Contents

Project Structure

.
├── 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
│   └── ...

Folders and Important Files

  • 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.

Local Setup Guide

Prerequisites

  • Docker
  • Docker Compose

Steps

  1. Clone the repository:

    git clone https://github.com/lkravi/fargate-web-app.git
    cd fargate-web-app
  2. Ensure MySQL is not running locally (to avoid port conflicts):

    sudo systemctl stop mysql
  3. Build and run the containers:

    docker-compose up --build
  4. Access the application:

    • Frontend: http://localhost:8080
    • Backend: http://localhost:5001

Seed Data and Database Initialization

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.

Building the AWS Fargate Environment with Terraform

Prerequisites

  • AWS CLI configured with appropriate credentials.
  • Terraform installed.

Steps

  1. Navigate to the terraform directory:

    cd terraform
  2. Initialize Terraform:

    terraform init
  3. 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
  4. Apply the Terraform configuration:

    terraform apply
  5. 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.

Demo

Watch the video

License

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.

fargate-web-app's People

Contributors

lkravi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.