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 diff --git a/internal/command/args.go b/internal/command/args.go index b6871f8..7d98949 100644 --- a/internal/command/args.go +++ b/internal/command/args.go @@ -37,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 6d84197..693949f 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: ".", + CacheFroms: []string{"foo/bar-1", "foo/bar-2"}, + }, + expected: []string{"build", "--progress", "plain", "--cache-from", "foo/bar-1", "--cache-from", "foo/bar-2", "."}, + }, } for _, tc := range testCases { tc := tc diff --git a/internal/options/build.go b/internal/options/build.go index 313f70e..16a73b4 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"` + CacheFroms []string BuildArgs []string Labels []string } @@ -28,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 ed5faa6..b29f9fe 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_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") @@ -29,6 +30,7 @@ func TestGetBuildOptions(t *testing.T) { AlwaysPull: true, BuildArgs: []string{"buildarg1=b1", "buildarg2=b2"}, Labels: []string{"label1=l1", "label2=l2"}, + CacheFroms: []string{"foo/bar-1", "foo/bar-2"}, }, o) }