add tag to args passed for package builds

Signed-off-by: Avi Deitcher <avi@deitcher.net>
This commit is contained in:
Avi Deitcher 2024-04-16 13:43:37 +03:00
parent de79880fff
commit 6af6291afe
3 changed files with 15 additions and 0 deletions

View File

@ -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.

View File

@ -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 {

View File

@ -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())