diff --git a/launcher_go/v2/cli_build.go b/launcher_go/v2/cli_build.go index b6f9294f4..5b9c67a1a 100644 --- a/launcher_go/v2/cli_build.go +++ b/launcher_go/v2/cli_build.go @@ -36,7 +36,8 @@ func (r *DockerBuildCmd) Run(cli *Cli, ctx *context.Context) error { if err := os.MkdirAll(dir, 0755); err != nil && !os.IsExist(err) { return err } - if err := config.WriteYamlConfig(dir); err != nil { + configFile := "config.yaml" + if err := config.WriteYamlConfig(dir, configFile); err != nil { return err } @@ -48,7 +49,7 @@ func (r *DockerBuildCmd) Run(cli *Cli, ctx *context.Context) error { builder := docker.DockerBuilder{ Config: config, Ctx: ctx, - Stdin: strings.NewReader(config.Dockerfile(pupsArgs, r.BakeEnv)), + Stdin: strings.NewReader(config.Dockerfile(pupsArgs, r.BakeEnv, configFile)), Dir: dir, Namespace: namespace, ImageTag: r.Tag, diff --git a/launcher_go/v2/config/config.go b/launcher_go/v2/config/config.go index 41e57188b..38a1f60a1 100644 --- a/launcher_go/v2/config/config.go +++ b/launcher_go/v2/config/config.go @@ -130,7 +130,10 @@ func (config *Config) Yaml() string { return strings.Join(config.rawYaml, "_FILE_SEPERATOR_") } -func (config *Config) Dockerfile(pupsArgs string, bakeEnv bool) string { +func (config *Config) Dockerfile(pupsArgs string, bakeEnv bool, configFile string) string { + if configFile == "" { + configFile = "config.yaml" + } builder := strings.Builder{} builder.WriteString("ARG dockerfile_from_image=" + config.Base_Image + "\n") builder.WriteString("FROM ${dockerfile_from_image}\n") @@ -139,7 +142,7 @@ func (config *Config) Dockerfile(pupsArgs string, bakeEnv bool) string { builder.WriteString(config.dockerfileEnvs() + "\n") } builder.WriteString(config.dockerfileExpose() + "\n") - builder.WriteString("COPY config.yaml /temp-config.yaml\n") + builder.WriteString("COPY " + configFile + " /temp-config.yaml\n") builder.WriteString("RUN " + "cat /temp-config.yaml | /usr/local/bin/pups " + pupsArgs + " --stdin " + "&& rm /temp-config.yaml\n") @@ -147,8 +150,11 @@ func (config *Config) Dockerfile(pupsArgs string, bakeEnv bool) string { return builder.String() } -func (config *Config) WriteYamlConfig(dir string) error { - file := strings.TrimRight(dir, "/") + "/config.yaml" +func (config *Config) WriteYamlConfig(dir string, configFile string) error { + if configFile == "" { + configFile = "config.yaml" + } + file := strings.TrimRight(dir, "/") + "/" + configFile if err := os.WriteFile(file, []byte(config.Yaml()), 0660); err != nil { return errors.New("error writing config file " + file) } diff --git a/launcher_go/v2/config/config_test.go b/launcher_go/v2/config/config_test.go index 85ce46ef8..104ba0c26 100644 --- a/launcher_go/v2/config/config_test.go +++ b/launcher_go/v2/config/config_test.go @@ -29,7 +29,7 @@ var _ = Describe("Config", func() { }) It("can write raw yaml config", func() { - err := conf.WriteYamlConfig(testDir) + err := conf.WriteYamlConfig(testDir, "config.yaml") Expect(err).To(BeNil()) out, err := os.ReadFile(testDir + "/config.yaml") Expect(err).To(BeNil()) @@ -38,7 +38,7 @@ var _ = Describe("Config", func() { }) It("can convert pups config to dockerfile format", func() { - dockerfile := conf.Dockerfile("", false) + dockerfile := conf.Dockerfile("", false, "config.yaml") Expect(dockerfile).To(ContainSubstring("ARG DISCOURSE_DEVELOPER_EMAILS")) Expect(dockerfile).To(ContainSubstring("RUN cat /temp-config.yaml")) Expect(dockerfile).To(ContainSubstring("EXPOSE 80"))