mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-18 17:01:07 +00:00
Merge pull request #4089 from deitch/tag-in-build-yml
support --tag in build.yml for packages
This commit is contained in:
commit
dc8c6d5985
@ -50,6 +50,7 @@ A package source consists of a directory containing at least two files:
|
|||||||
|
|
||||||
- `image` _(string)_: *(mandatory)* The name of the image to build
|
- `image` _(string)_: *(mandatory)* The name of the image to build
|
||||||
- `org` _(string)_: The hub/registry organisation to which this package belongs
|
- `org` _(string)_: The hub/registry organisation to which this package belongs
|
||||||
|
- `tag` _(string)_: The tag to use for the image, can be fixed string or template (default: `{{.Hash}}`)
|
||||||
- `dockerfile` _(string)_: The dockerfile to use to build this package, must be in this directory or below (default: `Dockerfile`)
|
- `dockerfile` _(string)_: The dockerfile to use to build this package, must be in this directory or below (default: `Dockerfile`)
|
||||||
- `arches` _(list of string)_: The architectures which this package should be built for (valid entries are `GOARCH` names)
|
- `arches` _(list of string)_: The architectures which this package should be built for (valid entries are `GOARCH` names)
|
||||||
- `extra-sources` _(list of strings)_: Additional sources for the package outside the package directory. The format is `src:dst`, where `src` can be relative to the package directory and `dst` is the destination in the build context. This is useful for sharing files, such as vendored go code, between packages.
|
- `extra-sources` _(list of strings)_: Additional sources for the package outside the package directory. The format is `src:dst`, where `src` can be relative to the package directory and `dst` is the destination in the build context. This is useful for sharing files, such as vendored go code, between packages.
|
||||||
|
@ -22,12 +22,13 @@ func createPackageResolver(baseDir string) spec.PackageResolver {
|
|||||||
pkgValue = pkgTmpl
|
pkgValue = pkgTmpl
|
||||||
case strings.HasPrefix(pkgTmpl, templateFlag+templatePkg):
|
case strings.HasPrefix(pkgTmpl, templateFlag+templatePkg):
|
||||||
pkgPath := strings.TrimPrefix(pkgTmpl, templateFlag+templatePkg)
|
pkgPath := strings.TrimPrefix(pkgTmpl, templateFlag+templatePkg)
|
||||||
|
piBase := pkglib.NewPkgInfo()
|
||||||
|
|
||||||
var pkgs []pkglib.Pkg
|
var pkgs []pkglib.Pkg
|
||||||
pkgConfig := pkglib.PkglibConfig{
|
pkgConfig := pkglib.PkglibConfig{
|
||||||
BuildYML: defaultPkgBuildYML,
|
BuildYML: defaultPkgBuildYML,
|
||||||
HashCommit: defaultPkgCommit,
|
HashCommit: defaultPkgCommit,
|
||||||
Tag: defaultPkgTag,
|
Tag: piBase.Tag,
|
||||||
}
|
}
|
||||||
pkgs, err = pkglib.NewFromConfig(pkgConfig, path.Join(baseDir, pkgPath))
|
pkgs, err = pkglib.NewFromConfig(pkgConfig, path.Join(baseDir, pkgPath))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -3,5 +3,4 @@ package main
|
|||||||
const (
|
const (
|
||||||
defaultPkgBuildYML = "build.yml"
|
defaultPkgBuildYML = "build.yml"
|
||||||
defaultPkgCommit = "HEAD"
|
defaultPkgCommit = "HEAD"
|
||||||
defaultPkgTag = "{{.Hash}}"
|
|
||||||
)
|
)
|
||||||
|
@ -37,7 +37,6 @@ func pkgCmd() *cobra.Command {
|
|||||||
HashPath: hashPath,
|
HashPath: hashPath,
|
||||||
Dirty: dirty,
|
Dirty: dirty,
|
||||||
Dev: devMode,
|
Dev: devMode,
|
||||||
Tag: tag,
|
|
||||||
}
|
}
|
||||||
if cmd.Flags().Changed("disable-cache") && cmd.Flags().Changed("enable-cache") {
|
if cmd.Flags().Changed("disable-cache") && cmd.Flags().Changed("enable-cache") {
|
||||||
return errors.New("cannot set but disable-cache and enable-cache")
|
return errors.New("cannot set but disable-cache and enable-cache")
|
||||||
@ -65,6 +64,9 @@ func pkgCmd() *cobra.Command {
|
|||||||
if cmd.Flags().Changed("org") {
|
if cmd.Flags().Changed("org") {
|
||||||
pkglibConfig.Org = &argOrg
|
pkglibConfig.Org = &argOrg
|
||||||
}
|
}
|
||||||
|
if cmd.Flags().Changed("tag") {
|
||||||
|
pkglibConfig.Tag = tag
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
@ -88,7 +90,7 @@ func pkgCmd() *cobra.Command {
|
|||||||
cmd.PersistentFlags().StringVar(&argOrg, "org", piBase.Org, "Override the hub org")
|
cmd.PersistentFlags().StringVar(&argOrg, "org", piBase.Org, "Override the hub org")
|
||||||
cmd.PersistentFlags().StringVar(&buildYML, "build-yml", defaultPkgBuildYML, "Override the name of the yml file")
|
cmd.PersistentFlags().StringVar(&buildYML, "build-yml", defaultPkgBuildYML, "Override the name of the yml file")
|
||||||
cmd.PersistentFlags().StringVar(&hash, "hash", "", "Override the image hash (default is to query git for the package's tree-sh)")
|
cmd.PersistentFlags().StringVar(&hash, "hash", "", "Override the image hash (default is to query git for the package's tree-sh)")
|
||||||
cmd.PersistentFlags().StringVar(&tag, "tag", defaultPkgTag, "Override the tag using fixed strings and/or text templates. Acceptable are .Hash for the hash")
|
cmd.PersistentFlags().StringVar(&tag, "tag", piBase.Tag, "Override the tag using fixed strings and/or text templates. Acceptable are .Hash for the hash")
|
||||||
cmd.PersistentFlags().StringVar(&hashCommit, "hash-commit", defaultPkgCommit, "Override the git commit to use for the hash")
|
cmd.PersistentFlags().StringVar(&hashCommit, "hash-commit", defaultPkgCommit, "Override the git commit to use for the hash")
|
||||||
cmd.PersistentFlags().StringVar(&hashPath, "hash-path", "", "Override the directory to use for the image hash, must be a parent of the package dir (default is to use the package dir)")
|
cmd.PersistentFlags().StringVar(&hashPath, "hash-path", "", "Override the directory to use for the image hash, must be a parent of the package dir (default is to use the package dir)")
|
||||||
cmd.PersistentFlags().BoolVar(&dirty, "force-dirty", false, "Force the pkg(s) to be considered dirty")
|
cmd.PersistentFlags().BoolVar(&dirty, "force-dirty", false, "Force the pkg(s) to be considered dirty")
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
type pkgInfo struct {
|
type pkgInfo struct {
|
||||||
Image string `yaml:"image"`
|
Image string `yaml:"image"`
|
||||||
Org string `yaml:"org"`
|
Org string `yaml:"org"`
|
||||||
|
Tag string `yaml:"tag,omitempty"` // default to {{.Hash}}
|
||||||
Dockerfile string `yaml:"dockerfile"`
|
Dockerfile string `yaml:"dockerfile"`
|
||||||
Arches []string `yaml:"arches"`
|
Arches []string `yaml:"arches"`
|
||||||
ExtraSources []string `yaml:"extra-sources"`
|
ExtraSources []string `yaml:"extra-sources"`
|
||||||
@ -60,6 +61,7 @@ func NewPkgInfo() pkgInfo {
|
|||||||
return pkgInfo{
|
return pkgInfo{
|
||||||
Org: "linuxkit",
|
Org: "linuxkit",
|
||||||
Arches: []string{"amd64", "arm64"},
|
Arches: []string{"amd64", "arm64"},
|
||||||
|
Tag: "{{.Hash}}",
|
||||||
GitRepo: "https://github.com/linuxkit/linuxkit",
|
GitRepo: "https://github.com/linuxkit/linuxkit",
|
||||||
Network: false,
|
Network: false,
|
||||||
DisableCache: false,
|
DisableCache: false,
|
||||||
@ -257,9 +259,16 @@ func NewFromConfig(cfg PkglibConfig, args ...string) ([]Pkg, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
tagTmpl := pi.Tag
|
||||||
|
if cfg.Tag != "" {
|
||||||
|
tagTmpl = cfg.Tag
|
||||||
|
}
|
||||||
|
if tagTmpl == "" {
|
||||||
|
tagTmpl = "{{.Hash}}"
|
||||||
|
}
|
||||||
|
|
||||||
// calculate the tag to use based on the template and the pkgHash
|
// calculate the tag to use based on the template and the pkgHash
|
||||||
tmpl, err := template.New("tag").Parse(cfg.Tag)
|
tmpl, err := template.New("tag").Parse(tagTmpl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("invalid tag template: %v", err)
|
return nil, fmt.Errorf("invalid tag template: %v", err)
|
||||||
}
|
}
|
||||||
|
1
test/cases/000_build/057_pkg_tag/000_tag_yaml/Dockerfile
Normal file
1
test/cases/000_build/057_pkg_tag/000_tag_yaml/Dockerfile
Normal file
@ -0,0 +1 @@
|
|||||||
|
FROM alpine:3.20
|
3
test/cases/000_build/057_pkg_tag/000_tag_yaml/build.yml
Normal file
3
test/cases/000_build/057_pkg_tag/000_tag_yaml/build.yml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
org: linuxkit
|
||||||
|
image: image-with-tag
|
||||||
|
tag: file
|
16
test/cases/000_build/057_pkg_tag/000_tag_yaml/test.sh
Normal file
16
test/cases/000_build/057_pkg_tag/000_tag_yaml/test.sh
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# SUMMARY: Check that tar output format build is reproducible
|
||||||
|
# LABELS:
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Source libraries. Uncomment if needed/defined
|
||||||
|
#. "${RT_LIB}"
|
||||||
|
. "${RT_PROJECT_ROOT}/_lib/lib.sh"
|
||||||
|
|
||||||
|
linuxkit pkg build --force .
|
||||||
|
|
||||||
|
# just run docker image inspect; if it does not exist, it will error out
|
||||||
|
linuxkit cache ls 2>&1 | grep 'linuxkit/image-with-tag:file'
|
||||||
|
|
||||||
|
exit 0
|
1
test/cases/000_build/057_pkg_tag/001_tag_cli/Dockerfile
Normal file
1
test/cases/000_build/057_pkg_tag/001_tag_cli/Dockerfile
Normal file
@ -0,0 +1 @@
|
|||||||
|
FROM alpine:3.20
|
2
test/cases/000_build/057_pkg_tag/001_tag_cli/build.yml
Normal file
2
test/cases/000_build/057_pkg_tag/001_tag_cli/build.yml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
org: linuxkit
|
||||||
|
image: image-with-tag
|
16
test/cases/000_build/057_pkg_tag/001_tag_cli/test.sh
Normal file
16
test/cases/000_build/057_pkg_tag/001_tag_cli/test.sh
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# SUMMARY: Check that tar output format build is reproducible
|
||||||
|
# LABELS:
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Source libraries. Uncomment if needed/defined
|
||||||
|
#. "${RT_LIB}"
|
||||||
|
. "${RT_PROJECT_ROOT}/_lib/lib.sh"
|
||||||
|
|
||||||
|
linuxkit pkg build --force --tag cli .
|
||||||
|
|
||||||
|
# just run docker image inspect; if it does not exist, it will error out
|
||||||
|
linuxkit cache ls 2>&1 | grep 'linuxkit/image-with-tag:cli'
|
||||||
|
|
||||||
|
exit 0
|
@ -0,0 +1 @@
|
|||||||
|
FROM alpine:3.20
|
@ -0,0 +1,3 @@
|
|||||||
|
org: linuxkit
|
||||||
|
image: image-with-tag
|
||||||
|
tag: file-new
|
@ -0,0 +1,22 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# SUMMARY: Check that tar output format build is reproducible
|
||||||
|
# LABELS:
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Source libraries. Uncomment if needed/defined
|
||||||
|
#. "${RT_LIB}"
|
||||||
|
. "${RT_PROJECT_ROOT}/_lib/lib.sh"
|
||||||
|
|
||||||
|
linuxkit pkg build --force --tag cli .
|
||||||
|
|
||||||
|
# just run docker image inspect; if it does not exist, it will error out
|
||||||
|
linuxkit cache ls 2>&1 | grep 'linuxkit/image-with-tag:cli'
|
||||||
|
|
||||||
|
# specifically, the `file` tag should not exist, so check that it does not exist
|
||||||
|
if linuxkit cache ls 2>&1 | grep 'linuxkit/image-with-tag:file-new'; then
|
||||||
|
echo "ERROR: image with tag 'file-new' should not exist"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit 0
|
Loading…
Reference in New Issue
Block a user