Skip to content
This repository was archived by the owner on Jun 22, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions internal/command/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
8 changes: 8 additions & 0 deletions internal/command/args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions internal/options/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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, ",")
}
Expand Down
2 changes: 2 additions & 0 deletions internal/options/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
}

Expand Down