Skip to content

Commit acc336d

Browse files
allow for generating multi config
1 parent 5efaf1e commit acc336d

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

docker_compose.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,24 +150,34 @@ func ExportEnv(config config.Config) string {
150150
return strings.Join(builder, "\n")
151151
}
152152

153+
//TODO: main docker-compose should include secondary docker-compose files inside it somehow.
153154
type DockerComposeCmd struct {
154155
OutputDir string `name:"output dir" default:"./compose" short:"o" help:"Output dir for docker compose files." predictor:"dir"`
155156
BakeEnv bool `short:"e" help:"Bake in the configured environment to image after build."`
156157

157-
Config string `arg:"" name:"config" help:"config" predictor:"config"`
158+
Config []string `arg:"" name:"config" help:"config to include in the docker-compose. The first config is assuemd to be the main container, and will be the parent folder of the ouput project" predictor:"config"`
158159
}
159160

160161
func (r *DockerComposeCmd) Run(cli *Cli, ctx *context.Context) error {
161-
config, err := config.LoadConfig(cli.ConfDir, r.Config, true, cli.TemplatesDir)
162-
if err != nil {
163-
return errors.New("YAML syntax error. Please check your containers/*.yml config files.")
162+
if len(r.Config) < 1 {
163+
return errors.New("No config given, need at least one container name.")
164164
}
165-
dir := r.OutputDir + "/" + r.Config
165+
166+
dir := r.OutputDir + "/" + r.Config[0]
166167
if err := os.MkdirAll(dir, 0755); err != nil && !os.IsExist(err) {
167168
return err
168169
}
169-
if err := WriteDockerCompose(*config, dir, r.BakeEnv); err != nil {
170-
return err
170+
171+
configs := []*config.Config{}
172+
for _, configName := range(r.Config) {
173+
config, err := config.LoadConfig(cli.ConfDir, configName, true, cli.TemplatesDir)
174+
if err != nil {
175+
return errors.New("YAML syntax error. Please check your containers/*.yml config files.")
176+
}
177+
if err := WriteDockerCompose(*config, dir, r.BakeEnv); err != nil {
178+
return err
179+
}
180+
configs = append(configs, config)
171181
}
172182
return nil
173183
}

main_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ var _ = Describe("Generate", func() {
3636
})
3737

3838
It("should output docker compose cmd to config name's subdir", func() {
39-
runner := ddocker.DockerComposeCmd{Config: "test",
39+
runner := ddocker.DockerComposeCmd{Config: []string{"test"},
4040
OutputDir: testDir}
4141
err := runner.Run(cli, &ctx)
4242
Expect(err).To(BeNil())
@@ -46,7 +46,7 @@ var _ = Describe("Generate", func() {
4646
})
4747

4848
It("should force create output parent folders", func() {
49-
runner := ddocker.DockerComposeCmd{Config: "test",
49+
runner := ddocker.DockerComposeCmd{Config: []string{"test"},
5050
OutputDir: testDir + "/subfolder/sub-subfolder"}
5151
err := runner.Run(cli, &ctx)
5252
Expect(err).To(BeNil())

0 commit comments

Comments
 (0)