Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy core services from tar #725

Merged
merged 5 commits into from
Jan 28, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ var (
once sync.Once
)

// ServiceConfig contains information related to services that the config knows about
type ServiceConfig struct {
URL string
Env map[string]string
}

// Config contains all the configuration needed.
type Config struct {
Server struct {
Expand All @@ -47,6 +53,10 @@ type Config struct {
}
}

Service struct {
Foo ServiceConfig
}

Docker struct {
Socket string
Core struct {
Expand Down Expand Up @@ -74,6 +84,7 @@ func New() (*Config, error) {
c.Core.Database.ExecutionRelativePath = filepath.Join("database", "executions")
c.Docker.Core.Path = "/mesg"
c.Docker.Socket = "/var/run/docker.sock"
c.Service.Foo = ServiceConfig{"https://github.com/mesg-foundation/service-ethereum-erc20", map[string]string{}}
return &c, nil
}

Expand Down Expand Up @@ -123,6 +134,13 @@ func (c *Config) Validate() error {
return nil
}

// Services returns all services that the configuration package is aware of
func (c *Config) Services() []ServiceConfig {
return []ServiceConfig{
c.Service.Foo,
}
}

// DaemonEnv returns the needed environmental variable for the Daemon.
func (c *Config) DaemonEnv() map[string]string {
return map[string]string{
Expand Down
21 changes: 21 additions & 0 deletions core/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,31 @@ func initGRPCServer(c *config.Config) (*grpc.Server, error) {
}

// init system services.
if err := deployCoreServices(c, a); err != nil {
return nil, err
}

return grpc.New(c.Server.Address, a), nil
}

func deployCoreServices(c *config.Config, api *api.API) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic shouldn't be in main.go

for _, service := range c.Services() {
logrus.Infof("Deploy service from %s", service.URL)
s, valid, err := api.DeployServiceFromURL(service.URL, service.Env)
if valid != nil {
return valid
}
if err != nil {
return err
}
logrus.Infof("Service %s deployed", s.Name)
if err := api.StartService(s.Sid); err != nil {
return err
}
}
return nil
}

func main() {
// init configs.
c, err := config.Global()
Expand Down