Declare build-args in build.yml

This allows multiple build flavors for a single codebase, without
sacrificing reproducible builds. The build-args are set in build.yml,
which is typically under the source control (if it is not, then no
reproducible builds are possible anyways). Meaning that mutating
build-args would result in setting "dirty" flag.

Intended use of this commit is to switch between build flavors by
specifying a different yaml file (presumably also under the version
control)  by  `-build-yml` option.

Because it is impossible to build a final image from packages in
cache, the test for this feature relies on the `RUN echo $build-arg`
output during the `pkg build` process.

Signed-off-by: Yuri Volchkov <yuri@zededa.com>
This commit is contained in:
Yuri Volchkov
2022-02-01 20:15:34 +00:00
parent e3bedd0985
commit 1a013f4424
6 changed files with 42 additions and 0 deletions

View File

@@ -257,6 +257,12 @@ func (p Pkg) Build(bos ...BuildOpt) error {
args = append(args, "--label=org.mobyproject.linuxkit.version="+version.Version)
args = append(args, "--label=org.mobyproject.linuxkit.revision="+version.GitCommit)
if p.buildArgs != nil {
for _, buildArg := range *p.buildArgs {
args = append(args, "--build-arg", buildArg)
}
}
// build for each arch and save in the linuxkit cache
for _, platform := range bo.platforms {
desc, err := p.buildArch(d, c, platform.Architecture, args, writer, bo)

View File

@@ -26,6 +26,7 @@ type pkgInfo struct {
Network bool `yaml:"network"`
DisableCache bool `yaml:"disable-cache"`
Config *moby.ImageConfig `yaml:"config"`
BuildArgs *[]string `yaml:"buildArgs,omitempty"`
Depends struct {
DockerImages struct {
TargetDir string `yaml:"target-dir"`
@@ -54,6 +55,7 @@ type Pkg struct {
trust bool
cache bool
config *moby.ImageConfig
buildArgs *[]string
dockerDepends dockerDepends
// Internal state
@@ -260,6 +262,7 @@ func NewFromCLI(fs *flag.FlagSet, args ...string) ([]Pkg, error) {
network: pi.Network,
cache: !pi.DisableCache,
config: pi.Config,
buildArgs: pi.BuildArgs,
dockerDepends: dockerDepends,
dirty: dirty,
path: pkgPath,