From 39fcdd7ce75080431684fc7591b92bfcac01d396 Mon Sep 17 00:00:00 2001 From: Peter Baumgartner Date: Mon, 10 Jul 2023 21:13:06 +0000 Subject: [PATCH] Pass all config vars as build args to Docker --- builder/containers/containers.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/builder/containers/containers.go b/builder/containers/containers.go index 53a4866..addaf00 100644 --- a/builder/containers/containers.go +++ b/builder/containers/containers.go @@ -196,16 +196,21 @@ func (c *Containers) DeleteContainer(containerID string) error { func (c *Containers) BuildImage(dockerfile string, config *BuildConfig) error { c.Log().Debug().Str("image", config.Image).Msg("building Docker image") - cmd := exec.Command( - "docker", "buildx", "build", + dockerArgs := []string{ + "buildx", + "build", "--tag", config.Image, "--progress", "plain", "--cache-to", fmt.Sprintf("type=local,dest=%s", config.CacheDir), "--cache-from", fmt.Sprintf("type=local,src=%s", config.CacheDir), "--file", dockerfile, "--load", - ".", - ) + } + for k, v := range config.Env { + dockerArgs = append(dockerArgs, "--build-arg", fmt.Sprintf("%s=%s", k, v)) + } + dockerArgs = append(dockerArgs, ".") + cmd := exec.Command("docker", dockerArgs...) out := io.MultiWriter(os.Stdout, config.LogFile) cmd.Stdout = out cmd.Stderr = out