Poor man's function as a service.
fx is a tool to help you do Function as a Service on your own server. fx can make your stateless function a service in seconds. The most exciting thing is that you can write your functions with most programming languages.
Feel free hacking fx to support the languages not listed. Welcome to tweet me or Buy me a coffee.
Language | Status | Contributor |
---|---|---|
Go | Supported | fx |
Rust | Supported | @FrontMage |
Node | Supported | fx |
Python | Supported | fx |
Ruby | Supported | fx |
Java | Supported | fx |
PHP | Supported | @chlins |
Julia | Supported | @mbesancon |
D | Supported | @andre2007 |
R | Working on need your help |
┌────────┐
│fx init │ fx━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
└────────┘ ┃ ┌───────────────────────┐ ┃
────────────────────────╋─────────▶│Environment initialize │ ┃
┌──────┐ ┃ │* proxy docker sock │ ┃
│fx up │ ┃ │* pull fx base docker │ ┃
┌ ─ ─ ─ ┴──────┘─ ─ ┐ ┃ └───────────────────────┘ ┃
Function Source ┃ ┌──────────────┐ ┌─────────────────────────────┐ ┃
└ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘────╋──┬──────▶│ Pack │ │ │ ┃
┃ │ └──────┬───────┘ │ │ ┃
┌────────┐ ┃ │ ┌──────▼───────┐ │ │ ┃
│fx call │ ┃ │ │Build Service │◀─────▶│ │ ┃
└────────┘ ┃ │ └──────┬───────┘ │ │ ┃
┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐ ┃ │ ┌──────▼───────┐ │ │ ┃
Function Source ┃ │ │ Run Service │◀─────▶│ │ ┃
│ (with params) │────╋──┤ └──────────────┘ │ │ ┃
─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┃ │ │ │ ┃
┃ │ │ │ ┃
┃ │ ┌──────────────┐ │ Docker API │ ┃
┌────────┐ ┃ └──────▶│ Call Service │ │ │ ┃
│fx down │ ┃ │ (http) │ │ │ ┃
└────────┘ ┃ └──────────────┘ │ │ ┃
┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┃ ┌──────────────┐ │ │ ┃
Service Name │────╋─────────▶│ Stop Service │◀─────▶│ │ ┃
└ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┃ └──────────────┘ │ │ ┃
┌────────┐ ┃ │ │ ┃
│fx list │ ┃ │ │ ┃
└────────┘ ┃ │ │ ┃
┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┃ ┌──────────────┐ │ │ ┃
Service Name │────╋─────────▶│List Services │◀─────▶│ │ ┃
└ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┃ └──────────────┘ └─────────────────────────────┘ ┃
┃ ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
- MacOS
brew tap metrue/homebrew-fx
brew install metrue/fx/fx
- Linux/Unix
via cURL
curl -o- https://raw.githubusercontent.com/metrue/fx/master/scripts/install.sh | bash
or Wget
wget -qO- https://raw.githubusercontent.com/metrue/fx/master/scripts/install.sh | bash
fx will be installed into /usr/local/bin, sometimes you may need source ~/.zshrc
or source ~/.bashrc
to make fx available in $PAHT
.
- Window
You can go the release page to download fx manually;
Make sure Docker installed and running on your server first. then type fx -h
on your terminal to check out basic help.
$ fx -h
NAME:
fx - makes function as a service
USAGE:
fx [global options] command [command options] [arguments...]
VERSION:
0.3.2
COMMANDS:
init initialize fx running enviroment
up deploy a function or a group of functions
down destroy a service
list list deployed services
call run a function instantly
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--help, -h show help
--version, -v print the version
- Initialize fx running enviroment
fx init
It may take minutes since fx
needs to download some basic resources
- Write a function
You can check out examples for reference. Let's write a function as an example, it calculates the sum of two numbers then returns:
module.exports = (input) => {
return parseInt(input.a, 10) + parseInt(input.b, 10)
}
Then save it to a file sum.js
.
- Deploy your function as a service
fx up sum.js
or give your service a name with --name
fx up --name service_sum sum.js
if everything ok, you will get an url
for service.
- Test your service
then you can test your service:
curl -X POST <service address> -H "Content-Type: application/json" -d '{"a": 1, "b": 1}'
fx uses Project to manage the development.
- Docker: make sure Docker installed and running on your server.
- dep: fx project uses dep to do the golang dependency management.
$ git clone https://github.com/metrue/fx
$ cd fx
$ dep ensure
$ make build
Then you can build and test:
$ make build
$ ./build/fx -h
Thank you to all the people who already contributed to fx!