Skip to content

Commit

Permalink
Merge pull request #725 from mesg-foundation/feature/deploy-core-serv…
Browse files Browse the repository at this point in the history
…ice-from-tar

Deploy core services from tar
  • Loading branch information
antho1404 committed Jan 28, 2019
2 parents 938c878 + d351dc6 commit 84457e0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
18 changes: 18 additions & 0 deletions config/config.go
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
23 changes: 23 additions & 0 deletions core/main.go
Expand Up @@ -33,9 +33,32 @@ func initGRPCServer(c *config.Config) (*grpc.Server, error) {
return nil, err
}

// 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 {
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

0 comments on commit 84457e0

Please sign in to comment.