Skip to content

Commit

Permalink
alpha: new protocol, run deps improvements, plugin cache dir
Browse files Browse the repository at this point in the history
  • Loading branch information
23doors committed Dec 6, 2021
1 parent 86d9caa commit e120dc0
Show file tree
Hide file tree
Showing 44 changed files with 847 additions and 1,011 deletions.
15 changes: 14 additions & 1 deletion cmd/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/outblocks/outblocks-cli/pkg/getter"
"github.com/outblocks/outblocks-cli/pkg/logger"
"github.com/outblocks/outblocks-cli/pkg/plugins"
"github.com/outblocks/outblocks-cli/pkg/server"
"github.com/pterm/pterm"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand All @@ -29,6 +30,8 @@ type Executor struct {
loader *plugins.Loader
log logger.Logger

srv *server.Server

cfg *config.Project

opts struct {
Expand Down Expand Up @@ -115,7 +118,7 @@ func (e *Executor) commandPreRun(ctx context.Context) error {
vals := map[string]interface{}{"var": v}

// Load config file.
if err := e.loadProjectConfig(ctx, cfgPath, vals, skipLoadApps, skipLoadPlugins, skipCheckConfig); err != nil && !errors.Is(err, config.ErrProjectConfigNotFound) {
if err := e.loadProjectConfig(ctx, cfgPath, e.srv.Addr().String(), vals, skipLoadApps, skipLoadPlugins, skipCheckConfig); err != nil && !errors.Is(err, config.ErrProjectConfigNotFound) {
return err
}

Expand Down Expand Up @@ -166,6 +169,12 @@ func (e *Executor) addPluginsCommands(cmd *cobra.Command) error {
return nil
}

func (e *Executor) startHostServer() error {
e.srv = server.NewServer(e.log)

return e.srv.Serve()
}

func (e *Executor) Execute(ctx context.Context) error {
if err := e.initConfig(); err != nil {
return err
Expand All @@ -175,6 +184,10 @@ func (e *Executor) Execute(ctx context.Context) error {
return err
}

if err := e.startHostServer(); err != nil {
return err
}

if err := e.commandPreRun(ctx); err != nil {
return err
}
Expand Down
18 changes: 10 additions & 8 deletions cmd/executor_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
plugin_util "github.com/outblocks/outblocks-plugin-go/util"
)

func (e *Executor) loadProjectConfig(ctx context.Context, cfgPath string, vals map[string]interface{}, skipLoadApps, skipLoadPlugins, skipCheck bool) error {
func (e *Executor) loadProjectConfig(ctx context.Context, cfgPath, hostAddr string, vals map[string]interface{}, skipLoadApps, skipLoadPlugins, skipCheck bool) error {
cfg, err := config.LoadProjectConfig(cfgPath, vals, &config.ProjectOptions{
Env: e.opts.env,
})
Expand All @@ -33,7 +33,7 @@ func (e *Executor) loadProjectConfig(ctx context.Context, cfgPath string, vals m
e.cfg = cfg

if !skipLoadPlugins {
if err := cfg.LoadPlugins(ctx, e.log, e.loader); err != nil {
if err := cfg.LoadPlugins(ctx, e.log, e.loader, hostAddr); err != nil {
return err
}
}
Expand All @@ -50,14 +50,16 @@ func (e *Executor) loadProjectConfig(ctx context.Context, cfgPath string, vals m
}

func (e *Executor) cleanupProject() error {
if e.cfg == nil {
return nil
if e.cfg != nil {
for _, plug := range e.cfg.LoadedPlugins() {
if err := plug.Stop(); err != nil {
return fmt.Errorf("error stopping plugin '%s': %w", plug.Name, err)
}
}
}

for _, plug := range e.cfg.LoadedPlugins() {
if err := plug.Stop(); err != nil {
return fmt.Errorf("error stopping plugin '%s': %w", plug.Name, err)
}
if e.srv != nil {
e.srv.Stop()
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (e *Executor) newInitCmd() *cobra.Command {
},
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
return actions.NewInit(e.Log(), e.PluginsCacheDir(), opts).Run(cmd.Context())
return actions.NewInit(e.Log(), e.PluginsCacheDir(), e.srv.Addr().String(), opts).Run(cmd.Context())
},
}

Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ require (
github.com/mholt/archiver/v3 v3.5.1
github.com/mitchellh/go-homedir v1.1.0
github.com/otiai10/copy v1.6.0
github.com/outblocks/outblocks-plugin-go v0.0.0-20211115132657-c42fed05643f
github.com/outblocks/outblocks-plugin-go v0.0.0-20211124232451-2f90864671ce
github.com/pterm/pterm v0.12.33
github.com/spf13/cobra v1.2.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.9.0
github.com/txn2/txeh v1.3.0
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
google.golang.org/grpc v1.42.0
google.golang.org/protobuf v1.27.1
)

require (
Expand Down Expand Up @@ -87,8 +89,6 @@ require (
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20210828152312-66f60bf46e71 // indirect
google.golang.org/grpc v1.40.0 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/ini.v1 v1.63.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
Expand All @@ -97,4 +97,4 @@ replace github.com/goccy/go-yaml => github.com/23doors/go-yaml v1.8.10-0.2021080

// replace github.com/goccy/go-yaml => ../go-yaml

replace github.com/outblocks/outblocks-plugin-go => ../outblocks-plugin-go
// replace github.com/outblocks/outblocks-plugin-go => ../outblocks-plugin-go
12 changes: 9 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,11 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI=
github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
github.com/containerd/aufs v0.0.0-20200908144142-dab0cbea06f4/go.mod h1:nukgQABAEopAHvB6j7cnP5zJ+/3aVcE7hCYqvIwAHyE=
github.com/containerd/aufs v0.0.0-20201003224125-76a6863f2989/go.mod h1:AkGGQs9NM2vtYHaUen+NljV0/baGCAPELGm2q9ZXpWU=
Expand Down Expand Up @@ -311,6 +315,7 @@ github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5y
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ=
github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/evanphx/json-patch v4.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
Expand Down Expand Up @@ -681,8 +686,8 @@ github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6
github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo=
github.com/otiai10/mint v1.3.2 h1:VYWnrP5fXmz1MXvjuUvcBrXSjGE6xjON+axB/UrpO3E=
github.com/otiai10/mint v1.3.2/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc=
github.com/outblocks/outblocks-plugin-go v0.0.0-20211115132657-c42fed05643f h1:Z6bxU4JvJSYM5piFCRWB0VMWjcDIXTWWAUNcTyHSfsY=
github.com/outblocks/outblocks-plugin-go v0.0.0-20211115132657-c42fed05643f/go.mod h1:xosanOIc+3GlRA9b90/xRoYWzRgdhbew9T7+yTeI/TQ=
github.com/outblocks/outblocks-plugin-go v0.0.0-20211124232451-2f90864671ce h1:boMBQxdPROQ9ZaUB6SVJMsLOckrCjrf/PgyeJO+0fPA=
github.com/outblocks/outblocks-plugin-go v0.0.0-20211124232451-2f90864671ce/go.mod h1:YpdRDqsSy9b2WbUiTIv5aXcxr52Rw2WGrCzoFCj4B8Q=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pelletier/go-toml v1.8.1/go.mod h1:T2/BmBdy8dvIRq1a/8aqjN41wvWlN4lrapLU/GW4pbc=
Expand Down Expand Up @@ -1313,8 +1318,9 @@ google.golang.org/grpc v1.37.1/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQ
google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
google.golang.org/grpc v1.39.0/go.mod h1:PImNr+rS9TWYb2O4/emRugxiyHZ5JyHW5F+RPnDzfrE=
google.golang.org/grpc v1.39.1/go.mod h1:PImNr+rS9TWYb2O4/emRugxiyHZ5JyHW5F+RPnDzfrE=
google.golang.org/grpc v1.40.0 h1:AGJ0Ih4mHjSeibYkFGh1dD9KJ/eOtZ93I6hoHhukQ5Q=
google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34=
google.golang.org/grpc v1.42.0 h1:XT2/MFpuPFsEX2fWh3YQtHkZ+WYZFQRfaUgLZYj/p6A=
google.golang.org/grpc v1.42.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
Expand Down
2 changes: 1 addition & 1 deletion internal/util/cmdinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (i *CmdInfo) Stop() error {
time.Sleep(commandCleanupTimeout)

if i.IsRunning() {
_ = i.cmd.Process.Signal(syscall.SIGKILL)
_ = i.cmd.Process.Kill()
}
}()

Expand Down
21 changes: 21 additions & 0 deletions internal/util/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package util

import (
"errors"

"google.golang.org/grpc/status"
)

func StatusFromError(err error) (s *status.Status, ok bool) {
for {
s, ok = status.FromError(err)
if ok {
return s, ok
}

err = errors.Unwrap(err)
if err == nil {
return nil, false
}
}
}
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@ package main

import (
"context"
"io"
"os"
"os/signal"
"runtime/debug"
"syscall"

"github.com/outblocks/outblocks-cli/cmd"
"google.golang.org/grpc/grpclog"
)

func main() {
// Disable grpc client logging.
grpclog.SetLoggerV2(grpclog.NewLoggerV2(io.Discard, io.Discard, io.Discard))

exec := cmd.NewExecutor()

ctx, cancel := context.WithCancel(context.Background())
Expand Down
8 changes: 4 additions & 4 deletions pkg/actions/app_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ func (d *AppAdd) prompt() (interface{}, error) {
if os.IsNotExist(err) {
err = plugin_util.MkdirAll(d.opts.OutputDir, 0755)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to create dir %s: %w", d.opts.OutputDir, err)
}
}

Expand Down Expand Up @@ -518,10 +518,10 @@ func (d *AppAdd) promptStatic() (*staticAppInfo, error) {
AppType: config.AppTypeStatic,
AppURL: d.opts.URL,
AppDir: d.opts.Dir,
AppDeploy: &types.AppDeployInfo{
AppDeploy: &config.AppDeployInfo{
Plugin: d.opts.DeployPlugin,
},
AppRun: &types.AppRunInfo{
AppRun: &config.AppRunInfo{
Plugin: d.opts.RunPlugin,
Command: d.opts.RunCommand,
},
Expand All @@ -545,7 +545,7 @@ func (d *AppAdd) promptService() (*serviceAppInfo, error) { // nolint: unparam
AppType: config.AppTypeService,
AppURL: d.opts.URL,
AppDir: d.opts.Dir,
AppRun: &types.AppRunInfo{
AppRun: &config.AppRunInfo{
Command: d.opts.RunCommand,
},
},
Expand Down
Loading

0 comments on commit e120dc0

Please sign in to comment.