#90DaysOfDevOps Challenge - Day 87 - DevOps Project 8 - Automating React App Deployment on AWS Elastic Beanstalk with GitHub Actions

Cloud Engineer and DevOps enthusiast, just talking about AWS, Docker, Linux, Kubernetes, Python, and automation.
Search for a command to run...

Cloud Engineer and DevOps enthusiast, just talking about AWS, Docker, Linux, Kubernetes, Python, and automation.
No comments yet. Be the first to comment.
The #90DaysOfDevOps Challenge is a dedicated initiative aimed at promoting continuous learning and skill development in the field of DevOps over a 90-day period.
Welcome to Day 86 of the #90DaysOfDevOps Challenge. Today, we have a new project where we'll automate the deployment of a Portfolio app on AWS S3 using GitHub Actions. GitHub Actions will enable us to achieve Continuous Integration and Continuous Dep...
Running your own home lab used to mean expensive hardware, complex networking, and hours of manual configuration. This project changes that. With a single Raspberry Pi, Docker Compose, and a few hundr

Welcome to an advanced hybrid directory demo where we'll guide you through setting up a hybrid environment, connecting to simulated on-premises infrastructure, creating a managed Microsoft AD within AWS, establishing a two-way forest trust, and integ...

Hello DevOps Community! Today marks the completion of the #90DaysOfDevOps Challenge, and it's a moment to reflect on the journey we've undertaken together. Throughout this period, I've engaged with various technologies, refining my skills in the DevO...

In a modern cloud infrastructure setup, creating a robust and scalable 2-tier architecture is essential. Such an architecture helps meet the demands of your applications while ensuring repeatability, reliability, and security. In this article, we'll ...

Welcome to Part 4 of my series on building a comprehensive CI/CD pipeline in AWS. In this article, I will explore AWS CodePipeline, a powerful service for building and deploying applications in a continuous integration and continuous delivery (CI/CD)...

Welcome to Day 87 of the #90DaysOfDevOps Challenge. Today, we have a new project ahead, where we will automate the deployment of a React application on AWS Elastic Beanstalk using GitHub Actions. With the power of GitHub Actions, we can seamlessly integrate continuous integration and continuous deployment (CI/CD) into our GitHub repository, making the deployment process efficient and automated.
In this project, our goal is to deploy a React application on AWS Elastic Beanstalk, a fully managed service that makes it easy to deploy, manage, and scale applications. By leveraging GitHub Actions, we can set up a CI/CD pipeline to automatically build and deploy the React app to Elastic Beanstalk whenever there is a new commit or a pull request in the GitHub repository.
Before we dive into the project, you can read this blog for a better understanding of how the deployment process works with GitHub Actions and AWS Elastic Beanstalk.
Welcome to this hands-on project where we'll walk through automating the deployment of a React app on AWS Elastic Beanstalk using Docker and GitHub Actions. By the end of this project, you'll have a fully functioning deployment pipeline for your React app.
If you are using an Ubuntu machine, Git is likely pre-installed. Clone the repository and navigate to the project directory.
git clone https://github.com/estebanmorenoit/AWS_Elastic_BeanStalk_On_EC2.git

cd AWS_Elastic_BeanStalk_On_EC2

After cloning the code, find the docker_install.sh shell-script, which will install and enable Docker. Make it executable and run the script to install Docker.
chmod +x docker_install.sh
sh docker_install.sh

Our React app requires Node.js to run and NGINX to serve requests after deployment. Let's create a multi-stage Dockerfile to address these requirements.
Dockerfile:
FROM node:14-alpine as builder
WORKDIR /app
COPY package.json .
RUN npm install
COPY . .
RUN npm run build
FROM nginx
EXPOSE 80
COPY --from=builder /app/build /usr/share/nginx/html

With the Dockerfile in place, it's time to build the Docker image.
sudo docker build -t react-app-image .

Launch a Docker container with the built image:
sudo docker run -d -p 80:80 react-app-image
Ensure the container is running using docker ps and confirm the application's activity by accessing the EC2 public IP on port 80.

Go to the AWS Elastic Beanstalk service and click on "Create Application". Provide the required details, including a name for the application, select "Docker" as the platform, and choose "Sample Code" as a starting point.

After clicking "Create Application", wait for the environment to be set up.

To access your deployed app, go to the "Domain" section and follow the URL provided. This link will lead you to your live React app running on AWS Elastic Beanstalk.

We will use GitHub Actions for CI/CD. Locate the "deploy-react.yaml" file and move it under the ".github/workflows" directory. Update the file with relevant parameters such as branch name, application name, environment name, AWS access key, AWS secret access key and region.
name : Deploy react application in BeanStalk
on :
push:
branches:
- "main"
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v2
- name: Generate deployment package
run: zip -r deploy.zip . -x '*.git*'
- name: Deploy to EB
uses: einaregilsson/beanstalk-deploy@v21
with:
aws_access_key: ${{ secrets.AWS_ADMIN_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.AWS_ADMIN_SECRET_ACCESS_KEY_ID }}
application_name: react-app
environment_name: React-app-env-2
version_label: ${{ github.sha }}
region: eu-west-2
deployment_package: deploy.zip
Push all the codes under the "AWS_Elastic_BeanStalk_On_EC2" folder to the "main" branch of your GitHub repository. GitHub Actions will automatically trigger the CI/CD process.

Verify the Elastic Beanstalk link received earlier. The sample application should now be replaced with our React app, which confirms a successful deployment.

Congratulations on completing this hands-on project! Day 87 of the #90DaysOfDevOps Challenge was all about automating the deployment of a React application on AWS Elastic Beanstalk using GitHub Actions. By setting up this CI/CD pipeline, you have streamlined the deployment process, ensuring that your app is always up-to-date and readily available to your users. Tomorrow, we'll dive into another exciting project. Stay tuned!