GithubHelp home page GithubHelp logo

devops_challenge_jianx's Introduction

devops_challenge_jianx

A static website using Docker and Nginx

This repo contains code to build a containerized static website using docker and Nginx. The static content is in index.html file, and Nginx is the web server. The Dockerfile is to build the docker image.

1. Build the website at localhost

1.1 Build Image

Run the following command to build a image:

cd devops_challenge_jianx

docker build -t webdemo .

docker images

1.2 Run a container to start the website

To run the image in a Docker container, use the following command

docker run --rm -p 80:80 webdemo

Note: Use --rm option to remove container automatically.

This will start the website on port 80. if you visit http://localhost and you will be able to see the static webpage.

1.3 Cleanup

Ctrl+C to stop the current container.

2. Create AWS Resource via Terraform

Please refer to README.md under terraform_aws_infra for the creation of AWS resources, which are used to host this static website.

AS shown in the following architectural diagram, the dockerized web application is hosted on EC2, which is fronted by CloudFront to globalise content delivery. the domain name http://web.jiandevops.link is managed by Route53. A tls certificate was created and managed by ACM to enabled https connection.

Alt text

3. Deploy the static web application to AWS via Jenkins CICD pipeline

Jenkins web server is manually hosted on a AWS EC2 instance, the Jenkinsfile under cicd folder is used to create a CICD pipeline to deploy this web application to AWS EC2.

3.1 Jenkins pipeline set-up

Steps to be followed to set up Jenkins CICD pipeline are :

  • Create pipeline in Jenkins
  • Set the definition to Pipeline script from SCM within the pipeline configuration
  • Add github repository URL
  • Set Jenkinsfile path in the Script Path
  • Set up webhooker on github application repository, in order to automatically trigger the pipeline when a change is pushed to main branch

Alt text

3.2 Pipeline stages

The pipeline stages include:

  • Build image based on the Dockerfile
  • Authenticate Docker client to AWS ECR
  • Push image to ECR
  • Deploy to remote web host

The pipeline output looks like this when run successfully.

Alt text

Alt text

Improvements, Alternatives and additional works

Improvements I would make if I had more time

Security improvement:

  • deploy an Application Load Balancer in the public subnet
  • associate web host EC2 with private subnet
  • set up EC2 security groups rules to allow incoming traffics only from ALB
  • update the distribution in CloudFront with the origin of ALB endpoint

Scalabilty and performance improvement

  • Set up an auto-scaling group (ASG) of EC2 instances to host the website instead of a single instance in private subnet
  • deploy an Application Load Balancer in the public subnet, and targeting ASG

Others

  • Set up a Jenkins pipeline to manage resources with Terraform

Alternative solution

The Alternative solution would be to host a static website with AWS S3 bucket, which, in my opinion, is a better alternative in this case, as S3 is one of the AWS resources with highest availability.

The reason why i didn't use AWS S3 is that I would like to demonstrate my technical skills on docker and container management.

Additional works if in production grade

  • Create dedicated VPC and subnets for the project to improve security
  • Deploy the containerized application to AWS ECS Fargate or AWS EKS in private subnets with multi-AZ set-up, depending on the type of the app and the needs of the business
  • Create API gateway, Lambda function or DynnamoDB resources if needed, especially when dynamic contents need to be delivered to the website.
  • Set up a monitoring dashboard to monitor the performance of the website, especially Throughput, Error rate, Latency and Saturation.
  • Set up terraform backend on AWS S3 and DynamoDB, to make teamwork easier
  • Create multi-branch CICD pipeline on Jenkins instead of single branch to improve development efficiency

devops_challenge_jianx's People

Contributors

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