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

Store configuration in service as a separated attribute #860

Merged
merged 12 commits into from
Apr 12, 2019
30 changes: 22 additions & 8 deletions interface/grpc/core/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ func toProtoServices(ss []*service.Service) []*definition.Service {

func toProtoService(s *service.Service) *definition.Service {
return &definition.Service{
Hash: s.Hash,
Sid: s.Sid,
Name: s.Name,
Description: s.Description,
Repository: s.Repository,
Tasks: toProtoTasks(s.Tasks),
Events: toProtoEvents(s.Events),
Dependencies: toProtoDependencies(s.Dependencies),
Hash: s.Hash,
Sid: s.Sid,
Name: s.Name,
Description: s.Description,
Repository: s.Repository,
Tasks: toProtoTasks(s.Tasks),
Events: toProtoEvents(s.Events),
Configuration: toProtoConfiguration(s.Configuration),
Dependencies: toProtoDependencies(s.Dependencies),
}
}

Expand Down Expand Up @@ -95,6 +96,19 @@ func toProtoParameters(params []*service.Parameter) []*definition.Parameter {
return ps
}

func toProtoConfiguration(configuration *service.Dependency) *definition.Configuration {
if configuration == nil {
return nil
}
return &definition.Configuration{
Args: configuration.Args,
Command: configuration.Command,
Ports: configuration.Ports,
Volumes: configuration.Volumes,
Volumesfrom: configuration.VolumesFrom,
antho1404 marked this conversation as resolved.
Show resolved Hide resolved
}
}

func toProtoDependency(dep *service.Dependency) *definition.Dependency {
if dep == nil {
return nil
Expand Down
188 changes: 135 additions & 53 deletions protobuf/definition/service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions protobuf/definition/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ message Service {
string sid = 12; // Service's sid.
string name = 1; // Service's name.
string description = 2; // Service's description.
Configuration configuration = 8; // Configurations related to the service
repeated Task tasks = 5; // The list of tasks this service can execute.
repeated Event events = 6; // The list of events this service can emit.
repeated Dependency dependencies = 7; // The container dependencies this service requires.
Expand Down Expand Up @@ -51,6 +52,14 @@ message Parameter {
repeated Parameter object = 10; // Optional object structure definition when type is set to `Object`
}

message Configuration {
repeated string volumes = 1; // List of volumes.
repeated string volumesfrom = 2; // List of volumes mounted from other dependencies.
antho1404 marked this conversation as resolved.
Show resolved Hide resolved
repeated string ports = 3; // List of ports the container exposes.
repeated string args = 4; // Args to pass to the container.
string command = 5; // Command to run the container.
}

// A dependency is a configuration of an other container that runs separately from the service.
message Dependency {
string key = 8; // Dependency's key.
Expand Down
17 changes: 8 additions & 9 deletions service/inject_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@ func (s *Service) injectDefinition(def *importer.ServiceDefinition) {
s.Tasks = s.defTasksToService(def.Tasks)
s.Dependencies = s.defDependenciesToService(def.Dependencies)

configuration := &Dependency{
Key: importer.ConfigurationDependencyKey,
s.Configuration = &Dependency{
Key: MainServiceKey,
}
if def.Configuration != nil {
configuration.Command = def.Configuration.Command
configuration.Args = def.Configuration.Args
configuration.Ports = def.Configuration.Ports
configuration.Volumes = def.Configuration.Volumes
configuration.VolumesFrom = def.Configuration.VolumesFrom
configuration.Env = def.Configuration.Env
s.Configuration.Command = def.Configuration.Command
s.Configuration.Args = def.Configuration.Args
s.Configuration.Ports = def.Configuration.Ports
s.Configuration.Volumes = def.Configuration.Volumes
s.Configuration.VolumesFrom = def.Configuration.VolumesFrom
s.Configuration.Env = def.Configuration.Env
}
s.Dependencies = append(s.Dependencies, configuration)
}

func (s *Service) defTasksToService(tasks map[string]*importer.Task) []*Task {
Expand Down
Loading