From f518c1b9a7aad1277502c5da37330a0f2295a933 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sun, 29 Mar 2020 18:43:29 +0800 Subject: [PATCH 1/3] chore: support --cache-from arg Signed-off-by: Bo-Yi Wu --- internal/command/args.go | 4 ++++ internal/command/args_test.go | 8 ++++++++ internal/options/build.go | 1 + internal/options/build_test.go | 2 ++ 4 files changed, 15 insertions(+) diff --git a/internal/command/args.go b/internal/command/args.go index b6871f8..150e723 100644 --- a/internal/command/args.go +++ b/internal/command/args.go @@ -29,6 +29,10 @@ func BuildArgs(o options.Build, github options.GitHub, tags []string) []string { args = append(args, "--file", o.Dockerfile) } + if o.CacheFrom != "" { + args = append(args, "--cache-from", o.CacheFrom) + } + if o.Target != "" { args = append(args, "--target", o.Target) } diff --git a/internal/command/args_test.go b/internal/command/args_test.go index 6d84197..e57d5ba 100644 --- a/internal/command/args_test.go +++ b/internal/command/args_test.go @@ -77,6 +77,14 @@ func TestBuildArgs(t *testing.T) { }, expected: []string{"build", "--progress", "plain", "--build-arg", "build-arg-1", "--build-arg", "build-arg-2", "."}, }, + { + name: "with-cache-from", + build: options.Build{ + Path: ".", + CacheFrom: "foo/bar", + }, + expected: []string{"build", "--progress", "plain", "--cache-from", "foo/bar", "."}, + }, } for _, tc := range testCases { tc := tc diff --git a/internal/options/build.go b/internal/options/build.go index 313f70e..f23e56d 100644 --- a/internal/options/build.go +++ b/internal/options/build.go @@ -17,6 +17,7 @@ type Build struct { AddGitLabels bool `env:"INPUT_ADD_GIT_LABELS"` Target string `env:"INPUT_TARGET"` AlwaysPull bool `env:"INPUT_ALWAYS_PULL"` + CacheFrom string `env:"INPUT_CACHE_FROM"` BuildArgs []string Labels []string } diff --git a/internal/options/build_test.go b/internal/options/build_test.go index ed5faa6..a80b0cd 100644 --- a/internal/options/build_test.go +++ b/internal/options/build_test.go @@ -12,6 +12,7 @@ import ( func TestGetBuildOptions(t *testing.T) { _ = os.Setenv("INPUT_PATH", "path") _ = os.Setenv("INPUT_DOCKERFILE", "dockerfile") + _ = os.Setenv("INPUT_CACHE_FROM", "foo/bar") _ = os.Setenv("INPUT_REPOSITORY", "repository") _ = os.Setenv("INPUT_BUILD_ARGS", "buildarg1=b1,buildarg2=b2") _ = os.Setenv("INPUT_LABELS", "label1=l1,label2=l2") @@ -29,6 +30,7 @@ func TestGetBuildOptions(t *testing.T) { AlwaysPull: true, BuildArgs: []string{"buildarg1=b1", "buildarg2=b2"}, Labels: []string{"label1=l1", "label2=l2"}, + CacheFrom: "foo/bar", }, o) } From f05453caffb843189c22e0d7be18fbd12c34474c Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sat, 18 Apr 2020 01:45:18 +0800 Subject: [PATCH 2/3] chore: update Signed-off-by: Bo-Yi Wu --- internal/command/args.go | 8 ++++---- internal/command/args_test.go | 6 +++--- internal/options/build.go | 6 +++++- internal/options/build_test.go | 4 ++-- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/internal/command/args.go b/internal/command/args.go index 150e723..7d98949 100644 --- a/internal/command/args.go +++ b/internal/command/args.go @@ -29,10 +29,6 @@ func BuildArgs(o options.Build, github options.GitHub, tags []string) []string { args = append(args, "--file", o.Dockerfile) } - if o.CacheFrom != "" { - args = append(args, "--cache-from", o.CacheFrom) - } - if o.Target != "" { args = append(args, "--target", o.Target) } @@ -41,6 +37,10 @@ func BuildArgs(o options.Build, github options.GitHub, tags []string) []string { args = append(args, "--pull") } + for _, cacheFrom := range o.CacheFroms { + args = append(args, "--cache-from", cacheFrom) + } + for _, buildArg := range o.BuildArgs { args = append(args, "--build-arg", buildArg) } diff --git a/internal/command/args_test.go b/internal/command/args_test.go index e57d5ba..693949f 100644 --- a/internal/command/args_test.go +++ b/internal/command/args_test.go @@ -80,10 +80,10 @@ func TestBuildArgs(t *testing.T) { { name: "with-cache-from", build: options.Build{ - Path: ".", - CacheFrom: "foo/bar", + Path: ".", + CacheFroms: []string{"foo/bar-1", "foo/bar-2"}, }, - expected: []string{"build", "--progress", "plain", "--cache-from", "foo/bar", "."}, + expected: []string{"build", "--progress", "plain", "--cache-from", "foo/bar-1", "--cache-from", "foo/bar-2", "."}, }, } for _, tc := range testCases { diff --git a/internal/options/build.go b/internal/options/build.go index f23e56d..16a73b4 100644 --- a/internal/options/build.go +++ b/internal/options/build.go @@ -17,7 +17,7 @@ type Build struct { AddGitLabels bool `env:"INPUT_ADD_GIT_LABELS"` Target string `env:"INPUT_TARGET"` AlwaysPull bool `env:"INPUT_ALWAYS_PULL"` - CacheFrom string `env:"INPUT_CACHE_FROM"` + CacheFroms []string BuildArgs []string Labels []string } @@ -29,6 +29,10 @@ func GetBuildOptions() (Build, error) { return build, err } + if cacheFroms := os.Getenv("INPUT_CACHE_FROMS"); cacheFroms != "" { + build.CacheFroms = strings.Split(cacheFroms, ",") + } + if buildArgs := os.Getenv("INPUT_BUILD_ARGS"); buildArgs != "" { build.BuildArgs = strings.Split(buildArgs, ",") } diff --git a/internal/options/build_test.go b/internal/options/build_test.go index a80b0cd..b29f9fe 100644 --- a/internal/options/build_test.go +++ b/internal/options/build_test.go @@ -12,7 +12,7 @@ import ( func TestGetBuildOptions(t *testing.T) { _ = os.Setenv("INPUT_PATH", "path") _ = os.Setenv("INPUT_DOCKERFILE", "dockerfile") - _ = os.Setenv("INPUT_CACHE_FROM", "foo/bar") + _ = os.Setenv("INPUT_CACHE_FROMS", "foo/bar-1,foo/bar-2") _ = os.Setenv("INPUT_REPOSITORY", "repository") _ = os.Setenv("INPUT_BUILD_ARGS", "buildarg1=b1,buildarg2=b2") _ = os.Setenv("INPUT_LABELS", "label1=l1,label2=l2") @@ -30,7 +30,7 @@ func TestGetBuildOptions(t *testing.T) { AlwaysPull: true, BuildArgs: []string{"buildarg1=b1", "buildarg2=b2"}, Labels: []string{"label1=l1", "label2=l2"}, - CacheFrom: "foo/bar", + CacheFroms: []string{"foo/bar-1", "foo/bar-2"}, }, o) } From 9f2d8e01b68264988dc852f9dbd08042f0d7e888 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Mon, 20 Apr 2020 22:39:45 +0800 Subject: [PATCH 3/3] docs: udpate readme Signed-off-by: Bo-Yi Wu --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 9c1c4fd..e2250f1 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ Builds and tags a docker image. |INPUT_TARGET|no|Target build stage to build| |INPUT_BUILD_ARGS|no|Comma-delimited list of build-args| |INPUT_LABELS|no|Comma-delimited list of labels| +|INPUT_CACHE_FROMS|no|Comma-delimited list of cache-froms| See the tagging section for information on tag inputs