Compare commits

..

3 Commits

Author SHA1 Message Date
Minghe
f9690b74a5 auto startup fx agent during setup progress (#354)
* auto start fx agent during setup progress

* bump version
2019-11-15 19:41:17 +08:00
Minghe
f2c58d545a add document on ubunut (#352)
* add document on ubunut

* fix typo
2019-11-15 13:29:31 +08:00
Siddhesh Poyarekar
4732426629 Point to instructions to build from source for non-x86 targets (#350)
* Fix typos
* Point to instructions to build from source for non-x86 targets

Installation instructions do not specify clearly enough the fact that
they are supported only on x86. Make it clearer and point to the Build
and Test section in Contribute for instructions on building fx.
2019-11-14 15:22:25 +08:00
6 changed files with 88 additions and 47 deletions

View File

@@ -40,6 +40,8 @@ Feel free hacking fx to support the languages not listed. Welcome to tweet me [@
# 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
```
@@ -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
```
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;
@@ -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.
<a name="buildtest"></a>
#### Build & Test
```

View File

@@ -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
View 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
View File

@@ -15,7 +15,7 @@ import (
"github.com/urfave/cli"
)
const version = "0.8.1"
const version = "0.8.2"
func init() {
go checkForUpdate()

View File

@@ -3,15 +3,11 @@ set -e
# ++
# verified on Ubuntu 16.04 x64
# ++
user_host=$1
ssh ${user_host} 'bash -s' <<EOF
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"
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
EOF

View File

@@ -3,6 +3,7 @@ package middlewares
import (
"os"
"github.com/apex/log"
"github.com/metrue/fx/constants"
containerruntimes "github.com/metrue/fx/container_runtimes"
dockerHTTP "github.com/metrue/fx/container_runtimes/docker/http"
@@ -11,10 +12,37 @@ import (
"github.com/metrue/fx/deploy"
dockerDeployer "github.com/metrue/fx/deploy/docker"
k8sDeployer "github.com/metrue/fx/deploy/kubernetes"
"github.com/metrue/fx/provision"
)
// Setup create k8s or docker cli
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
if os.Getenv("KUBECONFIG") != "" {
deployer, err = k8sDeployer.Create()
@@ -29,21 +57,5 @@ func Setup(ctx *context.Context) (err error) {
}
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
}