Code Monkey home page Code Monkey logo

bubble-sort-service's Introduction

Bubble Sort Service

Build Status

Bubble Sort Service is a service that implements the bubble sort as service. It can be run in various ways.

  • Locally by using local installed version of Node
  • Docker Container that exposes a server
  • Run locally within a docker container by providing an array as an env vairable (BUBBLE_SORT_ARRAY)

Tech

Bubble Sort Service uses a number of open source projects to work properly:

  • [node.js] - evented I/O for the backend
  • [Express] - fast node.js network app framework [@tjholowaychuk]
  • eslint - The pluggable linting utility for JavaScript and JSX
  • husky - Git hooks made easy
  • Docker - Building and Running Containers
  • node-docker - Small Docker Image to run node application - tarampampam/node:alpine
  • Jest - Unit Testing
  • TravisCI - CI Server
  • DockerHub - AutoBuilds Docker Container on Commit

And of course bubble-sort-service itself is open source with a [public repository][dill] on GitHub.

Installation

Bubble Sort Service requires Node.js v6+ to run.

To build the container locally

$ cd bubble-sort-service
$ yarn
$ yarn clean-build-docker

Install the dependencies and devDependencies and start the server.

$ cd bubble-sort-service
$ yarn
$ yarn docker-run

Once you have it up and running you can simply test it by

$ curl -X POST \
  http://localhost:8000/bubblesort \
  -H 'Content-Type: application/json' \
  -d '{"unsortedArray":[6, 2, [4, 3],[[[5], null], 1],6, 2, [4, 3],[[[5], null], 1],6, 2, [4, 3],[[[5], null], 1],6, 2, [4, 3],[[[5], null], 1]]}'

Your response will be a sorted array

To start the process locally and provide an array to sort edit the package.json file and simply run.

$ cd bubble-sort-service
$ yarn
$ yarn docker-run-local

Other commands include docker-run-with-max-items that allows you to specify the number of items the bubble-sort-service will support. If no value is provided it defaults to 10000

$ cd bubble-sort-service
$ yarn
$ yarn docker-run-with-max-items

The raw command for this is

$ docker run -e MAX_AMOUNT_OF_ITEMS_PER_ARRAY=100000 -p 8000:8000 -d bubble-sort-service

Extra Added Features!

In the repo you will see there is a folder labelled Cloudformation

  • This contains a CF Template that can be used in conjunction with the serverless framework to rapidly deploy bubble-sort-service to cloud infrastructure.

  • The template contains 3 resources:

    • BubbleSortRole - Dictates the permissions for our service
    • BubbleSortRoleInstaceProfile - Attaches BubbleSortRole to a Instance Profile
    • EC2InstanceBubbleSort - Is the EC2 Machine that will run the docker container that expects some parameters
      • InstanceType - The instance type: t2.nano should be suffienct
      • KeyName - Our SSH Key which was created in the EC2 Console
      • UserData: Provides the startup script for our machine when it provisioned. Here it installs docker, pulls jmaleonard/bubble-sort-service and start a container that exposes the service on port 8000
  • The serverless folder contains a template for our cloudformation stack "bubble-sort-service"

    • Replace call the parameters that are marked as #CHANGE ME

To Run:

  • To Run this template we can use the serverless framework as it provides a nice pattern when using CF
  • Install serverless
$ npm install -g serverless
$ cp -f serverless/EC2_Deployment.yml ./serverless.yml && sls deploy --stage personal --aws-profile personal && rm serverless.yml

Ways to improve this solution:

Add AWS Elastic Load Balancer that will allow us to not expose the EC2 Instaces Add a Launch Configuration that can be used with Auto Scaling so that bubble-sort-service can scale under load Add a VPC and place all Instances within the VPC and only exposing traffic through the AWS Elastic Load Balancer

bubble-sort-service's People

Contributors

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