Skip to content

Commit

Permalink
buildkit: check ADD statements (#137)
Browse files Browse the repository at this point in the history
* check about ADD statement even if built by buildkit
* add manifest test
* use alpine:3.14
  • Loading branch information
tomoyamachi committed Aug 31, 2021
1 parent 2f941a8 commit 06cb752
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ RUN apk --no-cache add git
COPY . .
RUN CGO_ENABLED=0 go build -a -o /dockle ${PWD}/cmd/dockle

FROM alpine:3.13
FROM alpine:3.14
COPY --from=builder /dockle /usr/local/bin/dockle
RUN chmod +x /usr/local/bin/dockle
RUN apk --no-cache add ca-certificates shadow
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.releaser
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM alpine:3.13
FROM alpine:3.14
COPY dockle /usr/bin/dockle
ENTRYPOINT ["/usr/bin/dockle"]
2 changes: 1 addition & 1 deletion pkg/assessor/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func useDistUpgrade(cmdSlices map[int][]string) bool {

func useADDstatement(cmdSlices map[int][]string) bool {
for _, cmdSlice := range cmdSlices {
if containsAll(cmdSlice, []string{"ADD", "in"}) {
if containsThreshold(cmdSlice, []string{"ADD", "in", "buildkit"}, 2) {
return true
}
}
Expand Down
52 changes: 52 additions & 0 deletions pkg/assessor/manifest/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,58 @@ func TestUseDistUpgrade(t *testing.T) {
}
}

func TestContainsThreshold(t *testing.T) {
var tests = map[string]struct {
heystack []string
needles []string
threshold int
expected bool
}{
"SimpleSuccess2": {
heystack: []string{"a", "b", "c", "d"},
needles: []string{"a", "b", "x", "z"},
threshold: 2,
expected: true,
},
"SimpleFail2": {
heystack: []string{"a", "b", "c", "d"},
needles: []string{"a", "x", "y", "z"},
threshold: 3,
expected: false,
},
"SimpleSuccess3": {
heystack: []string{"a", "b", "c", "d"},
needles: []string{"a", "b", "c", "z"},
threshold: 3,
expected: true,
},
"SimpleFail3": {
heystack: []string{"a", "b", "d", "f"},
needles: []string{"a", "b", "c", "z"},
threshold: 3,
expected: false,
},
"DuplicateHeystackSuccess": {
heystack: []string{"a", "a", "b", "c"},
needles: []string{"a", "a", "y", "z"},
threshold: 2,
expected: false,
},
"DuplicateHeystackFail": {
heystack: []string{"a", "a", "b", "c"},
needles: []string{"a", "x", "y", "z"},
threshold: 2,
expected: false,
},
}
for testname, v := range tests {
actual := containsThreshold(v.heystack, v.needles, v.threshold)
if actual != v.expected {
t.Errorf("%s want: %t, got %t", testname, v.expected, actual)
}
}
}

func loadImageFromFile(path string) (config types.Image, err error) {
read, err := os.Open(path)
if err != nil {
Expand Down

0 comments on commit 06cb752

Please sign in to comment.