Giter Site home page Giter Site logo

hellgrenj / bare_knuckles Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 1.0 8 KB

A demo of a simple zero-downtime-deployment strategy using docker compose and HAProxy. The example application in the demo is built with the following tech: .net core 2.0, entity framework core 2.0, postgresql/mssql-linux and docker.

C# 86.65% Shell 0.56% JavaScript 12.78%

bare_knuckles's Introduction

bare knuckles

A demo of a simple zero-downtime-deployment strategy using docker compose and HAProxy. The example application in the demo is built with the following tech: .net core 2.0, entity framework core 2.0, postgresql/mssql-linux and docker.

prerequisites

  • docker (with docker-compose) (tested on 17.06.2-ce-win27 and 17.06.2-ce-mac27)
  • node 8.4.x or greater
  • .net core 2.0

take it for a spin

in .\bare_knuckles\api

  • run dotnet restore

in .\bare_knuckles

  • run npm install
  • open one terminal tab and run docker-compose up
  • wait until docker-compose is running the system, then open another terminal tab and run node exercise.js
    (this is a script simulating users. it sends a request every second and prints the response)
    Now you can see the requests being handled by two instances of ./bare_knuckles/api (HAProxy balancing with round robin) in one terminal tab (docker-compose up)
    and the responses in the other tab (exercise.js)
  • Now change what DemoController (GET /demo) is returning! (see BloggingContext and ValuesController for some example data access code)
  • Finally in a third tab run the deployment script node zero-downtime-deployment.js and see your changes reach "the users"
    (output from the running exercise.js script) without the system ever becoming unavailable.

.....and if you want, try this demo with mssql-linux instead of postgres

First stop the demo system (docker-compose stop) and kill the exercise.js script, then:

  1. replace postgres in docker-compose with
 mssql:
    image: microsoft/mssql-server-linux
    ports:
      - "1433:1433"
    volumes:
    - sharedvol:/var/opt/mssql
    environment:
      - ACCEPT_EULA=Y
      - SA_PASSWORD=BareKNuckles10

and make sure you have a volume "sharedvol" ..
see the postgresvol for an example in the same docker-compose file

  1. change what driver is being used in api.csproj
  <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.0" />
  <!-- <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.0" /> -->
  1. update the connection string and the driver being used in Startup.cs
  // postgres
  var sqlConnectionString = @"Server=postgres;Database=postgres;User Id=admin;Password=password";
  services.AddDbContext<BloggingContext>(options => options.UseNpgsql(sqlConnectionString));
    
  // sql server
  // var sqlConnectionString = @"Server=mssql;Database=Blogging;User Id=sa;Password=BareKNuckles10";
  // services.AddDbContext<BloggingContext>(options => options.UseSqlServer(sqlConnectionString));
  1. remove existing migrations
 rm -r Migrations
  1. create new init migration (for mssql)
dotnet ef migrations add init
  1. Make sure docker has at least 4GB of RAM

License

Released under the MIT license. Copyright (c) 2017 Johan Hellgren.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

bare_knuckles's People

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

dorucioclea

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.