alexgarzao / fx

fx is a framework to help you do Function as a Service with painless on your own servers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

fx

Poor man's function as a service.
build codecov Go Report Card Go Doc Release

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

Architecture

        ┌────────┐
        │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 │◀─────▶│                             │      ┃
 └ ─ ─ ─ ─ ─ ─ ─ ─ ─     ┃          └──────────────┘       └─────────────────────────────┘      ┃
                         ┃                                                                      ┃
                         ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

Installation

  • 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;

Usage

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
  1. Initialize fx running enviroment
fx init

It may take minutes since fx needs to download some basic resources

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

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

  1. Test your service

then you can test your service:

curl -X POST <service address> -H "Content-Type: application/json" -d '{"a": 1, "b": 1}'

Contribute

fx uses Project to manage the development.

Prerequisites

  1. Docker: make sure Docker installed and running on your server.
  2. dep: fx project uses dep to do the golang dependency management.

Build & Test

$ git clone https://github.com/metrue/fx
$ cd fx
$ dep ensure
$ make build

Then you can build and test:

$ make build
$ ./build/fx -h

Contributors

Thank you to all the people who already contributed to fx!

metrue pplam muka xwjdsh mbesancon avelino DaidoujiChen chlins andre2007 andre2007

About

fx is a framework to help you do Function as a Service with painless on your own servers

License:MIT License


Languages

Language:Go 87.1%Language:Shell 7.4%Language:Dockerfile 1.9%Language:Rust 1.9%Language:Makefile 1.7%Language:C 0.0%