Skip to content

Commit 2f3de7b

Browse files
committed
Initial commit
0 parents  commit 2f3de7b

File tree

25 files changed

+2988
-0
lines changed

25 files changed

+2988
-0
lines changed

.gitignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
templates
2+
template
3+
build
4+
# Binaries for programs and plugins
5+
*.exe
6+
*.exe~
7+
*.dll
8+
*.so
9+
*.dylib
10+
11+
# Test binary, built with `go test -c`
12+
*.test
13+
14+
# Output of the go coverage tool, specifically when used with LiteIDE
15+
*.out
16+
17+
# Dependency directories (remove the comment below to include it)
18+
# vendor/

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 octoproject
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Octo CLI
2+
3+
`octo-cli` makes the data available from any database as a serverless web service, simplifying the process of building data-driven applications.
4+
5+
Knative and OpenFaaS are the only supported serverless frameworks in `octo-cli` for now.
6+
7+
<img src="https://user-images.githubusercontent.com/20528562/92412306-1b8d1880-f154-11ea-974e-8b610cbb4ea4.png" max-width="100%" />
8+
9+
10+
11+
Octo will create an endpoint that will expose your data as service, all you need to provide is yml file that describes your service.
12+
13+
![overview](https://user-images.githubusercontent.com/20528562/92733888-b9652b00-f380-11ea-9643-9845953050dd.png)
14+
15+
# Installation
16+
[Download Latest Binary](https://github.com/octoproject/octo-cli/releases/latest)
17+
18+
Alternatively you can install using go:
19+
20+
```bash
21+
go get github.com/octoproject/octo-cli
22+
```
23+
24+
# Examples
25+
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
26+
`octo-cli` .
27+
28+
# Usage
29+
30+
```
31+
$ octo-cli
32+
Expose data from any database as web service
33+
34+
Usage:
35+
octo-cli [flags]
36+
octo-cli [command]
37+
38+
Available Commands:
39+
build Build function Docker container
40+
create Create a new service
41+
deploy Deploy a new service
42+
help Help about any command
43+
init Generate service configuration YAML file
44+
45+
Flags:
46+
-h, --help help for octo-cli
47+
48+
Use "octo-cli [command] --help" for more information about a command.
49+
50+
```
51+

command/build.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package command
2+
3+
import (
4+
"errors"
5+
6+
"github.com/octoproject/octo-cli/config"
7+
"github.com/octoproject/octo-cli/service"
8+
"github.com/spf13/cobra"
9+
)
10+
11+
var (
12+
ErrEmptyRegistryPrefix = errors.New("error empty Docker Registry prefix")
13+
)
14+
15+
type buildOptions struct {
16+
fileName string
17+
registryPrefix string
18+
imageTag string
19+
}
20+
21+
func NewBuildCommand() *cobra.Command {
22+
options := buildOptions{}
23+
24+
cmd := &cobra.Command{
25+
Use: "build",
26+
Short: "Build function Docker container",
27+
Example: "octo-cli build --file example-config.yml --prefix test.com --tag v1",
28+
RunE: func(cmd *cobra.Command, args []string) error {
29+
return runBuild(options)
30+
},
31+
SilenceUsage: true,
32+
}
33+
34+
flags := cmd.Flags()
35+
flags.StringVarP(&options.fileName, "file", "f", "", "Name of octo configuration file")
36+
flags.StringVarP(&options.registryPrefix, "prefix", "p", "", "Docker Registry prefix to build image")
37+
flags.StringVarP(&options.imageTag, "tag", "t", "", "Name and optionally a tag in the 'name:tag' format")
38+
39+
return cmd
40+
}
41+
func runBuild(o buildOptions) error {
42+
s, err := config.LoadService(o.fileName)
43+
if err != nil {
44+
return err
45+
}
46+
47+
if len(o.registryPrefix) < 1 {
48+
return ErrEmptyRegistryPrefix
49+
}
50+
err = service.BuildFunction(s, o.registryPrefix, o.imageTag)
51+
if err != nil {
52+
return err
53+
}
54+
return nil
55+
}

command/create.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package command
2+
3+
import (
4+
"github.com/octoproject/octo-cli/config"
5+
"github.com/octoproject/octo-cli/service"
6+
"github.com/spf13/cobra"
7+
)
8+
9+
type createOptions struct {
10+
fileName string
11+
}
12+
13+
func NewCreateCommand() *cobra.Command {
14+
options := createOptions{}
15+
16+
cmd := &cobra.Command{
17+
Use: "create",
18+
Short: "Create a new service",
19+
Example: "octo-cli create -f example-config.yml",
20+
RunE: func(cmd *cobra.Command, args []string) error {
21+
return runCreate(options)
22+
},
23+
SilenceUsage: true,
24+
}
25+
26+
flags := cmd.Flags()
27+
flags.StringVarP(&options.fileName, "file", "f", "", "Name of octo configuration file")
28+
return cmd
29+
}
30+
func runCreate(o createOptions) error {
31+
s, err := config.LoadService(o.fileName)
32+
if err != nil {
33+
return err
34+
}
35+
36+
err = service.NewFunction(s)
37+
if err != nil {
38+
return err
39+
}
40+
return nil
41+
}

command/deploy.go

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
package command
2+
3+
import (
4+
"errors"
5+
"fmt"
6+
7+
"github.com/octoproject/octo-cli/config"
8+
"github.com/octoproject/octo-cli/faas"
9+
"github.com/octoproject/octo-cli/knative"
10+
"github.com/spf13/cobra"
11+
)
12+
13+
var (
14+
ErrBadGatewayURL = errors.New("error empty gateway url")
15+
ErrOpenfaasCredentials = errors.New("error empty Openfaas username or password")
16+
ErrUnknownPlatform = errors.New("error unknown platform")
17+
)
18+
19+
type deplpyOptions struct {
20+
fileName string
21+
username string
22+
password string
23+
gatewayURL string
24+
namespace string
25+
image string
26+
imagePullPolicy string
27+
}
28+
29+
func NewDeployCommand() *cobra.Command {
30+
options := deplpyOptions{}
31+
32+
cmd := &cobra.Command{
33+
Use: "deploy",
34+
Short: "Deploy a new service",
35+
Example: `octo-cli deploy -f example.yml -i functions/nodeinfo-http:latest
36+
octo-cli deploy -f example.yml -g http://127.0.0.1:8080 -i functions/nodeinfo-http:latest -u admin -p 123456 `,
37+
RunE: func(cmd *cobra.Command, args []string) error {
38+
return runDeploy(options)
39+
},
40+
SilenceUsage: true,
41+
}
42+
43+
flags := cmd.Flags()
44+
flags.StringVarP(&options.fileName, "file", "f", "", "Name of the service yml file")
45+
flags.StringVarP(&options.username, "username", "u", "", "Openfaas gateway username")
46+
flags.StringVarP(&options.password, "password", "p", "", "Openfaas gateway password")
47+
flags.StringVarP(&options.gatewayURL, "gateway", "g", "http://127.0.0.1:8080", "Openfaas gateway URL")
48+
flags.StringVarP(&options.namespace, "namespace", "n", "", "Namespace for deployed function")
49+
flags.StringVarP(&options.image, "image", "i", "", "Docker image name")
50+
flags.StringVarP(&options.imagePullPolicy, "pullPolicy", "", "", "Docker image pull policy")
51+
52+
return cmd
53+
}
54+
55+
func runDeploy(o deplpyOptions) error {
56+
s, err := config.LoadService(o.fileName)
57+
if err != nil {
58+
return err
59+
}
60+
61+
env := map[string]string{
62+
"DB_USER": s.DB.User,
63+
"DB_PASSWORD": s.DB.Password,
64+
"DB_NAME": s.DB.Name,
65+
"DB_HOST": s.DB.Host,
66+
"DB_DIALECT": s.DB.Type,
67+
"DB_PORT": s.DB.Port,
68+
"DB_TIMEOUT": s.DB.RequestTimeout,
69+
}
70+
71+
switch s.Platform {
72+
case "openfaas":
73+
if len(o.username) < 1 || len(o.password) < 1 {
74+
return ErrOpenfaasCredentials
75+
}
76+
77+
c := faas.New(o.username, o.password, o.gatewayURL)
78+
79+
f := faas.Function{
80+
ServiceName: s.ServiceName,
81+
Image: o.image,
82+
Namespace: o.namespace,
83+
EnvVars: env,
84+
}
85+
86+
err := c.DeployFunction(&f)
87+
if err != nil {
88+
return err
89+
}
90+
91+
fmt.Printf("Servive %s deployed successfully.\n", s.ServiceName)
92+
93+
case "knative":
94+
f := knative.Function{
95+
ServiceName: s.ServiceName,
96+
Image: o.image,
97+
Namespace: o.namespace,
98+
EnvVars: env,
99+
}
100+
101+
err := knative.DeployFunction(&f)
102+
if err != nil {
103+
return err
104+
}
105+
106+
fmt.Printf("Servive %s deployed successfully.\n", s.ServiceName)
107+
default:
108+
return ErrUnknownPlatform
109+
110+
}
111+
return nil
112+
}

0 commit comments

Comments
 (0)