Skip to content

Conversation

@shivasurya
Copy link
Owner

@shivasurya shivasurya commented Dec 8, 2025

Executive Summary

This PR introduces the foundational data structures needed for Dockerfile parsing and analysis. It contains ZERO behavioral changes to the existing codebase - only new type definitions, constructors, and tests.

File Structure

Following the existing pattern (java/, python/), files are organized in:

sast-engine/graph/docker/
├── node.go           (DockerfileNode - unified instruction representation)
├── graph.go          (DockerfileGraph + BuildStage - multi-stage support)
├── node_test.go      (Comprehensive tests)
└── graph_test.go     (Comprehensive tests)

Why This is Safe

  • ✅ No modifications to existing files
  • ✅ No integration with existing logic
  • ✅ All new code is isolated in new package
  • ✅ 100% test coverage on all new code
  • ✅ All tests pass: gradle buildGo && gradle testGo && gradle lintGo

Quality Metrics

Metric Result
Build Status ✅ BUILD SUCCESSFUL
Test Coverage ✅ 100%
Linting ✅ 0 issues
Test Execution ✅ All tests PASS

Code Examples

Creating a FROM instruction node:

node := docker.NewDockerfileNode("FROM", 1)
node.BaseImage = "ubuntu"
node.ImageTag = "20.04"
node.StageAlias = "builder"

Building a Dockerfile graph:

graph := docker.NewDockerfileGraph("/path/to/Dockerfile")
graph.AddInstruction(fromNode)
graph.AddInstruction(runNode)

// Security check
if graph.IsRunningAsRoot() {
    // Container runs as root
}

Multi-stage build analysis:

stages := graph.GetStages()
for _, stage := range stages {
    fmt.Printf("Stage %s: %s:%s\n", 
        stage.Alias, stage.BaseImage, stage.ImageTag)
}

Part of Stack

Dockerfile & Docker Compose Support implementation:

Testing Coverage

  • ✅ Constructor and initialization tests
  • ✅ Flag operations (GetFlag, HasFlag)
  • ✅ Helper methods (IsRootUser, UsesLatestTag)
  • ✅ Graph operations (AddInstruction, GetInstructions)
  • ✅ Multi-stage analysis (AnalyzeBuildStages, GetStageByAlias)
  • ✅ Edge cases (empty graph, single stage, no USER instruction)

Adds foundational data structures for Dockerfile parsing in docker/ subdirectory following the existing pattern (java/, python/).

Files added:
- sast-engine/graph/docker/node.go (DockerfileNode - unified instruction representation)
- sast-engine/graph/docker/graph.go (DockerfileGraph - complete Dockerfile with indexes, BuildStage - multi-stage support)
- sast-engine/graph/docker/node_test.go (comprehensive tests for DockerfileNode)
- sast-engine/graph/docker/graph_test.go (comprehensive tests for DockerfileGraph)

All structures have 100% test coverage.

Part of: Dockerfile & Docker Compose Support
Next PR: #2 Tree-sitter Integration
@shivasurya shivasurya self-assigned this Dec 8, 2025
@shivasurya shivasurya added docker Docker/Dockerfile related changes enhancement New feature or request go Pull requests that update go code labels Dec 8, 2025
@shivasurya shivasurya marked this pull request as ready for review December 8, 2025 13:49
@safedep
Copy link

safedep bot commented Dec 8, 2025

SafeDep Report Summary

Green Malicious Packages Badge Green Vulnerable Packages Badge Green Risky License Badge

No dependency changes detected. Nothing to scan.

This report is generated by SafeDep Github App

@codecov
Copy link

codecov bot commented Dec 8, 2025

Codecov Report

❌ Patch coverage is 93.10345% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.61%. Comparing base (3004338) to head (097fbb0).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
sast-engine/graph/docker/node.go 82.60% 2 Missing and 2 partials ⚠️
sast-engine/graph/docker/graph.go 96.87% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #416      +/-   ##
==========================================
+ Coverage   80.47%   80.61%   +0.13%     
==========================================
  Files          77       79       +2     
  Lines        7763     7850      +87     
==========================================
+ Hits         6247     6328      +81     
- Misses       1269     1272       +3     
- Partials      247      250       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Owner Author

shivasurya commented Dec 10, 2025

Merge activity

  • Dec 10, 6:17 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Dec 10, 6:17 AM UTC: @shivasurya merged this pull request with Graphite.

@shivasurya shivasurya merged commit d6edfab into main Dec 10, 2025
5 checks passed
@shivasurya shivasurya deleted the docker/01-core-data-structures branch December 10, 2025 06:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docker Docker/Dockerfile related changes enhancement New feature or request go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants