feat: support depends_on
This commit is contained in:
parent
669ebd0f25
commit
8b68c9587c
@ -518,6 +518,7 @@ func NewSecret() *Secret {
|
||||
type Service struct {
|
||||
CapabilitiesAdd []string `json:"cap_add,omitempty" yaml:"cap_add,omitempty"`
|
||||
CapabilitiesDrop []string `json:"cap_drop,omitempty" yaml:"cap_drop,omitempty"`
|
||||
DependsOn []string `json:"depends_on,omitempty" yaml:"depends_on,omitempty"`
|
||||
Deploy *ServiceDeploy `json:"deploy,omitempty" yaml:"deploy,omitempty"`
|
||||
Environments []string `json:"environment,omitempty" yaml:"environment,omitempty"`
|
||||
ExtraHosts []string `json:"extra_hosts,omitempty" yaml:"extra_hosts,omitempty"`
|
||||
@ -644,6 +645,7 @@ func (s *Service) Equal(equalable Equalable) bool {
|
||||
default:
|
||||
return equalSlice(s.CapabilitiesAdd, service.CapabilitiesAdd) &&
|
||||
equalSlice(s.CapabilitiesDrop, service.CapabilitiesDrop) &&
|
||||
equalSlice(s.DependsOn, service.DependsOn) &&
|
||||
s.Deploy.Equal(service.Deploy) &&
|
||||
equalSlice(s.Environments, service.Environments) &&
|
||||
equalSlice(s.ExtraHosts, service.ExtraHosts) &&
|
||||
@ -675,6 +677,7 @@ func (s *Service) MergeExistingWin(service *Service) {
|
||||
default:
|
||||
s.mergeExistingWinCapabilitiesAdd(service.CapabilitiesAdd)
|
||||
s.mergeExistingWinCapabilitiesDrop(service.CapabilitiesDrop)
|
||||
s.mergeExistingWinDependsOn(service.DependsOn)
|
||||
s.mergeExistingWinDeploy(service.Deploy)
|
||||
s.mergeExistingWinEnvironments(service.Environments)
|
||||
s.mergeExistingWinExtraHosts(service.ExtraHosts)
|
||||
@ -708,6 +711,7 @@ func (s *Service) MergeLastWin(service *Service) {
|
||||
default:
|
||||
s.mergeLastWinCapabilitiesAdd(service.CapabilitiesAdd)
|
||||
s.mergeLastWinCapabilitiesDrop(service.CapabilitiesDrop)
|
||||
s.mergeLastWinDependsOn(service.DependsOn)
|
||||
s.mergeLastWinDeploy(service.Deploy)
|
||||
s.mergeLastWinEnvironments(service.Environments)
|
||||
s.mergeLastWinExtraHosts(service.ExtraHosts)
|
||||
@ -737,6 +741,14 @@ func (s *Service) mergeExistingWinCapabilitiesDrop(capabilitiesDrop []string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Service) mergeExistingWinDependsOn(dependsOn []string) {
|
||||
for _, depOn := range dependsOn {
|
||||
if !existsInSlice(s.DependsOn, depOn) && len(depOn) > 0 {
|
||||
s.DependsOn = append(s.DependsOn, depOn)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Service) mergeExistingWinDeploy(deploy *ServiceDeploy) {
|
||||
switch {
|
||||
case s.Deploy == nil && deploy != nil:
|
||||
@ -913,12 +925,24 @@ func (s *Service) mergeLastWinCapabilitiesDrop(capabilitiesDrop []string) {
|
||||
continue
|
||||
}
|
||||
|
||||
if !existsInSlice(s.CapabilitiesAdd, capabilityDrop) {
|
||||
if !existsInSlice(s.CapabilitiesDrop, capabilityDrop) {
|
||||
s.CapabilitiesDrop = append(s.CapabilitiesDrop, capabilityDrop)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Service) mergeLastWinDependsOn(dependsOn []string) {
|
||||
for _, dep := range dependsOn {
|
||||
if len(dep) <= 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
if !existsInSlice(s.DependsOn, dep) {
|
||||
s.DependsOn = append(s.DependsOn, dep)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Service) mergeLastWinDeploy(deploy *ServiceDeploy) {
|
||||
switch {
|
||||
case s.Deploy == nil && deploy != nil:
|
||||
|
@ -225,6 +225,7 @@ func TestService_Equal(t *testing.T) {
|
||||
equalableA: &dockerCompose.Service{
|
||||
CapabilitiesAdd: []string{},
|
||||
CapabilitiesDrop: []string{},
|
||||
DependsOn: []string{},
|
||||
Deploy: nil,
|
||||
Environments: []string{},
|
||||
ExtraHosts: []string{},
|
||||
@ -239,6 +240,7 @@ func TestService_Equal(t *testing.T) {
|
||||
equalableB: &dockerCompose.Service{
|
||||
CapabilitiesAdd: []string{},
|
||||
CapabilitiesDrop: []string{},
|
||||
DependsOn: []string{},
|
||||
Deploy: nil,
|
||||
Environments: []string{},
|
||||
ExtraHosts: []string{},
|
||||
@ -288,6 +290,24 @@ func TestService_Equal(t *testing.T) {
|
||||
},
|
||||
expectedResult: false,
|
||||
},
|
||||
{
|
||||
equalableA: &dockerCompose.Service{
|
||||
DependsOn: []string{"app"},
|
||||
},
|
||||
equalableB: &dockerCompose.Service{
|
||||
DependsOn: []string{},
|
||||
},
|
||||
expectedResult: false,
|
||||
},
|
||||
{
|
||||
equalableA: &dockerCompose.Service{
|
||||
DependsOn: []string{"app"},
|
||||
},
|
||||
equalableB: &dockerCompose.Service{
|
||||
DependsOn: []string{"app"},
|
||||
},
|
||||
expectedResult: true,
|
||||
},
|
||||
{
|
||||
equalableA: &dockerCompose.Service{
|
||||
Deploy: &dockerCompose.ServiceDeploy{},
|
||||
@ -575,6 +595,52 @@ func TestService_MergeExistingWin(t *testing.T) {
|
||||
},
|
||||
},
|
||||
|
||||
// DependsOn
|
||||
{
|
||||
serviceDeploymentA: &dockerCompose.Service{
|
||||
DependsOn: []string{"app"},
|
||||
},
|
||||
serviceDeploymentB: &dockerCompose.Service{
|
||||
DependsOn: []string{},
|
||||
},
|
||||
expectedService: &dockerCompose.Service{
|
||||
DependsOn: []string{"app"},
|
||||
},
|
||||
},
|
||||
{
|
||||
serviceDeploymentA: &dockerCompose.Service{
|
||||
DependsOn: []string{},
|
||||
},
|
||||
serviceDeploymentB: &dockerCompose.Service{
|
||||
DependsOn: []string{"app"},
|
||||
},
|
||||
expectedService: &dockerCompose.Service{
|
||||
DependsOn: []string{"app"},
|
||||
},
|
||||
},
|
||||
{
|
||||
serviceDeploymentA: &dockerCompose.Service{
|
||||
DependsOn: []string{"app"},
|
||||
},
|
||||
serviceDeploymentB: &dockerCompose.Service{
|
||||
DependsOn: []string{"app"},
|
||||
},
|
||||
expectedService: &dockerCompose.Service{
|
||||
DependsOn: []string{"app"},
|
||||
},
|
||||
},
|
||||
{
|
||||
serviceDeploymentA: &dockerCompose.Service{
|
||||
DependsOn: []string{"app"},
|
||||
},
|
||||
serviceDeploymentB: &dockerCompose.Service{
|
||||
DependsOn: []string{""},
|
||||
},
|
||||
expectedService: &dockerCompose.Service{
|
||||
DependsOn: []string{"app"},
|
||||
},
|
||||
},
|
||||
|
||||
// Deploy
|
||||
{
|
||||
serviceDeploymentA: &dockerCompose.Service{
|
||||
@ -1476,6 +1542,52 @@ func TestService_MergeLastWin(t *testing.T) {
|
||||
},
|
||||
},
|
||||
|
||||
// DependsOn
|
||||
{
|
||||
serviceDeploymentA: &dockerCompose.Service{
|
||||
DependsOn: []string{"app"},
|
||||
},
|
||||
serviceDeploymentB: &dockerCompose.Service{
|
||||
DependsOn: []string{},
|
||||
},
|
||||
expectedService: &dockerCompose.Service{
|
||||
DependsOn: []string{"app"},
|
||||
},
|
||||
},
|
||||
{
|
||||
serviceDeploymentA: &dockerCompose.Service{
|
||||
DependsOn: []string{},
|
||||
},
|
||||
serviceDeploymentB: &dockerCompose.Service{
|
||||
DependsOn: []string{"app"},
|
||||
},
|
||||
expectedService: &dockerCompose.Service{
|
||||
DependsOn: []string{"app"},
|
||||
},
|
||||
},
|
||||
{
|
||||
serviceDeploymentA: &dockerCompose.Service{
|
||||
DependsOn: []string{"app"},
|
||||
},
|
||||
serviceDeploymentB: &dockerCompose.Service{
|
||||
DependsOn: []string{"app"},
|
||||
},
|
||||
expectedService: &dockerCompose.Service{
|
||||
DependsOn: []string{"app"},
|
||||
},
|
||||
},
|
||||
{
|
||||
serviceDeploymentA: &dockerCompose.Service{
|
||||
DependsOn: []string{"app"},
|
||||
},
|
||||
serviceDeploymentB: &dockerCompose.Service{
|
||||
DependsOn: []string{""},
|
||||
},
|
||||
expectedService: &dockerCompose.Service{
|
||||
DependsOn: []string{"app"},
|
||||
},
|
||||
},
|
||||
|
||||
// Deploy
|
||||
{
|
||||
serviceDeploymentA: &dockerCompose.Service{
|
||||
|
Loading…
Reference in New Issue
Block a user