Compare commits
3 Commits
0.8.1-alph
...
0.8.2-alph
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f9690b74a5 | ||
|
|
f2c58d545a | ||
|
|
4732426629 |
@@ -40,6 +40,8 @@ Feel free hacking fx to support the languages not listed. Welcome to tweet me [@
|
|||||||
|
|
||||||
# Installation
|
# Installation
|
||||||
|
|
||||||
|
Binaries are available for Windows, MacOS and Linux/Unix on x86. For other architectures and platforms, follow instructions to [build fx from source](#buildtest).
|
||||||
|
|
||||||
* MacOS
|
* MacOS
|
||||||
|
|
||||||
```
|
```
|
||||||
@@ -59,9 +61,9 @@ curl -o- https://raw.githubusercontent.com/metrue/fx/master/scripts/install.sh |
|
|||||||
curl -o- https://raw.githubusercontent.com/metrue/fx/master/scripts/install.sh | sudo bash
|
curl -o- https://raw.githubusercontent.com/metrue/fx/master/scripts/install.sh | sudo bash
|
||||||
```
|
```
|
||||||
|
|
||||||
fx will be installed into /usr/local/bin, sometimes you may need `source ~/.zshrc` or `source ~/.bashrc` to make fx available in `$PAHT`.
|
fx will be installed into /usr/local/bin, sometimes you may need `source ~/.zshrc` or `source ~/.bashrc` to make fx available in `$PATH`.
|
||||||
|
|
||||||
* Window
|
* Windows
|
||||||
|
|
||||||
You can go the release page to [download](https://github.com/metrue/fx/releases) fx manually;
|
You can go the release page to [download](https://github.com/metrue/fx/releases) fx manually;
|
||||||
|
|
||||||
@@ -229,6 +231,7 @@ fx uses [Project](https://github.com/metrue/fx/projects/4) to manage the develop
|
|||||||
Docker: make sure [Docker](https://docs.docker.com/engine/installation/) installed and running on your server.
|
Docker: make sure [Docker](https://docs.docker.com/engine/installation/) installed and running on your server.
|
||||||
|
|
||||||
|
|
||||||
|
<a name="buildtest"></a>
|
||||||
#### Build & Test
|
#### Build & Test
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
# fx on Amazon Lightsai
|
|
||||||
|
|
||||||
* make sure your instance have docker installed and running,
|
|
||||||
* make sure your instance can be ssh login (with user and password)
|
|
||||||
|
|
||||||
```
|
|
||||||
ssh <user>@<host>
|
|
||||||
```
|
|
||||||
|
|
||||||
* make sure your instance accept port 8866
|
|
||||||
|
|
||||||
* then you can deploy function to remote host
|
|
||||||
|
|
||||||
```
|
|
||||||
DOCKER_REMOTE_HOST_ADDR=<your host> DOCKER_REMOTE_HOST_USER=<your user> DOCKER_REMOTE_HOST_PASSWORD=<your password> ./build/fx up -p 1234 test/functions/func.js
|
|
||||||
```
|
|
||||||
46
docs/ubuntu.md
Normal file
46
docs/ubuntu.md
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
# fx on Ubuntu
|
||||||
|
|
||||||
|
> The guide is verified on Amazon Lightsail ubuntu 18.08 instance
|
||||||
|
|
||||||
|
## Install Docker
|
||||||
|
|
||||||
|
```shell
|
||||||
|
apt-get remove -y docker docker-engine docker.io containerd runc
|
||||||
|
apt-get update -y
|
||||||
|
apt-get install -y apt-transport-https ca-certificates curl software-properties-common lsb-core
|
||||||
|
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
|
||||||
|
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
|
||||||
|
apt-get update -y
|
||||||
|
apt-get install -y docker-ce
|
||||||
|
docker run hello-world
|
||||||
|
```
|
||||||
|
|
||||||
|
## Install fx
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$ curl -o- https://raw.githubusercontent.com/metrue/fx/master/scripts/install.sh | sudo bash
|
||||||
|
```
|
||||||
|
|
||||||
|
## Deploy a function onto localhost
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$ cat func.js
|
||||||
|
|
||||||
|
module.exports = (ctx) => {
|
||||||
|
ctx.body = 'hello world'
|
||||||
|
}
|
||||||
|
|
||||||
|
$ fx up -n test -p 2000 func.js
|
||||||
|
$ curl 127.0.0.1:2000
|
||||||
|
```
|
||||||
|
|
||||||
|
## Deploy a function onto remote host
|
||||||
|
|
||||||
|
* make sure your instance can be ssh login
|
||||||
|
* make sure your instance accept port 8866
|
||||||
|
|
||||||
|
then you can deploy function to remote host
|
||||||
|
|
||||||
|
```shell
|
||||||
|
DOCKER_REMOTE_HOST_ADDR=<your host> DOCKER_REMOTE_HOST_USER=<your user> DOCKER_REMOTE_HOST_PASSWORD=<your password> fx up -p 2000 test/functions/func.js
|
||||||
|
```
|
||||||
2
fx.go
2
fx.go
@@ -15,7 +15,7 @@ import (
|
|||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
const version = "0.8.1"
|
const version = "0.8.2"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
go checkForUpdate()
|
go checkForUpdate()
|
||||||
|
|||||||
@@ -3,15 +3,11 @@ set -e
|
|||||||
# ++
|
# ++
|
||||||
# verified on Ubuntu 16.04 x64
|
# verified on Ubuntu 16.04 x64
|
||||||
# ++
|
# ++
|
||||||
user_host=$1
|
apt-get remove -y docker docker-engine docker.io containerd runc
|
||||||
|
apt-get update -y
|
||||||
ssh ${user_host} 'bash -s' <<EOF
|
apt-get install -y apt-transport-https ca-certificates curl software-properties-common lsb-core
|
||||||
apt-get remove -y docker docker-engine docker.io containerd runc
|
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
|
||||||
apt-get update -y
|
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
|
||||||
apt-get install -y apt-transport-https ca-certificates curl software-properties-common lsb-core
|
apt-get update -y
|
||||||
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
|
apt-get install -y docker-ce
|
||||||
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu \$(lsb_release -cs) stable"
|
docker run hello-world
|
||||||
apt-get update -y
|
|
||||||
apt-get install -y docker-ce
|
|
||||||
docker run hello-world
|
|
||||||
EOF
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package middlewares
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/apex/log"
|
||||||
"github.com/metrue/fx/constants"
|
"github.com/metrue/fx/constants"
|
||||||
containerruntimes "github.com/metrue/fx/container_runtimes"
|
containerruntimes "github.com/metrue/fx/container_runtimes"
|
||||||
dockerHTTP "github.com/metrue/fx/container_runtimes/docker/http"
|
dockerHTTP "github.com/metrue/fx/container_runtimes/docker/http"
|
||||||
@@ -11,10 +12,37 @@ import (
|
|||||||
"github.com/metrue/fx/deploy"
|
"github.com/metrue/fx/deploy"
|
||||||
dockerDeployer "github.com/metrue/fx/deploy/docker"
|
dockerDeployer "github.com/metrue/fx/deploy/docker"
|
||||||
k8sDeployer "github.com/metrue/fx/deploy/kubernetes"
|
k8sDeployer "github.com/metrue/fx/deploy/kubernetes"
|
||||||
|
"github.com/metrue/fx/provision"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Setup create k8s or docker cli
|
// Setup create k8s or docker cli
|
||||||
func Setup(ctx *context.Context) (err error) {
|
func Setup(ctx *context.Context) (err error) {
|
||||||
|
host := os.Getenv("DOCKER_REMOTE_HOST_ADDR")
|
||||||
|
user := os.Getenv("DOCKER_REMOTE_HOST_USER")
|
||||||
|
passord := os.Getenv("DOCKER_REMOTE_HOST_PASSWORD")
|
||||||
|
var docker containerruntimes.ContainerRuntime
|
||||||
|
if host != "" && user != "" {
|
||||||
|
provisioner := provision.NewWithHost(host, user, passord)
|
||||||
|
if !provisioner.IsFxAgentRunning() {
|
||||||
|
if err := provisioner.StartFxAgent(); err != nil {
|
||||||
|
log.Fatalf("could not start fx agent on host: %s", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
log.Info("fx agent started")
|
||||||
|
}
|
||||||
|
|
||||||
|
docker, err = dockerHTTP.Create(host, constants.AgentPort)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
docker, err = dockerSDK.CreateClient(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ctx.Set("docker", docker)
|
||||||
|
|
||||||
var deployer deploy.Deployer
|
var deployer deploy.Deployer
|
||||||
if os.Getenv("KUBECONFIG") != "" {
|
if os.Getenv("KUBECONFIG") != "" {
|
||||||
deployer, err = k8sDeployer.Create()
|
deployer, err = k8sDeployer.Create()
|
||||||
@@ -29,21 +57,5 @@ func Setup(ctx *context.Context) (err error) {
|
|||||||
}
|
}
|
||||||
ctx.Set("deployer", deployer)
|
ctx.Set("deployer", deployer)
|
||||||
|
|
||||||
host := os.Getenv("DOCKER_REMOTE_HOST_ADDR")
|
|
||||||
user := os.Getenv("DOCKER_REMOTE_HOST_USER")
|
|
||||||
var docker containerruntimes.ContainerRuntime
|
|
||||||
if host != "" && user != "" {
|
|
||||||
docker, err = dockerHTTP.Create(host, constants.AgentPort)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
docker, err = dockerSDK.CreateClient(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ctx.Set("docker", docker)
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user