Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix get-deps tool to handle non LinuxKit containers #4168

Merged
merged 1 commit into from
Aug 28, 2024
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
7 changes: 6 additions & 1 deletion tools/get-deps/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,18 @@ func filterPkg(deps []string) []string {
var depList []string
dpList := make(map[string]bool)

reLF := regexp.MustCompile("lfedge/.*")
reLF := regexp.MustCompile("lfedge/.*")
rePkg := regexp.MustCompile("lfedge/(?:eve-)?(.*):.*")
for _, s := range deps {
// We are just interested on packages from lfegde (those that we
// published)
if reLF.MatchString(s) {
str := rePkg.ReplaceAllString(s, "pkg/$1")
// Check that the directory ./pkg/$1 exists.
// It doesn't exist for lfedge packages outside eve source tree e.g. eve-rust
if _, err := os.Stat(str); err != nil {
continue
}
if !dpList[str] {
dpList[str] = true
depList = append(depList, str)
Expand Down
62 changes: 53 additions & 9 deletions tools/get-deps/main_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,49 @@
package main

import (
"os"
"sort"
"strings"
"testing"
)

func TestParseDockerfile(t *testing.T) {
targets := readDockerFile()

expected := map[string]bool{
"abcd:12345": false,
"f": false,
"f-amd64": false,
"lfedge/eve-alpine:1f7685f95a475c6bbe682f0b976f121": false,
"lfedge/eve-alpine:1f7685f95a475c6bbe682f0b976f121-amd64": false,
"lfedge/eve-rust:1.80.1": false,
"lfedge/eve-xen-tools:": false,
}

for _, target := range targets {
expected[target] = true
}

if len(expected) != len(targets) {
t.Fatalf("expected %d, got %d", len(expected), len(targets))
}

for target, found := range expected {
if !found {
t.Fatalf("did not find target %s", target)
}
}
}

func readDockerFile() []string {
f := strings.NewReader(`
FROM abcd:12345 AS f
RUN echo \
FROM thisshouldnotbeincluded:666666
FROM lfedge/eve-alpine:1f7685f95a475c6bbe682f0b976f121
FROM lfedge/eve-alpine:1f7685f95a475c6bbe682f0b976f121-amd64
FROM lfedge/eve-rust:1.80.1
FROM lfedge/eve-xen-tools:$XENTOOLS

FROM f
RUN echo
Expand All @@ -18,20 +52,30 @@ func TestParseDockerfile(t *testing.T) {
`)

targets := parseDockerfile(f)
return targets
}

foundMap := map[string]bool{
"abcd:12345": false,
"f": false,
"f-amd64": false,
func TestNoneLinuxKitImage(t *testing.T) {
// set current directory to ../..
// so that we can find ./pkg/xxx
if os.Chdir("../..") != nil {
t.Fatalf("could not change working directory")
}

for _, target := range targets {
foundMap[target] = true
targets := readDockerFile()
filtered := filterPkg(targets)
sort.Strings(filtered)

expected := []string{"pkg/alpine", "pkg/xen-tools"}
sort.Strings(expected)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is guaranteed that filterPkg returns a sorted array?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@christoph-zededa no, this is why I sort them at lines 63,66

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, now I see; then it is okay


if len(filtered) != len(expected) {
t.Fatalf("expected %d, got %d [%v, %v]", len(expected), len(filtered), expected, filtered)
}

for target, found := range foundMap {
if !found {
t.Fatalf("did not find target %s", target)
for i, target := range filtered {
if target != expected[i] {
t.Fatalf("expected %s, got %s", expected[i], target)
}
}
}
Loading