Skip to content

Commit

Permalink
ignore commented images (AST-65541) (#31)
Browse files Browse the repository at this point in the history
* ignore commented images

* change test
  • Loading branch information
davidkesoshvili authored Aug 27, 2024
1 parent 517e14d commit 675b571
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
9 changes: 7 additions & 2 deletions internal/extractors/dockerfile_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package extractors
import (
"bufio"
"fmt"
"github.com/CheckmarxDev/containers-resolver/internal/logger"
"github.com/CheckmarxDev/containers-resolver/internal/types"
"os"
"path/filepath"
"regexp"
"strings"

"github.com/CheckmarxDev/containers-resolver/internal/logger"
"github.com/CheckmarxDev/containers-resolver/internal/types"
)

func ExtractImagesFromDockerfiles(logger *logger.Logger, filePaths []types.FilePath, envFiles map[string]map[string]string) ([]types.ImageModel, error) {
Expand Down Expand Up @@ -59,6 +60,10 @@ func extractImagesFromDockerfile(logger *logger.Logger, filePath types.FilePath,
// Replace placeholders with values from mergedEnvVars and argsAndEnv
line = replacePlaceholders(line, mergedEnvVars, argsAndEnv)

if strings.HasPrefix(strings.TrimSpace(line), "#") {
continue
}

// Parse FROM instructions
if match := regexp.MustCompile(`^\s*FROM\s+(?:--platform=[^\s]+\s+)?([\w./-]+(?::[\w.-]+)?)(?:\s+AS\s+(\w+))?`).FindStringSubmatch(line); match != nil {
imageName := match[1]
Expand Down
1 change: 1 addition & 0 deletions test_files/imageExtraction/dockerfiles/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# FROM ddd:test
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
# Install ReSharper GlobalTools
RUN dotnet tool install --global JetBrains.ReSharper.GlobalTools --version 2021.3.0
Expand Down

0 comments on commit 675b571

Please sign in to comment.