diff --git a/pkg/command/analyzer_test.go b/pkg/command/analyzer_test.go new file mode 100644 index 0000000..85f5015 --- /dev/null +++ b/pkg/command/analyzer_test.go @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2022 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v20.html + * + * Contributors: + * Red Hat, Inc. + ******************************************************************************/ +package command + +import "testing" + +func TestCheckNginx(t *testing.T) { + for _, tag := range []string{"1.25.0", "1.25.1", "1.25.2", "1.25.3"} { + t.Run(tag, func(t *testing.T) { + AnalyzeImage("docker.io/nginx:" + tag) + }) + } +} diff --git a/pkg/decompiler/utils/utils.go b/pkg/decompiler/utils/utils.go index a5a8df3..72b06cd 100644 --- a/pkg/decompiler/utils/utils.go +++ b/pkg/decompiler/utils/utils.go @@ -3,6 +3,7 @@ package utils import ( "github.com/moby/buildkit/frontend/dockerfile/parser" "github.com/redhat-developer/docker-openshift-analyzer/pkg/utils" + "regexp" "strings" ) @@ -26,7 +27,12 @@ var CONTAINERFILE_INSTRUCTIONS = []string{ utils.SHELL_INSTRUCTION, } +var LABEL_PATTERN = regexp.MustCompile("^LABEL\\s+(.*)=(.*)$") + func Line2Node(line string, root *parser.Node) error { + if strings.HasPrefix(line, utils.LABEL_INSTRUCTION) { + return parseLabel(line, root) + } result, err := parser.Parse(strings.NewReader(line)) if err != nil { return err @@ -37,10 +43,26 @@ func Line2Node(line string, root *parser.Node) error { return nil } +func parseLabel(line string, root *parser.Node) error { + elements := LABEL_PATTERN.FindStringSubmatch(line) + parent := &parser.Node{ + Value: "LABEL", + } + node := parent + for _, element := range elements[1:] { + node.Next = &parser.Node{ + Value: element, + } + node = node.Next + } + root.AddChild(parent, 0, 0) + return nil +} + func ExtractCmd(str string) string { index := strings.Index(str, utils.NOP) if index > 0 { - return str[index+len(utils.NOP):] + return strings.TrimSpace(str[index+len(utils.NOP):]) } index = strings.Index(str, utils.RUN_PREFIX) if index >= 0 {