diff --git a/docs/packages.md b/docs/packages.md index aa8f55d0d..3b5e96ff8 100644 --- a/docs/packages.md +++ b/docs/packages.md @@ -272,6 +272,8 @@ When building packages, the following build-args automatically are set for you: * `SOURCE` - the source repository of the package * `REVISION` - the git commit that was used for the build * `GOPKGVERSION` - the go package version or pseudo-version per https://go.dev/ref/mod#glos-pseudo-version +* `PKG_HASH` - the git tree hash of the package directory, e.g. `45a1ad5919f0b6acf0f0cf730e9434abfae11fe6`; tag part of `linuxkit pkg show-tag` +* `PKG_IMAGE` - the name of the image that is being built, e.g. `linuxkit/init`; image name part of `linuxkit pkg show-tag`. Combine with `PKG_HASH` for the full tag. Note that the above are set **only** if you do not set them in `build.yaml`. Your settings _always_ override these built-in ones. diff --git a/src/cmd/linuxkit/pkglib/build.go b/src/cmd/linuxkit/pkglib/build.go index 8945b5628..238dfa67d 100644 --- a/src/cmd/linuxkit/pkglib/build.go +++ b/src/cmd/linuxkit/pkglib/build.go @@ -431,6 +431,14 @@ func (p Pkg) Build(bos ...BuildOpt) error { if _, ok := imageBuildOpts.BuildArgs["GOPKGVERSION"]; !ok && goPkgVersion != "" { imageBuildOpts.BuildArgs["GOPKGVERSION"] = &goPkgVersion } + if _, ok := imageBuildOpts.BuildArgs["PKG_HASH"]; !ok && p.Hash() != "" { + ret := p.Hash() + imageBuildOpts.BuildArgs["PKG_HASH"] = &ret + } + if _, ok := imageBuildOpts.BuildArgs["PKG_IMAGE"]; !ok && p.Image() != "" { + ret := p.Image() + imageBuildOpts.BuildArgs["PKG_IMAGE"] = &ret + } // build for each arch and save in the linuxkit cache for _, platform := range platformsToBuild { diff --git a/src/cmd/linuxkit/pkglib/pkglib.go b/src/cmd/linuxkit/pkglib/pkglib.go index 3e675ac53..c12c98c6b 100644 --- a/src/cmd/linuxkit/pkglib/pkglib.go +++ b/src/cmd/linuxkit/pkglib/pkglib.go @@ -317,6 +317,11 @@ func (p Pkg) Tag() string { return p.org + "/" + p.image + ":" + t } +// Image returns the image name without the tag +func (p Pkg) Image() string { + return p.org + "/" + p.image +} + // FullTag returns a reference expanded tag func (p Pkg) FullTag() string { return util.ReferenceExpand(p.Tag())