Skip to content

Commit

Permalink
Fix get-deps tool to handle non LinuxKit containers
Browse files Browse the repository at this point in the history
If the package is built outside EVE source tree the tool still adds it
to dependencies and later Makefile fails to find target.
We have lfedge/eve-rust container that is affected but this bug
We just check that the package really exists in EVE source tree

This commit also fixes the following incorrect dependency

pkg/external-boot-image: pkg/kernel

Also add some tests

Signed-off-by: Mikhail Malyshev <[email protected]>
  • Loading branch information
rucoder committed Aug 27, 2024
1 parent 8c5b27a commit a6c953f
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 11 deletions.
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 doens't exist for lfedge packages outside eve source tree e.g. eve-rust

Check failure on line 210 in tools/get-deps/main.go

View workflow job for this annotation

GitHub Actions / yetus

codespell: doens't ==> doesn't
if _, err := os.Stat(str); err != nil {
continue
}
if !dpList[str] {
dpList[str] = true
depList = append(depList, str)
Expand Down
63 changes: 53 additions & 10 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,29 @@ 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
//
os.Chdir("../..")

Check failure on line 62 in tools/get-deps/main_test.go

View workflow job for this annotation

GitHub Actions / yetus

golangcilint: Error return value of `os.Chdir` is not checked (errcheck)

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)

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)
}
}
}

0 comments on commit a6c953f

Please sign in to comment.