Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.1.0] - 2026-10-24

First release. The Changed, Removed and Fixed sections describe differences from
the unreleased code on `main` before this version, for anyone who built it from
source.

### Added
- Initial project structure
- Dockerfile parser with multi-stage build support
- Lint rules for base images, layer optimization, security, and best practices
- CLI with file and stdin input support
Expand Down Expand Up @@ -47,6 +52,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
`--no-config` flags
- The GitHub Action lints several paths or patterns (one per line) and takes a
`config` input
- `--version` falls back to the version Go records in the binary, so builds from
`go install github.com/devblac/docker-lint/cmd/docker-lint@v0.1.0` report it

### Changed
- **Breaking:** rule IDs move from `DLxxxx`, which collide with hadolint's IDs for
Expand All @@ -73,9 +80,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
corpus they fired on 51 and 39 of 52 files, and Kubernetes ignores HEALTHCHECK
- DKL103 judges only the base of the final image

### Deprecated
- N/A

### Removed
- Hand-written Dockerfile lexer (`internal/parser/lexer.go`), superseded by BuildKit

Expand Down Expand Up @@ -103,5 +107,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
(`COPY go.mod go.sum ./`, `COPY package*.json ./`) because it inspected the
destination instead of the sources

### Security
- N/A
[Unreleased]: https://github.com/devblac/docker-lint/compare/v0.1.0...HEAD
[0.1.0]: https://github.com/devblac/docker-lint/releases/tag/v0.1.0
28 changes: 27 additions & 1 deletion cmd/docker-lint/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"io"
"os"
"runtime/debug"
"strings"

"github.com/devblac/docker-lint/internal/analyzer"
Expand Down Expand Up @@ -402,7 +403,32 @@ Exit Codes:
}

func printVersion(w io.Writer) {
fmt.Fprintf(w, "docker-lint version %s (commit %s, built %s)\n", version, commit, date)
info, _ := debug.ReadBuildInfo()
v, c, d := buildVersion(info)
fmt.Fprintf(w, "docker-lint version %s (commit %s, built %s)\n", v, c, d)
}

// buildVersion returns the version, commit and build date to report. Release
// builds set them with -ldflags. Other builds fall back to what Go records in
// the binary: the module version for "go install ...@v0.1.0", and the VCS
// revision and commit time for a build inside a Git checkout.
func buildVersion(info *debug.BuildInfo) (v, c, d string) {
v, c, d = version, commit, date
if info == nil {
return v, c, d
}
if v == "dev" && info.Main.Version != "" && info.Main.Version != "(devel)" {
v = strings.TrimPrefix(info.Main.Version, "v")
}
for _, setting := range info.Settings {
switch {
case setting.Key == "vcs.revision" && c == "none":
c = setting.Value
case setting.Key == "vcs.time" && d == "unknown":
d = setting.Value
}
}
return v, c, d
}

func listRules(w io.Writer) {
Expand Down
59 changes: 59 additions & 0 deletions cmd/docker-lint/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"os"
"path/filepath"
"runtime/debug"
"strings"
"testing"
)
Expand Down Expand Up @@ -866,3 +867,61 @@ func TestSARIFKeepsExitCode(t *testing.T) {
t.Errorf("expected an error-level result:\n%s", stdout.String())
}
}

// TestBuildVersionFallback verifies binaries built without -ldflags, such as
// by "go install ...@v0.1.0", report the version Go recorded in the binary.
func TestBuildVersionFallback(t *testing.T) {
origVersion, origCommit, origDate := version, commit, date
defer func() {
version, commit, date = origVersion, origCommit, origDate
}()

tests := []struct {
name string
ldflags [3]string
info *debug.BuildInfo
wantV, wantC, wantD string
}{
{
name: "go install from the module proxy",
ldflags: [3]string{"dev", "none", "unknown"},
info: &debug.BuildInfo{Main: debug.Module{Version: "v0.1.0"}},
wantV: "0.1.0", wantC: "none", wantD: "unknown",
},
{
name: "go build in a checkout",
ldflags: [3]string{"dev", "none", "unknown"},
info: &debug.BuildInfo{
Main: debug.Module{Version: "(devel)"},
Settings: []debug.BuildSetting{
{Key: "vcs.revision", Value: "abc123"},
{Key: "vcs.time", Value: "2026-10-24T18:00:00Z"},
},
},
wantV: "dev", wantC: "abc123", wantD: "2026-10-24T18:00:00Z",
},
{
name: "ldflags win",
ldflags: [3]string{"0.2.0", "def456", "2026-11-01"},
info: &debug.BuildInfo{
Main: debug.Module{Version: "v0.1.0"},
Settings: []debug.BuildSetting{{Key: "vcs.revision", Value: "abc123"}},
},
wantV: "0.2.0", wantC: "def456", wantD: "2026-11-01",
},
{
name: "no build info",
ldflags: [3]string{"dev", "none", "unknown"},
wantV: "dev", wantC: "none", wantD: "unknown",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
version, commit, date = tt.ldflags[0], tt.ldflags[1], tt.ldflags[2]
v, c, d := buildVersion(tt.info)
if v != tt.wantV || c != tt.wantC || d != tt.wantD {
t.Errorf("buildVersion() = %q, %q, %q; want %q, %q, %q", v, c, d, tt.wantV, tt.wantC, tt.wantD)
}
})
}
}
2 changes: 2 additions & 0 deletions scripts/release-notes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ notes="$(awk -v version="$version" '
if (found) exit
if (index($0, "## [" version "]") == 1) { found = 1; next }
}
# Link reference definitions at the end of the file belong to no section.
found && /^\[[^]]+\]: / { next }
found { print }
' "$changelog")"

Expand Down
Loading