Coder Social home page Coder Social logo

deploying-react-app-aws's Introduction

Deploying React App on AWS EC2 with Dockerization

React Docker Terraform GitHub Actions AWS

Overview

CI/CD Pipeline

This repository contains all the necessary files and configurations to deploy a React application on an AWS EC2 instance using Docker. The deployment process is automated using Terraform for infrastructure provisioning and GitHub Actions for continuous integration and deployment (CI/CD).

Features

  • React Application: Deploy a React app built with the latest industry standards.
  • Dockerization: Containerize the React application for consistent and scalable deployment.
  • AWS EC2: Launch an EC2 instance to host the Docker container.
  • Terraform: Use Terraform to manage and provision AWS infrastructure.
  • GitHub Actions: Automate the deployment process using GitHub Actions for CI/CD.

Prerequisites

  • Docker installed on your local machine.
  • Terraform installed on your local machine.
  • AWS account with sufficient permissions to create and manage EC2 instances.
  • GitHub account for accessing the repository and configuring GitHub Actions.

Getting Started

Clone the Repository

First, clone the repository to your local machine:

git clone https://github.com/adil6572/deploying-react-app-aws.git
cd deploying-react-app-aws

Configure AWS Credentials

Ensure your AWS credentials are configured properly. You can use the AWS CLI to configure your credentials:

aws configure

Build and Push Docker Image

  1. Login to Docker Hub: Make sure you are logged into your Docker Hub account.

    docker login
  2. Build the Docker Image: Build the Docker image for your React application.

    docker build -t your-docker-username/your-image-name:latest .
  3. Push the Docker Image: Push the Docker image to Docker Hub.

    docker push your-docker-username/your-image-name:latest

Initialize Terraform

Navigate to the terraform directory, initialize the Terraform working directory, and download necessary providers:

cd terraform
terraform init

Plan and Apply Terraform Configuration

Review the Terraform plan and apply the configuration to provision the AWS resources:

terraform plan
terraform apply --auto-approve

GitHub Actions CI/CD

The repository includes a GitHub Actions workflow for automating the Docker build, push, and Terraform deployment. To enable this, ensure the following secrets are configured in your GitHub repository:

  • AWS_ACCESS_KEY
  • AWS_SECRET_ACCESS_KEY
  • DOCKER_USERNAME
  • DOCKER_PASSWORD

The workflow file is located at .github/workflows/deploy.yml.

Update Workflow and Terraform Files

Make sure to update the Docker image name in both the GitHub Actions workflow and the Terraform configuration files to match your Docker Hub repository:

  • In the workflow file .github/workflows/react-deploy.yml, update the image name in the Docker build and push steps:

    - name: Build and push Docker image
      run: |
        docker build -t your-docker-username/your-image-name:latest .
        docker push your-docker-username/your-image-name:latest
  • In your Terraform files, update the image name wherever the Docker image is referenced terraform/main.tf:

    user_data = <<-EOF
              #!/bin/bash
              sudo apt-get update -y
              sudo apt-get install -y docker.io
              sudo systemctl start docker
              sudo systemctl enable docker
              sudo docker pull your-docker-username/your-image-name:latest
              sudo docker run -d -p 80:80 your-docker-username/your-image-name:latest
              EOF
    

Replace your-docker-username/your-image-name with your actual Docker Hub username and the name of your Docker image.

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any changes or improvements.

License

This project is licensed under the MIT License. See the LICENSE file for details.

deploying-react-app-aws's People

Contributors

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