Giter VIP home page Giter VIP logo

bstmicro's Introduction

SmartConnect coding challenge

The app was tested and built on Ubuntu 20.04.2 with Elixir 1.9.1 and OTP 22.0.

I used GitHub Actions for CI, hence the test runs can be seen under the Actions tab.

How to build

The first step is cloning the project:

git clone https://github.com/czzrr/BSTMicro

Navigate to the project directory with cd BSTMicro/ and get the project dependencies:

mix deps.get

Compile the project:

mix compile

Build the release:

mix release

You can now start the app by running _build/dev/rel/bst_micro/bin/bst_micro start.

Requests can now be sent to localhost:8080. An example is:

curl -H "Content-Type: application/json" -d '{"value": 7, "tree":{"value":4,"right":null,"left":null}}' localhost:8080/insert

This inserts 7 into the binary search tree containing a single node of value 4.

The response is {"status":200,"data":{"value":4,"right":{"value":7,"right":null,"left":null},"left":null}}.

Running the app in a Docker container

Build the image from the provided Dockerfile:

docker build --tag webserver:focal .

Run the container:

docker run --name webserver -d -p 8080:8080 webserver:focal

HTTP requests can now be sent in the same way as above.

Deploying the app with Kubernetes

The following instructions are for deploying the app in a local kind cluster with ingress.

Create the cluster with the provided cluster-config.yaml file:

kind create cluster --config=cluster-config.yaml

Load the docker image we built earlier into the cluster:

kind load docker-image webserver:focal

You can check if the cluster is ready by running kubectl get nodes.

Make sure you have an ingress controller. For example, Ingress NGINX is setup with

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/kind/deploy.yaml

When the process for setting up Ingress NGINX is done, the webserver and ingress can be started with:

kubectl apply -f webserver-config.yaml

Requests can now be sent the to the webserver by sending them to localhost/insert. Example:

curl -H "Content-Type: application/json" -d '{"value": 7, "tree":{"value":4,"right":null,"left":null}}' localhost/insert

Sending requests more easily

Running the app with iex -S mix lets you send requests in an easier way:

iex> Service.request_insert(BSTNode.from_list([7, 5]), 19)
%{
  "data" => %{
    "left" => %{"left" => nil, "right" => nil, "value" => 5},
    "right" => %{"left" => nil, "right" => nil, "value" => 19},
    "value" => 7
  },
  "status" => 200
}

%BSTNode{
  left: %BSTNode{left: nil, right: nil, value: 5},
  right: %BSTNode{left: nil, right: nil, value: 19},
  value: 7
}

bstmicro's People

Contributors

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