-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2f3de7b
Showing
25 changed files
with
2,988 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
templates | ||
template | ||
build | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 octoproject | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Octo CLI | ||
|
||
`octo-cli` makes the data available from any database as a serverless web service, simplifying the process of building data-driven applications. | ||
|
||
Knative and OpenFaaS are the only supported serverless frameworks in `octo-cli` for now. | ||
|
||
<img src="https://user-images.githubusercontent.com/20528562/92412306-1b8d1880-f154-11ea-974e-8b610cbb4ea4.png" max-width="100%" /> | ||
|
||
|
||
|
||
Octo will create an endpoint that will expose your data as service, all you need to provide is yml file that describes your service. | ||
|
||
![overview](https://user-images.githubusercontent.com/20528562/92733888-b9652b00-f380-11ea-9643-9845953050dd.png) | ||
|
||
# Installation | ||
[Download Latest Binary](https://github.com/octoproject/octo-cli/releases/latest) | ||
|
||
Alternatively you can install using go: | ||
|
||
```bash | ||
go get github.com/octoproject/octo-cli | ||
``` | ||
|
||
# Examples | ||
Examples can be found in the [examples/](https://github.com/octoproject/octo-cli/tree/master/examples) directory. They are step-by-step examples that will help you to deploy your first service using | ||
`octo-cli` . | ||
|
||
# Usage | ||
|
||
``` | ||
$ octo-cli | ||
Expose data from any database as web service | ||
Usage: | ||
octo-cli [flags] | ||
octo-cli [command] | ||
Available Commands: | ||
build Build function Docker container | ||
create Create a new service | ||
deploy Deploy a new service | ||
help Help about any command | ||
init Generate service configuration YAML file | ||
Flags: | ||
-h, --help help for octo-cli | ||
Use "octo-cli [command] --help" for more information about a command. | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package command | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/octoproject/octo-cli/config" | ||
"github.com/octoproject/octo-cli/service" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
ErrEmptyRegistryPrefix = errors.New("error empty Docker Registry prefix") | ||
) | ||
|
||
type buildOptions struct { | ||
fileName string | ||
registryPrefix string | ||
imageTag string | ||
} | ||
|
||
func NewBuildCommand() *cobra.Command { | ||
options := buildOptions{} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "build", | ||
Short: "Build function Docker container", | ||
Example: "octo-cli build --file example-config.yml --prefix test.com --tag v1", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return runBuild(options) | ||
}, | ||
SilenceUsage: true, | ||
} | ||
|
||
flags := cmd.Flags() | ||
flags.StringVarP(&options.fileName, "file", "f", "", "Name of octo configuration file") | ||
flags.StringVarP(&options.registryPrefix, "prefix", "p", "", "Docker Registry prefix to build image") | ||
flags.StringVarP(&options.imageTag, "tag", "t", "", "Name and optionally a tag in the 'name:tag' format") | ||
|
||
return cmd | ||
} | ||
func runBuild(o buildOptions) error { | ||
s, err := config.LoadService(o.fileName) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if len(o.registryPrefix) < 1 { | ||
return ErrEmptyRegistryPrefix | ||
} | ||
err = service.BuildFunction(s, o.registryPrefix, o.imageTag) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package command | ||
|
||
import ( | ||
"github.com/octoproject/octo-cli/config" | ||
"github.com/octoproject/octo-cli/service" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type createOptions struct { | ||
fileName string | ||
} | ||
|
||
func NewCreateCommand() *cobra.Command { | ||
options := createOptions{} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "create", | ||
Short: "Create a new service", | ||
Example: "octo-cli create -f example-config.yml", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return runCreate(options) | ||
}, | ||
SilenceUsage: true, | ||
} | ||
|
||
flags := cmd.Flags() | ||
flags.StringVarP(&options.fileName, "file", "f", "", "Name of octo configuration file") | ||
return cmd | ||
} | ||
func runCreate(o createOptions) error { | ||
s, err := config.LoadService(o.fileName) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = service.NewFunction(s) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package command | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/octoproject/octo-cli/config" | ||
"github.com/octoproject/octo-cli/faas" | ||
"github.com/octoproject/octo-cli/knative" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
ErrBadGatewayURL = errors.New("error empty gateway url") | ||
ErrOpenfaasCredentials = errors.New("error empty Openfaas username or password") | ||
ErrUnknownPlatform = errors.New("error unknown platform") | ||
) | ||
|
||
type deplpyOptions struct { | ||
fileName string | ||
username string | ||
password string | ||
gatewayURL string | ||
namespace string | ||
image string | ||
imagePullPolicy string | ||
} | ||
|
||
func NewDeployCommand() *cobra.Command { | ||
options := deplpyOptions{} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "deploy", | ||
Short: "Deploy a new service", | ||
Example: `octo-cli deploy -f example.yml -i functions/nodeinfo-http:latest | ||
octo-cli deploy -f example.yml -g http://127.0.0.1:8080 -i functions/nodeinfo-http:latest -u admin -p 123456 `, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return runDeploy(options) | ||
}, | ||
SilenceUsage: true, | ||
} | ||
|
||
flags := cmd.Flags() | ||
flags.StringVarP(&options.fileName, "file", "f", "", "Name of the service yml file") | ||
flags.StringVarP(&options.username, "username", "u", "", "Openfaas gateway username") | ||
flags.StringVarP(&options.password, "password", "p", "", "Openfaas gateway password") | ||
flags.StringVarP(&options.gatewayURL, "gateway", "g", "http://127.0.0.1:8080", "Openfaas gateway URL") | ||
flags.StringVarP(&options.namespace, "namespace", "n", "", "Namespace for deployed function") | ||
flags.StringVarP(&options.image, "image", "i", "", "Docker image name") | ||
flags.StringVarP(&options.imagePullPolicy, "pullPolicy", "", "", "Docker image pull policy") | ||
|
||
return cmd | ||
} | ||
|
||
func runDeploy(o deplpyOptions) error { | ||
s, err := config.LoadService(o.fileName) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
env := map[string]string{ | ||
"DB_USER": s.DB.User, | ||
"DB_PASSWORD": s.DB.Password, | ||
"DB_NAME": s.DB.Name, | ||
"DB_HOST": s.DB.Host, | ||
"DB_DIALECT": s.DB.Type, | ||
"DB_PORT": s.DB.Port, | ||
"DB_TIMEOUT": s.DB.RequestTimeout, | ||
} | ||
|
||
switch s.Platform { | ||
case "openfaas": | ||
if len(o.username) < 1 || len(o.password) < 1 { | ||
return ErrOpenfaasCredentials | ||
} | ||
|
||
c := faas.New(o.username, o.password, o.gatewayURL) | ||
|
||
f := faas.Function{ | ||
ServiceName: s.ServiceName, | ||
Image: o.image, | ||
Namespace: o.namespace, | ||
EnvVars: env, | ||
} | ||
|
||
err := c.DeployFunction(&f) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Printf("Servive %s deployed successfully.\n", s.ServiceName) | ||
|
||
case "knative": | ||
f := knative.Function{ | ||
ServiceName: s.ServiceName, | ||
Image: o.image, | ||
Namespace: o.namespace, | ||
EnvVars: env, | ||
} | ||
|
||
err := knative.DeployFunction(&f) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Printf("Servive %s deployed successfully.\n", s.ServiceName) | ||
default: | ||
return ErrUnknownPlatform | ||
|
||
} | ||
return nil | ||
} |
Oops, something went wrong.