Code Monkey home page Code Monkey logo

pizzas-devops's Introduction

RAMPUP 2 - Pizzas

How is this made

Status

  • BACK

RampUp

  • FRONT

RampUp

The app

  • Frontend: ReactJS app

  • Backend: Monolithic Spring Boot app with JPA

  • Database: MySQL

Using the app

To see how the app works locally

Run the backend locally

docker run --name backend
    -p <port>:8080
    -e MYSQL_DB_PASSWORD=<db-password>
    -e MYSQL_DB_USER=<db-user>
    -e MYSQL_DB_PORT=<db-port>
    -e MYSQL_DB_HOST=<db-host>
    -e MYSQL_DB_DATABASE=<db-databasse>
    -d marteoma/pizzas-back

The db-params are the values that your database has. The port is wheret the app will run in the host

Run the frontend locally

The frontend runs as a typical react app. To run it locally:

  1. Put your host on the .env file
REACT_APP_API_URL=<your-host>
  1. Install modules
npm install
  1. Run
npm start

Additional you can run tests by running

npm test

The Cloud

The cloud infrastructure is based on ECS with EC2 instances

There is also an RDS with a the MySQL database and a S3 bucket working as hosting for the frontend.

Build instrastructure

The cloud arquitecture is designed on AWS and implemented in terraform. To create the resources on an AWS first, put your AWS credentials. There are two ways:

  • With aws-cli
aws configure
  • Manully, set in ~/.aws/credentials
[default]
region=<region>
aws_access_key_id=<acces-key>
aws_secret_access_key=<secret-key>

After having set up the credentials file you can run the terraform steps to create the infrastructure.

  1. terraform init

  2. terraform apply

In the variables.tf file there are some key variables to have in count.

The instance type the EC2 will have.

variable "instance_type" {
  default     = "t2.micro"
  description = "AWS instance type"
}

The minimum count of EC2 that your cluster can have.

variable "min_cluster_size" {
    description     = "Minimum size of the cluster"
    default         = "2"
}

The maximum count of EC2 that your cluster can have.

variable "max_cluster_size" {
    description     = "Maximum size of the cluster"
    default         = "3"
}

The number of docker containers running with the app.

variable "desired_tasks" {
    description     = "Desired number of tasks running"
    default         = "2"
}

These values should be changed depending on the level of availavility desired.

There are also som values that are hidden, like the password to use in the database. These variables are described in the terraform.tfvars.example. To make it work, create a file terraform.tfvars and add all the values described in the example, and add them a value. Like this:

rds_database_password = "<password>"

Arquitecture

Arquitecture

As we see in the image we we have the frontend in the S3 bucket, which is connected to an ALB that balance traffic to the differentes instances of the cluster. And the instances connect to an RDS.

The EC2 are in an ASG and the RDS and the EC2 are in a private subnet, so it's not possible to acces directly.

CI/CD

The both pipelines, (front and back), are made with CircleCI.

Backend

  • Package and test
  • Build docker image
  • Push docker image to Dockerhub
  • Update ECS service

This pipeline needs the following environment variables to work.

  • AWS_ACCESS_KEY_ID Access key of the aws account

  • AWS_DEFAULT_REGION Region for aws

  • AWS_SECRET_ACCESS_KEY Secret key of the aws account

  • DOCKER_LOGIN Username of dockerhub

  • DOCKER_PASSWORD Token of dockerhub

  • MYSQL_DB_DATABASE The name of the database created on AWS

  • MYSQL_DB_HOST The address of the database created on AWS, is an output of terraform

  • MYSQL_DB_PASSWORD The password of the database created on AWS

  • MYSQL_DB_PORT The port of the database created on AWS

  • MYSQL_DB_USER The user of the database created on AWS

Frontend

  • Install modules
  • Test
  • Build
  • Upload to S3

This pipeline needs the following environment variables to work.

  • AWS_ACCESS_KEY_ID Access key of the aws account

  • AWS_DEFAULT_REGION Region for aws

  • AWS_SECRET_ACCESS_KEY Secret key of the aws account

  • BACKEND DNS of the ALB, is an output of terraform

  • BUCKET Name of the S3 bucket

Monitoring

There are two options for monitoring the app; directly on CloudWatch log groups or in the ECS console. On the CloudWatch log groups, there are five log groups to watch the state of the app. These groups are under /ecs. Additional there are alarms, which work together with the autoscalin group.

For the ECS, you can directly watch some metrics of the cluster just by entering the Amazon ECS page. If you go inside the cluster, you can get more information, about the state of the cluster.

pizzas-devops's People

Contributors

marteoma avatar

Watchers

 avatar  avatar

Forkers

zelfick

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.