Skip to content
This repository was archived by the owner on Jun 22, 2021. It is now read-only.

Commit 0f18e2a

Browse files
authored
Merge pull request #17 from appleboy/cache
chore: support --cache-from arg
2 parents 468bbd1 + 9f2d8e0 commit 0f18e2a

File tree

5 files changed

+20
-0
lines changed

5 files changed

+20
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Builds and tags a docker image.
3535
|INPUT_TARGET|no|Target build stage to build|
3636
|INPUT_BUILD_ARGS|no|Comma-delimited list of build-args|
3737
|INPUT_LABELS|no|Comma-delimited list of labels|
38+
|INPUT_CACHE_FROMS|no|Comma-delimited list of cache-froms|
3839

3940
See the tagging section for information on tag inputs
4041

internal/command/args.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ func BuildArgs(o options.Build, github options.GitHub, tags []string) []string {
3737
args = append(args, "--pull")
3838
}
3939

40+
for _, cacheFrom := range o.CacheFroms {
41+
args = append(args, "--cache-from", cacheFrom)
42+
}
43+
4044
for _, buildArg := range o.BuildArgs {
4145
args = append(args, "--build-arg", buildArg)
4246
}

internal/command/args_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ func TestBuildArgs(t *testing.T) {
7777
},
7878
expected: []string{"build", "--progress", "plain", "--build-arg", "build-arg-1", "--build-arg", "build-arg-2", "."},
7979
},
80+
{
81+
name: "with-cache-from",
82+
build: options.Build{
83+
Path: ".",
84+
CacheFroms: []string{"foo/bar-1", "foo/bar-2"},
85+
},
86+
expected: []string{"build", "--progress", "plain", "--cache-from", "foo/bar-1", "--cache-from", "foo/bar-2", "."},
87+
},
8088
}
8189
for _, tc := range testCases {
8290
tc := tc

internal/options/build.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type Build struct {
1717
AddGitLabels bool `env:"INPUT_ADD_GIT_LABELS"`
1818
Target string `env:"INPUT_TARGET"`
1919
AlwaysPull bool `env:"INPUT_ALWAYS_PULL"`
20+
CacheFroms []string
2021
BuildArgs []string
2122
Labels []string
2223
}
@@ -28,6 +29,10 @@ func GetBuildOptions() (Build, error) {
2829
return build, err
2930
}
3031

32+
if cacheFroms := os.Getenv("INPUT_CACHE_FROMS"); cacheFroms != "" {
33+
build.CacheFroms = strings.Split(cacheFroms, ",")
34+
}
35+
3136
if buildArgs := os.Getenv("INPUT_BUILD_ARGS"); buildArgs != "" {
3237
build.BuildArgs = strings.Split(buildArgs, ",")
3338
}

internal/options/build_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
func TestGetBuildOptions(t *testing.T) {
1313
_ = os.Setenv("INPUT_PATH", "path")
1414
_ = os.Setenv("INPUT_DOCKERFILE", "dockerfile")
15+
_ = os.Setenv("INPUT_CACHE_FROMS", "foo/bar-1,foo/bar-2")
1516
_ = os.Setenv("INPUT_REPOSITORY", "repository")
1617
_ = os.Setenv("INPUT_BUILD_ARGS", "buildarg1=b1,buildarg2=b2")
1718
_ = os.Setenv("INPUT_LABELS", "label1=l1,label2=l2")
@@ -29,6 +30,7 @@ func TestGetBuildOptions(t *testing.T) {
2930
AlwaysPull: true,
3031
BuildArgs: []string{"buildarg1=b1", "buildarg2=b2"},
3132
Labels: []string{"label1=l1", "label2=l2"},
33+
CacheFroms: []string{"foo/bar-1", "foo/bar-2"},
3234
}, o)
3335
}
3436

0 commit comments

Comments
 (0)