Compare commits
4 Commits
0.8.0-alph
...
0.8.1-alph
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d4af4f67b2 | ||
|
|
6420e8b6c6 | ||
|
|
15c59fa31f | ||
|
|
294131b48f |
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@@ -43,7 +43,7 @@ jobs:
|
||||
env:
|
||||
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
|
||||
run: |
|
||||
go test -race -coverprofile=coverage.txt -covermode=atomic ./...
|
||||
./scripts/coverage.sh
|
||||
bash <(curl -s https://codecov.io/bash) -t ${CODECOV_TOKEN}
|
||||
|
||||
- name: build fx
|
||||
|
||||
88
README.md
88
README.md
@@ -2,10 +2,8 @@ fx
|
||||
------
|
||||
Poor man's function as a service.
|
||||
<br/>
|
||||

|
||||

|
||||
[](https://app.fossa.com/projects/git%2Bgithub.com%2Fmetrue%2Ffx?ref=badge_shield)
|
||||
[](https://codecov.io/gh/metrue/fx)
|
||||

|
||||
[](https://codecov.io/gh/metrue/fx)
|
||||
[](https://goreportcard.com/report/github.com/metrue/fx)
|
||||
[](http://godoc.org/github.com/metrue/fx)
|
||||

|
||||
@@ -20,7 +18,9 @@ Poor man's function as a service.
|
||||
|
||||
## Introduction
|
||||
|
||||
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.
|
||||

|
||||
|
||||
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, both Docker host and Kubernetes cluster supported. 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 [@_metrue](https://twitter.com/_metrue) on Twitter, [@metrue](https://www.weibo.com/u/2165714507) on Weibo.
|
||||
|
||||
@@ -77,16 +77,16 @@ USAGE:
|
||||
fx [global options] command [command options] [arguments...]
|
||||
|
||||
VERSION:
|
||||
0.6.0
|
||||
0.8.1
|
||||
|
||||
COMMANDS:
|
||||
infra manage infrastructure of fx
|
||||
image manage image of service
|
||||
doctor health check for fx
|
||||
up deploy a function or a group of functions
|
||||
init start fx agent on host
|
||||
up deploy a function
|
||||
down destroy a service
|
||||
list, ls list deployed services
|
||||
call run a function instantly
|
||||
image manage image of service
|
||||
doctor health check for fx
|
||||
help, h Shows a list of commands or help for one command
|
||||
|
||||
GLOBAL OPTIONS:
|
||||
@@ -94,62 +94,7 @@ GLOBAL OPTIONS:
|
||||
--version, -v print the version
|
||||
```
|
||||
|
||||
1. List your current machines and activate you machine
|
||||
|
||||
```shell
|
||||
$ fx infra ls # list machines
|
||||
|
||||
{
|
||||
"localhost": {
|
||||
"Host": "localhost",
|
||||
"User": "",
|
||||
"Password": "",
|
||||
"Enabled": true,
|
||||
"Provisioned": false
|
||||
}
|
||||
}
|
||||
|
||||
$ fx infra activate localhost # activate 'localhost'
|
||||
|
||||
2019/08/10 13:21:20 info Provision:pull python Docker base iamge: ✓
|
||||
2019/08/10 13:21:21 info Provision:pull d Docker base image: ✓
|
||||
2019/08/10 13:21:23 info Provision:pull java Docker base image: ✓
|
||||
2019/08/10 13:21:28 info Provision:pull julia Docker base image: ✓
|
||||
2019/08/10 13:21:31 info Provision:pull node Docker base image: ✓
|
||||
2019/08/10 13:22:09 info Provision:pull go Docker base image: ✓
|
||||
2019/08/10 13:22:09 info provision machine localhost: ✓
|
||||
2019/08/10 13:22:09 info enble machine localhost: ✓
|
||||
```
|
||||
It may take seconds since `fx` needs to download some basic resources
|
||||
|
||||
*Note* you can add a remote host as fx machine also,
|
||||
```
|
||||
$ fx infra add --name my_aws_vm --host 13.121.202.227 --user root --password yourpassword
|
||||
|
||||
$ fx infra list
|
||||
{
|
||||
"my_aws_vm": {
|
||||
"Host": "13.121.202.227",
|
||||
"User": "root",
|
||||
"Password": "yourpassword",
|
||||
"Enabled": false,
|
||||
"Provisioned": false
|
||||
},
|
||||
"localhost": {
|
||||
"Host": "localhost",
|
||||
"User": "",
|
||||
"Password": "",
|
||||
"Enabled": true,
|
||||
"Provisioned": true
|
||||
}
|
||||
}
|
||||
|
||||
$ fx infra activate my_aws_vm
|
||||
|
||||
```
|
||||
then your function will be deployed onto remote host also.
|
||||
|
||||
2. Write a function
|
||||
1. Write a function
|
||||
|
||||
You can check out [examples](https://github.com/metrue/fx/tree/master/examples/functions) for reference. Let's write a function as an example, it calculates the sum of two numbers then returns:
|
||||
|
||||
@@ -160,7 +105,7 @@ module.exports = (ctx) => {
|
||||
```
|
||||
Then save it to a file `func.js`.
|
||||
|
||||
3. Deploy your function as a service
|
||||
2. Deploy your function as a service
|
||||
|
||||
Give your service a port with `--port`, and name with `--name`, heath checking with `--healthcheck` if you want.
|
||||
|
||||
@@ -181,7 +126,7 @@ $ fx image export -o <path of dir> func.js
|
||||
2019/09/25 19:31:19 info exported to <path of dir>: ✓
|
||||
```
|
||||
|
||||
4. Test your service
|
||||
3. Test your service
|
||||
|
||||
then you can test your service:
|
||||
|
||||
@@ -210,7 +155,12 @@ hello world
|
||||
|
||||
## Docker
|
||||
|
||||
TODO
|
||||
**fx** is originally designed to turn a function into a runnable Docker container in a easiest way, on a host with Docker running, you can just deploy your function with `fx up` command,
|
||||
|
||||
```shell
|
||||
fx up --name hello-svc --port 7777 hello.js # onto localhost
|
||||
DOCKER_REMOTE_HOST_ADDR=xx.xx.xx.xx DOCKER_REMOTE_HOST_USER=xxxx DOCKER_REMOTE_HOST_PASSWORD=xxxx fx up --name hello-svc --port 7777 hello.js # onto remote host
|
||||
```
|
||||
|
||||
## Kubernetes
|
||||
|
||||
|
||||
BIN
docs/fx-workflow.png
Normal file
BIN
docs/fx-workflow.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 50 KiB |
90
fx.go
90
fx.go
@@ -15,7 +15,7 @@ import (
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
const version = "0.8.0"
|
||||
const version = "0.8.1"
|
||||
|
||||
func init() {
|
||||
go checkForUpdate()
|
||||
@@ -64,52 +64,9 @@ func main() {
|
||||
return handlers.Init()(context.FromCliContext(c))
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "image",
|
||||
Usage: "manage image of service",
|
||||
Subcommands: []cli.Command{
|
||||
{
|
||||
Name: "build",
|
||||
Usage: "build a image",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "tag, t",
|
||||
Usage: "image tag",
|
||||
},
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
ctx := context.FromCliContext(c)
|
||||
if err := ctx.Use(middlewares.Setup); err != nil {
|
||||
log.Fatalf("%v", err)
|
||||
}
|
||||
return handlers.BuildImage()(ctx)
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "export",
|
||||
Usage: "export the Docker project of service",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "output, o",
|
||||
Usage: "output directory",
|
||||
},
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
return handlers.ExportImage()(context.FromCliContext(c))
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "doctor",
|
||||
Usage: "health check for fx",
|
||||
Action: func(c *cli.Context) error {
|
||||
return handlers.Doctor()(context.FromCliContext(c))
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "up",
|
||||
Usage: "deploy a function or a group of functions",
|
||||
Usage: "deploy a function",
|
||||
ArgsUsage: "[func.go func.js func.py func.rb ...]",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
@@ -178,6 +135,49 @@ func main() {
|
||||
return handlers.Call()(context.FromCliContext(c))
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "image",
|
||||
Usage: "manage image of service",
|
||||
Subcommands: []cli.Command{
|
||||
{
|
||||
Name: "build",
|
||||
Usage: "build a image",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "tag, t",
|
||||
Usage: "image tag",
|
||||
},
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
ctx := context.FromCliContext(c)
|
||||
if err := ctx.Use(middlewares.Setup); err != nil {
|
||||
log.Fatalf("%v", err)
|
||||
}
|
||||
return handlers.BuildImage()(ctx)
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "export",
|
||||
Usage: "export the Docker project of service",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "output, o",
|
||||
Usage: "output directory",
|
||||
},
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
return handlers.ExportImage()(context.FromCliContext(c))
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "doctor",
|
||||
Usage: "health check for fx",
|
||||
Action: func(c *cli.Context) error {
|
||||
return handlers.Doctor()(context.FromCliContext(c))
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user