Skip to content

Commit 67d86c5

Browse files
committed
Add new rules, GitHub Actions, install script, and frontend updates
1 parent d36721a commit 67d86c5

9 files changed

Lines changed: 65 additions & 27 deletions

File tree

.github/workflows/examples/example-basic-lint.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ jobs:
1313
- name: Checkout code
1414
uses: actions/checkout@v3
1515

16-
- name: Run LayerLint
17-
uses: vviveksharma/layerLint@main
18-
with:
19-
dockerfile: ./Dockerfile
20-
fail-on-severity: high
16+
- name: Install LayerLint
17+
run: |
18+
curl -sSL https://github.com/vviveksharma/layerLint/releases/download/v1.0.0/layerLint_1.0.0_Linux_x86_64.tar.gz | tar xz
19+
chmod +x layerlint
20+
21+
- name: Scan Dockerfile
22+
run: ./layerlint scan --dockerfile ./Dockerfile --fail-on-severity high

.github/workflows/examples/example-build-deploy.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ jobs:
1818
- name: Checkout code
1919
uses: actions/checkout@v3
2020

21-
- name: Run LayerLint
22-
uses: vviveksharma/layerLint@main
23-
with:
24-
dockerfile: ./Dockerfile
25-
fail-on-severity: high
21+
- name: Install LayerLint
22+
run: |
23+
curl -sSL https://github.com/vviveksharma/layerLint/releases/download/v1.0.0/layerLint_1.0.0_Linux_x86_64.tar.gz | tar xz
24+
chmod +x layerlint
25+
26+
- name: Scan Dockerfile
27+
run: ./layerlint scan --dockerfile ./Dockerfile --fail-on-severity high
2628

2729
- name: Comment PR with findings
2830
if: github.event_name == 'pull_request'

.github/workflows/examples/example-multi-dockerfile.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ jobs:
3333
- name: Checkout code
3434
uses: actions/checkout@v3
3535

36-
- name: Run LayerLint on ${{ matrix.dockerfile }}
37-
uses: vviveksharma/layerLint@main
38-
with:
39-
dockerfile: ${{ matrix.dockerfile }}
40-
fail-on-severity: medium
36+
- name: Install LayerLint
37+
run: |
38+
curl -sSL https://github.com/vviveksharma/layerLint/releases/download/v1.0.0/layerLint_1.0.0_Linux_x86_64.tar.gz | tar xz
39+
chmod +x layerlint
40+
41+
- name: Scan ${{ matrix.dockerfile }}
42+
run: ./layerlint scan --dockerfile ${{ matrix.dockerfile }} --fail-on-severity medium

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Set up Go
2121
uses: actions/setup-go@v5
2222
with:
23-
go-version: '1.26.2'
23+
go-version: '1.26.3'
2424

2525
- name: Run GoReleaser
2626
uses: goreleaser/goreleaser-action@v6

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,12 @@ jobs:
6969
runs-on: ubuntu-latest
7070
steps:
7171
- uses: actions/checkout@v3
72-
- uses: vviveksharma/layerLint@main
73-
with:
74-
dockerfile: ./Dockerfile
72+
- name: Install LayerLint
73+
run: |
74+
curl -sSL https://github.com/vviveksharma/layerLint/releases/latest/download/layerLint_Linux_x86_64.tar.gz | tar xz
75+
chmod +x layerlint
76+
- name: Scan Dockerfile
77+
run: ./layerlint scan --dockerfile ./Dockerfile --fail-on-severity high
7578
```
7679
7780
**Ready-to-use examples** in [`.github/workflows/examples/`](.github/workflows/examples/):

cmd/layerlint/cmd/root.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package cmd
22

3-
import "github.com/spf13/cobra"
3+
import (
4+
"os"
5+
6+
"github.com/spf13/cobra"
7+
)
48

59
var rootCmd = &cobra.Command{
610
Use: "layerLint",
@@ -9,5 +13,7 @@ var rootCmd = &cobra.Command{
913

1014
func Execute() {
1115
rootCmd.AddCommand(scanCmd)
12-
rootCmd.Execute()
16+
if err := rootCmd.Execute(); err != nil {
17+
os.Exit(1)
18+
}
1319
}

cmd/layerlint/cmd/scan.go

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ var (
1515
dockerfilePath string
1616
outputFormat string
1717
outputPath string
18+
failOnSeverity string
1819
)
1920

2021
var scanCmd = &cobra.Command{
@@ -66,15 +67,36 @@ Supports multiple output formats:
6667
return fmt.Errorf("failed to generate report: %w", err)
6768
}
6869

69-
// Exit with error code if high severity issues found (for CI/CD)
70-
if hasHighSeverity(findings) {
71-
return fmt.Errorf("found high severity issues")
70+
// Exit with error code based on severity threshold (for CI/CD)
71+
if shouldFail(findings, failOnSeverity) {
72+
return fmt.Errorf("found issues at or above '%s' severity", failOnSeverity)
7273
}
7374

7475
return nil
7576
},
7677
}
7778

79+
func shouldFail(findings []models.Finding, threshold string) bool {
80+
if len(findings) == 0 {
81+
return false
82+
}
83+
84+
severityLevels := map[string]int{
85+
"low": 1,
86+
"medium": 2,
87+
"high": 3,
88+
}
89+
90+
thresholdLevel := severityLevels[threshold]
91+
92+
for _, f := range findings {
93+
if severityLevels[f.Severity] >= thresholdLevel {
94+
return true
95+
}
96+
}
97+
return false
98+
}
99+
78100
func hasHighSeverity(findings []models.Finding) bool {
79101
for _, f := range findings {
80102
if f.Severity == "high" {
@@ -88,5 +110,6 @@ func init() {
88110
scanCmd.Flags().StringVar(&dockerfilePath, "dockerfile", "Dockerfile", "Path to Dockerfile")
89111
scanCmd.Flags().StringVarP(&outputFormat, "format", "f", "text", "Output format (text, json, sarif, html)")
90112
scanCmd.Flags().StringVarP(&outputPath, "output", "o", "", "Output file path (default: stdout)")
113+
scanCmd.Flags().StringVar(&failOnSeverity, "fail-on-severity", "medium", "Fail if issues at or above this severity are found (low, medium, high)")
91114
scanCmd.MarkFlagRequired("dockerfile")
92115
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/vviveksharma/layerLint
33
go 1.26.3
44

55
require (
6-
github.com/moby/buildkit v0.29.0
6+
github.com/moby/buildkit v0.30.0
77
github.com/spf13/cobra v1.10.2
88
)
99

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2
1111
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
1212
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
1313
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
14-
github.com/moby/buildkit v0.29.0 h1:wxLEFbCOJntEDjSNNN2YWd8zxltZxT5muDQ0LzpbtpU=
15-
github.com/moby/buildkit v0.29.0/go.mod h1:Dmv2FeDe34t75QuzeU87rBoZpAAkcpT5zeu4hXzmASc=
14+
github.com/moby/buildkit v0.30.0 h1:OsK8T3BaYH52UNStpKd7gytDtHWWt2Fawak/lAPWatU=
15+
github.com/moby/buildkit v0.30.0/go.mod h1:k2wuw5ddaOqzh58RLt+mBn2XhK34gi6+gd0faONQ1xU=
1616
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
1717
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
1818
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 h1:GFCKgmp0tecUJ0sJuv4pzYCqS9+RGSn52M3FUwPs+uo=

0 commit comments

Comments
 (0)