Restaurant Management Application
Easily deploy your fullstack appilcation in your personal computer or in the Cloud with this sample.
- Table of Contents
- About this Repository
- Examples
- Additional Resources
In this repository, there are 3 applications: Frontend with Nginx
and React
; Backend with NodeJS
and ExpressJS
; Database with MySQL
. Sources & configurations of these applications are stored in corresponding folders, you will know purposes of these files later.
For now, you just have to know that this repository is used to build with AWS First Cloud Journey Workshops.
This repository can be used in some scenarios of deployments, see more details in the Examples section.
All of these examples are built for our use cases. If you want to use in your own use cases, you should to modify the configurations and follow these requirements:
- MySQL Server should have required Database, Tables and data.
- NodeJS Application must be configured with correct environment variables.
- Nginx & React Application will be configured depond on envinronments and strategies.
This scenario is divided into 2 cases:
If you deploy in this case, you have to install MySQL Server (Community) and make sure it is running on your local machine, then install dependencies and libraries to deploy appications.
-
Install these dependencies:
-
Create Database and Tables with MySQL Shell.
-
Modify the environment variables in
.env
inbackend
directory. -
Modify the congifuration in
vite.config.js
file to use proxy feature of Vite infrontend
directory.
For more details, you can follow these steps.
Note
In this case, we don't have to use Nginx with React, because React is running with its development server which is provided by Vite.
If you deploy in this case, you have to enable WSL2 and install Ubuntu Distro on you Windows Machine, then install Docker.
-
Install these dependencies:
- Enable WSL2 and install Ubuntu 24.04.1 LTS Distro: follow these steps.
- Install Docker Desktop (GUI with Docker Engine): here.
-
Run this command to let docker builds images, and run containers.
cd aws-fcj-container-app
docker compose -f docker-compose.yml up
- Type
http://localhost:3000
to search bar in your browser and hit enter to see the result.
Note
Docker will pull MySQL Server Image and automatically create required database, tables and insert example data. Then it will build Docker Image for Frontend and Backend application with
frontend/Dockerfile
andbackend/Dockerfile
.React Application will be built an antifacts and will be served by Nginx.
Before you do these examples, you have to make sure that:
- You must have an AWS account.
- You have a Docker account (Optional).
- You must have a base knowledge about Cloud, such as EC2, RDS, Networking on Cloud, ECS, ...
- Deploy a Network Infrastructure and configure some services for these example, you can view more details here.
- Deploy a RDS Instance, you can view more details here.
- Configure and Launch an EC2 to install required dependencies like Docker, MySQL Client, ..., you can view more details here.
And this scenario is divided into 3 cases, let's start!
-
Make sure that Docker Engine, Docker Daemon, Docker CLI, Git, ... are installed on EC2.
-
Clone this repository in your EC2 instance.
-
Change directory to
frontend
and build Frontend Image (Nginx and React). -
Change directory to
backend
, modifyDB_HOST
variable with the public DNS of RDS Instance in.env
file, then build Backend Image (NodeJS and ExpressJS). -
Create a Docker Network to use to add Frontend and Backend Container into a Network.
-
Run Containers with these Images and view result with EC2's public DNS Hostname.
For more details, you can follow these steps.
-
Make sure all dependencies and the source code are installed and RDS Instance is running.
-
Change directory to
docker-compose-env
, and modifyDB_HOST
variable with the public DNS of RDS Instance. In this example, we will use docker compose withdocker-compose.app.yml
, because Database Container is managed by Amazon RDS, so we don't have to install Database Server with Docker Compose. -
Run this command to deploy application
sudo docker compose -f docker-compose.app.yml up
- Go to
http://ec2-public-dns:3000
to view the result.
For more details, you can follow these steps.
Now, we will use ECS to deploy our application instead of EC2. Before you go to further, make sure that:
- RDS Instance is still running.
- Update Infrastructure. For more details, view here.
- Create ECR or Docker Hub Repository, build and upload images to ECR / Docker Hub. For more details, view here. Note that, with frontend image, you have to build with
frontend/Dockerfile.prod
file.
That's all requirements. Our containers will be managed directly by ECS Services with Task Definitions, and all of them are deployed in ECS Cluster. Let's start!
- For internal DNS, you have to register a namespace in Amazon Cloud Map and create a Service name for Backend.
- Create an ECS Cluster for our application.
- Create 2 Task Definitions for Frontend and Backend Container with their images.
- Create and configure Application Load Balancer to let users reach Containers inside ECS Cluster. In the previous guide, we deploy our application on a Public Subnet, so in this part, we must to deploy our ECS Cluster on a Private Subnet. With Frontend Task, you have to assign
BACKEND_HOST
andBACKEND_PORT
to let Docker uses thedefault.template.conf
to build suitable Nginx Configuration before Nginx starts. - Create 2 ECS Services for Frontend and Backend. With Backend Service, you have to enable Service Discovery and assign Namespace and Service that we configured in
step 1
. - View the result with
http://alb-public-dns
. At this time, we have to request toPort 80
for the right access to our application.
For more details, you can follow these steps (from Section 4 to 8).
Before you perform this use case, make sure that:
- You have a GitHub / GitLab account, and you can choose one of them.
- You have a fundamental knowledge about CI/CD, for more details, go to Additional Resources section.
- Fork or Clone and Create 3 new Repositories with this repository in your GitHub / GitLab account.
In this scenario, we will implement CI/CD with GitLab and EC2; with GitHub Actions; with Github and CodeBuild. That's all requirements, let's start!
We will register a EC2 Instance as a Runner. And this EC2 Instance will be attached a IAM Role with suitable permissions. For more details, you can follow these steps.
We will need an AWS Account with suitable permissions to to this part. For more details, you can follow these steps.
We will need to setup 2 CodeBuild Projects for Frontend and Backend, then use Github Actions to trigger CodeBuild to deploy application. For more details, you can follow these steps.
Note
With these use cases, we have to have a runner which is perform the instruction from YAML files. These files are configured in
.github/workflows
in GitHub repository or.gitlab-ci.yml
for GitLab repository. And we have to add environment variables (serects) for both of GitLab and GitHub repository to run Pipeline properly.
- Read more about Docker: https://www.docker.com/
- Read more about ECS: Amazon ECS
- Read more about CI/CD:
- With GitLab: What is CI/CD?
- With GitHub: CI/CD: The what, why, and how