Git Product home page Git Product logo

web-infra's Introduction

The tasks consist in two git repositories, the actual one which contains all the necesary files to complete the built of the infrustructe and https://github.com/pgjavier/simple-web which coaints the website code.

For this I have used AWS which setup is made by terraform and ansible to configure the instances, also the webservers are running with docker container. A part of that an instance of jenkins (master and slave) has been created to give the availability of CI, deploying the website code directly from github using webhooks.

The infrustructe is compose by 1 customer facing loadbalancer and n instances of frontends, in this example I use 2. The necesary subnets, groups and rules have been set to accomplish this task. As it is a development environment the nodes have direct access to internet to facilitate the deployment of the infrastructure.

In a production environment this would not be recommend and other tools like nexus (to store the docker images), or spacewalk (to have control of the packages) will be necessary.

Prerequisites: In the computer executing this code requires the following package:

- git
- ansible
- terraform
- boto python

Also it is need to setup AWS credentials in the ~/.aws/credentials file.

In variables.tf you will need to add the path to they Public key that you want to use to connect to AWS.

variable "public_key_path" {
description = "Enter the path to the SSH Public Key to add to AWS."
default = "~/.ssh/terraform.pub"

}

For checking to be able to conect to the slave, you need to add a private key to playbooks/roles/jenkins/files/id_rsa. It is been removed for security reasons.

Firstly you need to clone the actual repository to your local computer.

git clone https://github.com/pgjavier/web-infra.git

In order to run terraform you will to download it from https://www.terraform.io/downloads.html Go into the directory and run the following command to initiate terraform:

terraform init

You can now validate the terraform files

terraform validate

After that we will create an excecution plan

terraform plan

Finally after checking the excecution plan we will apply the configuration

terraform apply

Terraform will trigger ansible in order to configure the instances once they are running.

Due to the delays of the starting the aws instances I decided to removed the code that executes ansible from terraform as it was failing sometimes, even adding some mechanims to try to avoid it. It needs to be trigger in this way:

ansible-playbook -u centos --private-key 'key/id_rsa' playbooks/site.yml

The initial configuration of jekins needs to be manually done such as adding credentials. Also the configuration of webhooks in github is being done manually. With an own git server this part could be also automate.

If in any moment it is need to lunch ansible configuration again, it can be done executing the following playbook:

ansible-playbook -u centos --private-key 'key/id_rsa' playbooks/site.yml

To manually deploy the website code you can run:

ansible-playbook -u centos --private-key 'key/id_rsa' playbooks/website-deploy.yml

In order to avoid down time to the customers the deployment of the code is setup to be done in serie, in this case doing first the 50% of the nodes before continuing with the rest.

The site can be access from:

http://elb-public-frontend-642838251.us-east-2.elb.amazonaws.com/

web-infra's People

Watchers

James Cloos 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.