From 521a9e64a2f5a570deabeb4e88ba524462a208c2 Mon Sep 17 00:00:00 2001 From: Minghe Date: Fri, 20 Mar 2020 18:54:30 +0800 Subject: [PATCH] update docs (#498) --- README.md | 32 +----------------------- bundler/README.md | 63 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 31 deletions(-) create mode 100644 bundler/README.md diff --git a/README.md b/README.md index f0902d06..c4c77d39 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,6 @@ Poor man's function as a service. - [Introduction](#introduction) - [Installation](#installation) - [Usage](#usage) -- [Contribute](#contribute) - ## Introduction @@ -77,9 +75,6 @@ NAME: USAGE: fx [global options] command [command options] [arguments...] -VERSION: - 0.9.33 - COMMANDS: up deploy a function down destroy a service @@ -110,7 +105,7 @@ $ fx up --name hello ./examples/functions/JavaScript/func.js #### Remote host -Use `--host` to specify the target host for your function, +Use `--host` to specify the target host for your function, or you can just set it to `FX_HOST` environment variable. ```shell $ fx up --host roo@ --name hello ./examples/functions/JavaScript/func.js @@ -220,31 +215,6 @@ $ FX_KUBECONF=~/.kube/config fx up examples/functions/JavaScript/func.js --name fx infra create --type k3s --name fx-cluster-1 --master root@123.11.2.3 --agents 'root@1.1.1.1,root@2.2.2.2' ``` -## Contribute - -fx uses [Project](https://github.com/metrue/fx/projects/4) to manage the development. - -#### Prerequisites - -Docker: make sure [Docker](https://docs.docker.com/engine/installation/) installed and running on your server. - - - -#### Build & Test - -``` -$ git clone https://github.com/metrue/fx -$ cd fx -$ make build -``` - -Then you can build and test: - -``` -$ make build -$ ./build/fx -h -``` - ## Contributors diff --git a/bundler/README.md b/bundler/README.md new file mode 100644 index 00000000..6bff9a6c --- /dev/null +++ b/bundler/README.md @@ -0,0 +1,63 @@ +The only thing `fx` does is to make a single function to be an HTTP service, `fx` takes two steps to finish the process, +* Wraps the function into a web server project and make it be the handler function of the HTTP request. +* Builds the bundled web server to be Docker image, then run it as a Docker container and expose the service port. + +`bundler` is the component responsible for step 1: wrap a single function (and its dependencies) into a web server. Take a Node web service as an example, the project looks like this, +``` +helloworld +├── Dockerfile +├── app.js +└── fx.js +``` + +And the codes is pretty simple, + +**app.js** +```javascript +const Koa = require('koa'); +const bodyParser = require('koa-bodyparser'); +const cors = require('@koa/cors'); +const fx = require('./fx'); + +const app = new Koa(); +app.use(cors({ + origin: '*', +})); +app.use(bodyParser()); +app.use(fx); + +app.listen(3000); +``` + +**fx.js** +```javascript +module.exports = (ctx) => { + ctx.body = 'hello world' +} +``` + +**Dockerfile** +```dockerfile +FROM metrue/fx-node-base + +COPY . . +EXPOSE 3000 +CMD ["node", "app.js"] +``` + +You can see that it's a web service built with `Koa`, the request handler function defined in `fx.js` to response plain text `hello world`, so to make a general JavaScript/Node function to be a web service, we only have to put it into `fx.js` above, then build and run it with Docker and that's it. + +To support different programming languages, `fx` needs to implement different `bundlers`, the reasons are, +* The way to set up a web service is different in different languages +* The way to manage dependency is different in different languages. + +So there will be (are) different `bundlers` in `fx`. +``` +go-bundler: based on Gin +ruby-bundler: based on Sinatra +node-bundler: based on Koa +python-bundler: based on flask +... +``` + +