GithubHelp home page GithubHelp logo

danillouz / wasabi Goto Github PK

View Code? Open in Web Editor NEW
7.0 4.0 1.0 10 KB

The webcontainers API.

License: MIT License

Go 75.02% Smarty 24.98%
kubernetes docker faas faas-platform serverless serverless-framework serverless-architectures whale wasabi waas

wasabi's Introduction

Wasabi

The webcontainers API.

It's Like Function as a Service (FaaS), but with ๐Ÿณ. Instead of uploading a (NodeJS) function that can be executed by calling a unique URL, you run an executable (one-off) Docker Image, by making a HTTP POST request.

Wasabi โค๏ธ Kubernetes.

Why?

Why not? ๐Ÿ˜

How?

You create configurations, where each configuration specifies a Docker Image, that will run to completion each time the Wasabi API is called with the configuration name, where:

  • A configuration is a k8s secret.
  • The secret contains the Docker Image as a base64 encoded data property.
  • The secret name is used as the URL parameter when calling the Wasabi API, to execute the desired Image.
  • The Docker Image muste be a one-off executable; it must run to completion.
  • To start the process of running the container, a HTTP POST request must be made to the /jobs/<SECRET_NAME> endpoint of the Wasabi API.
  • A JSON payload can be sent to provide Env Vars for the container.
  • The entire JSON payload can be passed as an argument to the created container.
  • A k8s Job is created inside the cluster on which Wasabi is installed, everytime the Wasabi API is called.
  • The container runs to completion, inside the Pod that was created by the Job.

The Wasabi API is a simple Go HTTP API that can be installed on any k8s cluster using Helm.

1. Install

First install the Wasabi API on your k8s cluster in a separate namespace by running:

> helm install ./charts/wasabi --namespace webcontainers --set wasabi.namespace=webcontainers --name wasabi

It's recommended to install Wasabi in it's own namespace.

This will create a service of type LoadBalancer:

> kub get service

NAME      TYPE           CLUSTER-IP     EXTERNAL-IP      PORT(S)        AGE
wasabi    LoadBalancer   10.63.241.41   34.196.174.132   80:31878/TCP   18m

Use the external IP and send a GET request to the /health endpoint, to see if Wasabi can receive traffic:

> curl http://34.196.174.132/health

{"message":"OK"}

2. Configure

Creating a config, means creating a k8s secret, which must contain bas64 encoded data values. We have to provide the Docker Image we wish to execute, for example danillouz/docker-say. This is a simple NodeJS script that prints passed arguments to STDOUT, just for demo purposes. The source code can be viewed here.

Encode the Docker Image name:

> echo -n "danillouz/docker-say" | base64

ZGFuaWxsb3V6L2RvY2tlci1zYXk=

Create the k8s manifest file:

> cat <<EOF > docker-say.yaml
apiVersion: v1
kind: Secret
metadata:
  name: webcontainers-config-docker-say
  namespace: webcontainers
type: Opaque
data:
  image: ZGFuaWxsb3V6L2RvY2tlci1zYXk=
EOF

Create the k8s secret:

> kubectl create -f docker-say.yaml -n webcontainers

secret "webcontainers-config-docker-say" created

3. Execute

Now we can use the secret name webcontainers-config-docker-say, to execute the configured Docker Image by sending a HTTP POST request to the jobs/webcontainers-config-docker-say endpoint of the Wasabi API:

curl -H "Content-Type: application/json" -X POST -d '{"data":"Hello World!"}' http://34.196.174.132/jobs/webcontainers-config-docker-say

{"UID":"990ce026-3cfb-11e8-bf98-42010a840020","message":"OK","name":"webcontainer-1523391193"}

This created Job webcontainer-1523391193 and if we inspect the logs of the container that was run, we'll see:

> kubectl logs jobs/webcontainer-1523391193 -n webcontainers

say.js args:  [ '{"config":{"image":"danillouz/docker-say"},"payload":{"data":"Hello World!"}}' ]

This single JSON string contains a config property, which contains all data properties specified in the corresponding secret. And a payload property, which contains the entire JSON payload that was sent when making the HTTP POST request. The NodeJS script can print it by accessing process.argv.

Another Example

Some executable Docker Images don't accept arguments but are configured purely by passing Env Vars, for example slack-notify. We can still execute Images like this with Wasabi by sending the following JSON payload:

{
  "containerEnvVars": [
    {
      "name": "SLACK_WEBHOOK",
      "value": "https://hooks.slack.com/services/xxxxxxxxx/xxxxxxxxx/xxxxxxxxxxxxxxxxxxxxxxxx"
    },
    { "name": "SLACK_TITLE", "value": "Wasabi is alive!" },
    { "name": "SLACK_MESSAGE", "value": "Hello World!" },
    { "name": "SLACK_COLOR", "value": "#d1f1a9" }
  ],
  "passContainerArg": false
}

By providing the property passContainerArg with value false, the JSON payload is NOT passed as an argument.

Disclaimer

At this stage Wasabi is just a proof of concept and I advise not to run it in production, yet. But it's awesome for experimentation and executing webhook.

wasabi's People

Contributors

danillouz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

lcsouzamenezes

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.