@@ -24,46 +24,59 @@ type FactoryOptions struct {
24
24
25
25
// Factory chooses the appropriate service runner for the given data stream, depending
26
26
// on service configuration files defined in the package or data stream.
27
- func Factory (options FactoryOptions ) (ServiceDeployer , error ) {
27
+ func Factory (options FactoryOptions ) (map [ string ] ServiceDeployer , error ) {
28
28
devDeployPath , err := FindDevDeployPath (options )
29
29
if err != nil {
30
30
return nil , errors .Wrapf (err , "can't find \" %s\" directory" , devDeployDir )
31
31
}
32
32
33
- serviceDeployerName , err := findServiceDeployer (devDeployPath )
33
+ serviceDeployers , err := findServiceDeployer (devDeployPath )
34
34
if err != nil {
35
35
return nil , errors .Wrap (err , "can't find any valid service deployer" )
36
36
}
37
37
38
- serviceDeployerPath := filepath . Join ( devDeployPath , serviceDeployerName )
38
+ serviceDeployerInstances := make ( map [ string ] ServiceDeployer )
39
39
40
- switch serviceDeployerName {
41
- case "k8s" :
42
- if _ , err := os .Stat (serviceDeployerPath ); err == nil {
43
- return NewKubernetesServiceDeployer (serviceDeployerPath )
44
- }
45
- case "docker" :
46
- dockerComposeYMLPath := filepath .Join (serviceDeployerPath , "docker-compose.yml" )
47
- if _ , err := os .Stat (dockerComposeYMLPath ); err == nil {
48
- sv , err := useServiceVariant (devDeployPath , options .Variant )
49
- if err != nil {
50
- return nil , errors .Wrap (err , "can't use service variant" )
40
+ for _ , serviceDeployerName := range serviceDeployers {
41
+ serviceDeployerPath := filepath .Join (devDeployPath , serviceDeployerName )
42
+
43
+ switch serviceDeployerName {
44
+ case "k8s" :
45
+ if _ , err := os .Stat (serviceDeployerPath ); err == nil {
46
+ k8sDeployer , _ := NewKubernetesServiceDeployer (serviceDeployerPath )
47
+ serviceDeployerInstances ["k8s" ] = k8sDeployer
48
+ }
49
+
50
+ case "docker" :
51
+ dockerComposeYMLPath := filepath .Join (serviceDeployerPath , "docker-compose.yml" )
52
+ if _ , err := os .Stat (dockerComposeYMLPath ); err == nil {
53
+ sv , err := useServiceVariant (devDeployPath , options .Variant )
54
+ if err != nil {
55
+ return nil , fmt .Errorf ("can't use service variant: %w" , err )
56
+ }
57
+ dcDeployer , _ := NewDockerComposeServiceDeployer ([]string {dockerComposeYMLPath }, sv )
58
+ serviceDeployerInstances ["docker" ] = dcDeployer
59
+ }
60
+
61
+ case "agent" :
62
+ customAgentCfgYMLPath := filepath .Join (serviceDeployerPath , "custom-agent.yml" )
63
+ if _ , err := os .Stat (customAgentCfgYMLPath ); err != nil {
64
+ return nil , fmt .Errorf ("can't find expected file custom-agent.yml: %w" , err )
65
+ }
66
+ agentDeployer , _ := NewCustomAgentDeployer (customAgentCfgYMLPath )
67
+ serviceDeployerInstances ["agent" ] = agentDeployer
68
+
69
+ case "tf" :
70
+ if _ , err := os .Stat (serviceDeployerPath ); err == nil {
71
+ tfDeployer , _ := NewTerraformServiceDeployer (serviceDeployerPath )
72
+ serviceDeployerInstances ["tf" ] = tfDeployer
51
73
}
52
- return NewDockerComposeServiceDeployer ([]string {dockerComposeYMLPath }, sv )
53
- }
54
- case "agent" :
55
- customAgentCfgYMLPath := filepath .Join (serviceDeployerPath , "custom-agent.yml" )
56
- if _ , err := os .Stat (customAgentCfgYMLPath ); err != nil {
57
- return nil , errors .Wrap (err , "can't find expected file custom-agent.yml" )
58
- }
59
- return NewCustomAgentDeployer (customAgentCfgYMLPath )
60
74
61
- case "tf" :
62
- if _ , err := os .Stat (serviceDeployerPath ); err == nil {
63
- return NewTerraformServiceDeployer (serviceDeployerPath )
75
+ default :
76
+ return nil , fmt .Errorf ("unsupported service deployer (name: %s)" , serviceDeployerName )
64
77
}
65
78
}
66
- return nil , fmt . Errorf ( "unsupported service deployer (name: %s)" , serviceDeployerName )
79
+ return serviceDeployerInstances , nil
67
80
}
68
81
69
82
// FindDevDeployPath function returns a path reference to the "_dev/deploy" directory.
@@ -86,10 +99,10 @@ func FindDevDeployPath(options FactoryOptions) (string, error) {
86
99
return "" , fmt .Errorf ("\" %s\" directory doesn't exist" , devDeployDir )
87
100
}
88
101
89
- func findServiceDeployer (devDeployPath string ) (string , error ) {
102
+ func findServiceDeployer (devDeployPath string ) ([] string , error ) {
90
103
fis , err := os .ReadDir (devDeployPath )
91
104
if err != nil {
92
- return "" , errors .Wrapf (err , "can't read directory (path: %s)" , devDeployDir )
105
+ return nil , errors .Wrapf (err , "can't read directory (path: %s)" , devDeployDir )
93
106
}
94
107
95
108
var folders []os.DirEntry
@@ -99,8 +112,9 @@ func findServiceDeployer(devDeployPath string) (string, error) {
99
112
}
100
113
}
101
114
102
- if len (folders ) != 1 {
103
- return "" , fmt .Errorf ("expected to find only one service deployer in \" %s\" " , devDeployPath )
115
+ var folderNames []string
116
+ for _ , fname := range folders {
117
+ folderNames = append (folderNames , fname .Name ())
104
118
}
105
- return folders [ 0 ]. Name () , nil
119
+ return folderNames , nil
106
120
}
0 commit comments