Code Monkey home page Code Monkey logo

awsapp's Introduction

awsapp

This is a demo of doing a blue-green deploy of a simple web application using Docker Machine and Docker of course.

Orchestration of this deploy is handled using a highly advanced technology known as the Bourne again shell.

Requirements

  • Working copy of Docker.
  • Docker Machine installed as docker-machine command on your system.

Set the following environment variables:

$ export DOCKER_HUB_USER=nathanleclaire # Your username on Docker Hub
$ export AWS_VPC_ID=vpc-fe10ab9b # The default VPC for us-east-1 for your account
$ export AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
$ export AWS_ACCESS_KEY_ID=xxxxxxxxxxxxxxxxxxxx

After that, you should be ready to rock and roll.

Usage

Setup infrastructure (this will create the host and run the initial copy of the app):

./deploy.sh up 

Deploy the app:

./deploy.sh deploy 

Each deploy will be tagged by timestamp.

What if you deployed and broke everything with terrible code?

No problem. Just rollback to a known image tag:

./deploy.sh rollback Thu_Nov_13_22_49_34_UTC_2014 

Un-bootstrap (destroy) infrastructure:

./deploy.sh down 

Architecture

This demo is single-host, but the concepts could be applied to a multi-host setup with some additional elbow grease (and service discovery).

Two instances of a Flask (Python) application running in containers sit behind a load balancer (HAproxy). One exposes the application on the host's localhost:8000, the other exposes the application on the host's localhost:8001. They are connected to a container running Redis using Docker links.

The load balancer happily proxies requests to these backends with a round-robin algorithm.
Haproxy has a health check set so that if one of the containers stops responding at the health check endpoint, it will be taken out of rotation. So, when it comes time to do a deploy, first we tell one of the containers to start responding to HAproxy with a non-200 API status from the health check endpoint. This allows HAproxy an interval to "catch up" and remove the node from rotation before we take the container down and replace it with a new one running our new image (thereby deploying the new code).

All incoming requests get proxied to the "healthy" container while we restart the "unhealthy" one. When the node comes back up, it starts responding as healthy again and we repeat the process for the other node.

This allows us to do a deploy with very little (ideally none) downtime. You may notice that rollbacks to a previous tag are super fast too.

awsapp's People

Contributors

nathanleclaire avatar

Watchers

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