From 68526c3226e6fefc602e2687e1e03a25cfa67423 Mon Sep 17 00:00:00 2001 From: samir elsharkawy Date: Fri, 16 Oct 2020 15:57:27 +0200 Subject: [PATCH] builtin/docker/builder: Add dockerfile variable to BuilderConfig --- builtin/docker/builder.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/builtin/docker/builder.go b/builtin/docker/builder.go index 6c51317cda8..43630228e90 100644 --- a/builtin/docker/builder.go +++ b/builtin/docker/builder.go @@ -5,6 +5,7 @@ import ( "context" "fmt" "os" + "path" "github.com/docker/cli/cli/command/image/build" "github.com/docker/docker/api/types" @@ -38,6 +39,9 @@ type BuilderConfig struct { // Controls whether or not the image should be build with buildkit or docker v1 UseBuildKit bool `hcl:"buildkit,optional"` + + // The name/path to the Dockerfile if it is not the root of the project + Dockerfile string `hcl:"dockerfile,optional"` } func (b *Builder) Documentation() (*docs.Documentation, error) { @@ -110,7 +114,12 @@ func (b *Builder) Build( cli.NegotiateAPIVersion(ctx) - contextDir, relDockerfile, err := build.GetContextFromLocalDir(src.Path, "") + dockerfile := b.config.Dockerfile + if dockerfile != "" { + dockerfile = path.Join(src.Path, dockerfile) + } + + contextDir, relDockerfile, err := build.GetContextFromLocalDir(src.Path, dockerfile) if err != nil { return nil, status.Errorf(codes.FailedPrecondition, "unable to create Docker context: %s", err) }