2022-06-07 02:58:38 +08:00
|
|
|
package cli
|
|
|
|
|
2023-12-05 03:05:38 +08:00
|
|
|
// the cli package contains spf13/cobra related structs that help make up
|
|
|
|
// the command line for buildah commands. this file's contents are better
|
|
|
|
// suited for pkg/parse, but since pkg/parse imports pkg/util which also
|
|
|
|
// imports pkg/parse, having it there would create a cyclic dependency, so
|
|
|
|
// here we are.
|
2022-06-07 02:58:38 +08:00
|
|
|
|
|
|
|
import (
|
2022-07-06 17:14:06 +08:00
|
|
|
"errors"
|
2022-06-07 02:58:38 +08:00
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2025-01-23 22:27:47 +08:00
|
|
|
"slices"
|
2022-06-07 02:58:38 +08:00
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/containers/buildah/define"
|
|
|
|
"github.com/containers/buildah/pkg/parse"
|
|
|
|
"github.com/containers/buildah/pkg/util"
|
|
|
|
"github.com/containers/common/pkg/auth"
|
2022-07-18 13:47:55 +08:00
|
|
|
"github.com/containers/image/v5/docker/reference"
|
2022-09-15 18:00:23 +08:00
|
|
|
"github.com/containers/image/v5/types"
|
2022-09-19 17:08:50 +08:00
|
|
|
"github.com/opencontainers/runtime-spec/specs-go"
|
2022-06-07 02:58:38 +08:00
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
type BuildOptions struct {
|
|
|
|
*LayerResults
|
|
|
|
*BudResults
|
|
|
|
*UserNSResults
|
|
|
|
*FromAndBudResults
|
|
|
|
*NameSpaceResults
|
|
|
|
Logwriter *os.File
|
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
|
|
|
MaxPullPushRetries = 3
|
|
|
|
PullPushRetryDelay = 2 * time.Second
|
|
|
|
)
|
|
|
|
|
|
|
|
// GenBuildOptions translates command line flags into a BuildOptions structure
|
|
|
|
func GenBuildOptions(c *cobra.Command, inputArgs []string, iopts BuildOptions) (define.BuildOptions, []string, []string, error) {
|
|
|
|
options := define.BuildOptions{}
|
|
|
|
|
|
|
|
var removeAll []string
|
|
|
|
|
|
|
|
output := ""
|
|
|
|
cleanTmpFile := false
|
|
|
|
tags := []string{}
|
2022-09-16 02:26:37 +08:00
|
|
|
if iopts.Network == "none" {
|
|
|
|
if c.Flag("dns").Changed {
|
2022-09-21 10:02:40 +08:00
|
|
|
return options, nil, nil, errors.New("the --dns option cannot be used with --network=none")
|
2022-09-16 02:26:37 +08:00
|
|
|
}
|
|
|
|
if c.Flag("dns-option").Changed {
|
2022-09-21 10:02:40 +08:00
|
|
|
return options, nil, nil, errors.New("the --dns-option option cannot be used with --network=none")
|
2022-09-16 02:26:37 +08:00
|
|
|
}
|
|
|
|
if c.Flag("dns-search").Changed {
|
2022-09-21 10:02:40 +08:00
|
|
|
return options, nil, nil, errors.New("the --dns-search option cannot be used with --network=none")
|
2022-09-16 02:26:37 +08:00
|
|
|
}
|
|
|
|
}
|
2022-06-07 02:58:38 +08:00
|
|
|
if c.Flag("tag").Changed {
|
|
|
|
tags = iopts.Tag
|
|
|
|
if len(tags) > 0 {
|
|
|
|
output = tags[0]
|
|
|
|
tags = tags[1:]
|
|
|
|
}
|
|
|
|
if c.Flag("manifest").Changed {
|
2025-04-08 03:23:13 +08:00
|
|
|
if slices.Contains(tags, iopts.Manifest) {
|
|
|
|
return options, nil, nil, errors.New("the same name must not be specified for both '--tag' and '--manifest'")
|
2022-06-07 02:58:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err := auth.CheckAuthFile(iopts.BudResults.Authfile); err != nil {
|
|
|
|
return options, nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.Flag("logsplit").Changed {
|
|
|
|
if !c.Flag("logfile").Changed {
|
2022-07-06 17:14:06 +08:00
|
|
|
return options, nil, nil, errors.New("cannot use --logsplit without --logfile")
|
2022-06-07 02:58:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
iopts.BudResults.Authfile, cleanTmpFile = util.MirrorToTempFileIfPathIsDescriptor(iopts.BudResults.Authfile)
|
|
|
|
if cleanTmpFile {
|
|
|
|
removeAll = append(removeAll, iopts.BudResults.Authfile)
|
|
|
|
}
|
|
|
|
|
2023-12-05 03:05:38 +08:00
|
|
|
pullPolicy, err := parse.PullPolicyFromOptions(c)
|
|
|
|
if err != nil {
|
|
|
|
return options, nil, nil, err
|
2022-06-07 02:58:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
args := make(map[string]string)
|
2023-03-25 18:32:47 +08:00
|
|
|
if c.Flag("build-arg-file").Changed {
|
|
|
|
for _, argfile := range iopts.BuildArgFile {
|
|
|
|
if err := readBuildArgFile(argfile, args); err != nil {
|
|
|
|
return options, nil, nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-06-07 02:58:38 +08:00
|
|
|
if c.Flag("build-arg").Changed {
|
|
|
|
for _, arg := range iopts.BuildArg {
|
2023-03-25 18:32:47 +08:00
|
|
|
readBuildArg(arg, args)
|
2022-06-07 02:58:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
additionalBuildContext := make(map[string]*define.AdditionalBuildContext)
|
|
|
|
if c.Flag("build-context").Changed {
|
|
|
|
for _, contextString := range iopts.BuildContext {
|
|
|
|
av := strings.SplitN(contextString, "=", 2)
|
|
|
|
if len(av) > 1 {
|
|
|
|
parseAdditionalBuildContext, err := parse.GetAdditionalBuildContext(av[1])
|
|
|
|
if err != nil {
|
2022-07-06 17:14:06 +08:00
|
|
|
return options, nil, nil, fmt.Errorf("while parsing additional build context: %w", err)
|
2022-06-07 02:58:38 +08:00
|
|
|
}
|
|
|
|
additionalBuildContext[av[0]] = &parseAdditionalBuildContext
|
|
|
|
} else {
|
|
|
|
return options, nil, nil, fmt.Errorf("while parsing additional build context: %q, accepts value in the form of key=value", av)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
containerfiles := getContainerfiles(iopts.File)
|
2023-05-19 04:28:21 +08:00
|
|
|
format, err := GetFormat(iopts.Format)
|
2022-06-07 02:58:38 +08:00
|
|
|
if err != nil {
|
|
|
|
return options, nil, nil, err
|
|
|
|
}
|
|
|
|
layers := UseLayers()
|
|
|
|
if c.Flag("layers").Changed {
|
|
|
|
layers = iopts.Layers
|
|
|
|
}
|
|
|
|
contextDir := ""
|
|
|
|
cliArgs := inputArgs
|
|
|
|
|
|
|
|
// Nothing provided, we assume the current working directory as build
|
|
|
|
// context
|
|
|
|
if len(cliArgs) == 0 {
|
|
|
|
contextDir, err = os.Getwd()
|
|
|
|
if err != nil {
|
2022-07-06 17:14:06 +08:00
|
|
|
return options, nil, nil, fmt.Errorf("unable to choose current working directory as build context: %w", err)
|
2022-06-07 02:58:38 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// The context directory could be a URL. Try to handle that.
|
|
|
|
tempDir, subDir, err := define.TempDirForURL("", "buildah", cliArgs[0])
|
|
|
|
if err != nil {
|
2022-09-18 18:36:08 +08:00
|
|
|
return options, nil, nil, fmt.Errorf("prepping temporary context directory: %w", err)
|
2022-06-07 02:58:38 +08:00
|
|
|
}
|
|
|
|
if tempDir != "" {
|
|
|
|
// We had to download it to a temporary directory.
|
|
|
|
// Delete it later.
|
|
|
|
removeAll = append(removeAll, tempDir)
|
|
|
|
contextDir = filepath.Join(tempDir, subDir)
|
|
|
|
} else {
|
|
|
|
// Nope, it was local. Use it as is.
|
|
|
|
absDir, err := filepath.Abs(cliArgs[0])
|
|
|
|
if err != nil {
|
2022-09-18 18:36:08 +08:00
|
|
|
return options, nil, nil, fmt.Errorf("determining path to directory: %w", err)
|
2022-06-07 02:58:38 +08:00
|
|
|
}
|
|
|
|
contextDir = absDir
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(containerfiles) == 0 {
|
|
|
|
// Try to find the Containerfile/Dockerfile within the contextDir
|
|
|
|
containerfile, err := util.DiscoverContainerfile(contextDir)
|
|
|
|
if err != nil {
|
|
|
|
return options, nil, nil, err
|
|
|
|
}
|
|
|
|
containerfiles = append(containerfiles, containerfile)
|
|
|
|
contextDir = filepath.Dir(containerfile)
|
|
|
|
}
|
|
|
|
|
|
|
|
contextDir, err = filepath.EvalSymlinks(contextDir)
|
|
|
|
if err != nil {
|
2022-09-18 18:36:08 +08:00
|
|
|
return options, nil, nil, fmt.Errorf("evaluating symlinks in build context path: %w", err)
|
2022-06-07 02:58:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var stdin io.Reader
|
|
|
|
if iopts.Stdin {
|
|
|
|
stdin = os.Stdin
|
|
|
|
}
|
|
|
|
|
|
|
|
var stdout, stderr, reporter *os.File
|
|
|
|
stdout = os.Stdout
|
|
|
|
stderr = os.Stderr
|
|
|
|
reporter = os.Stderr
|
|
|
|
if iopts.Logwriter != nil {
|
|
|
|
logrus.SetOutput(iopts.Logwriter)
|
|
|
|
stdout = iopts.Logwriter
|
|
|
|
stderr = iopts.Logwriter
|
|
|
|
reporter = iopts.Logwriter
|
|
|
|
}
|
|
|
|
|
|
|
|
systemContext, err := parse.SystemContextFromOptions(c)
|
|
|
|
if err != nil {
|
2022-09-18 18:36:08 +08:00
|
|
|
return options, nil, nil, fmt.Errorf("building system context: %w", err)
|
2022-06-07 02:58:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
isolation, err := parse.IsolationOption(iopts.Isolation)
|
|
|
|
if err != nil {
|
|
|
|
return options, nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
runtimeFlags := []string{}
|
|
|
|
for _, arg := range iopts.RuntimeFlags {
|
|
|
|
runtimeFlags = append(runtimeFlags, "--"+arg)
|
|
|
|
}
|
|
|
|
|
|
|
|
commonOpts, err := parse.CommonBuildOptions(c)
|
|
|
|
if err != nil {
|
|
|
|
return options, nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c.Flag("rm").Changed || c.Flag("force-rm").Changed) && (!c.Flag("layers").Changed && !c.Flag("no-cache").Changed) {
|
2022-07-06 17:14:06 +08:00
|
|
|
return options, nil, nil, errors.New("'rm' and 'force-rm' can only be set with either 'layers' or 'no-cache'")
|
2022-06-07 02:58:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if c.Flag("compress").Changed {
|
|
|
|
logrus.Debugf("--compress option specified but is ignored")
|
|
|
|
}
|
|
|
|
|
|
|
|
compression := define.Gzip
|
|
|
|
if iopts.DisableCompression {
|
|
|
|
compression = define.Uncompressed
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.Flag("disable-content-trust").Changed {
|
|
|
|
logrus.Debugf("--disable-content-trust option specified but is ignored")
|
|
|
|
}
|
|
|
|
|
|
|
|
namespaceOptions, networkPolicy, err := parse.NamespaceOptions(c)
|
|
|
|
if err != nil {
|
|
|
|
return options, nil, nil, err
|
|
|
|
}
|
|
|
|
usernsOption, idmappingOptions, err := parse.IDMappingOptions(c, isolation)
|
|
|
|
if err != nil {
|
2022-09-18 18:36:08 +08:00
|
|
|
return options, nil, nil, fmt.Errorf("parsing ID mapping options: %w", err)
|
2022-06-07 02:58:38 +08:00
|
|
|
}
|
|
|
|
namespaceOptions.AddOrReplace(usernsOption...)
|
|
|
|
|
|
|
|
platforms, err := parse.PlatformsFromOptions(c)
|
|
|
|
if err != nil {
|
|
|
|
return options, nil, nil, err
|
|
|
|
}
|
|
|
|
|
2023-05-19 04:28:21 +08:00
|
|
|
decryptConfig, err := DecryptConfig(iopts.DecryptionKeys)
|
2022-06-07 02:58:38 +08:00
|
|
|
if err != nil {
|
2022-07-06 17:14:06 +08:00
|
|
|
return options, nil, nil, fmt.Errorf("unable to obtain decrypt config: %w", err)
|
2022-06-07 02:58:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var excludes []string
|
|
|
|
if iopts.IgnoreFile != "" {
|
2022-09-13 14:35:34 +08:00
|
|
|
if excludes, _, err = parse.ContainerIgnoreFile(contextDir, iopts.IgnoreFile, containerfiles); err != nil {
|
2022-06-07 02:58:38 +08:00
|
|
|
return options, nil, nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var timestamp *time.Time
|
|
|
|
if c.Flag("timestamp").Changed {
|
|
|
|
t := time.Unix(iopts.Timestamp, 0).UTC()
|
|
|
|
timestamp = &t
|
|
|
|
}
|
|
|
|
if c.Flag("output").Changed {
|
|
|
|
buildOption, err := parse.GetBuildOutput(iopts.BuildOutput)
|
|
|
|
if err != nil {
|
|
|
|
return options, nil, nil, err
|
|
|
|
}
|
|
|
|
if buildOption.IsStdout {
|
|
|
|
iopts.Quiet = true
|
|
|
|
}
|
|
|
|
}
|
2023-07-18 04:27:19 +08:00
|
|
|
var confidentialWorkloadOptions define.ConfidentialWorkloadOptions
|
|
|
|
if c.Flag("cw").Changed {
|
|
|
|
confidentialWorkloadOptions, err = parse.GetConfidentialWorkloadOptions(iopts.CWOptions)
|
|
|
|
if err != nil {
|
|
|
|
return options, nil, nil, err
|
|
|
|
}
|
|
|
|
}
|
2022-12-05 14:29:19 +08:00
|
|
|
var cacheTo []reference.Named
|
|
|
|
var cacheFrom []reference.Named
|
2022-07-18 13:47:55 +08:00
|
|
|
cacheTo = nil
|
|
|
|
cacheFrom = nil
|
|
|
|
if c.Flag("cache-to").Changed {
|
2022-12-05 14:29:19 +08:00
|
|
|
cacheTo, err = parse.RepoNamesToNamedReferences(iopts.CacheTo)
|
2022-07-18 13:47:55 +08:00
|
|
|
if err != nil {
|
|
|
|
return options, nil, nil, fmt.Errorf("unable to parse value provided `%s` to --cache-to: %w", iopts.CacheTo, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if c.Flag("cache-from").Changed {
|
2022-12-05 14:29:19 +08:00
|
|
|
cacheFrom, err = parse.RepoNamesToNamedReferences(iopts.CacheFrom)
|
2022-07-18 13:47:55 +08:00
|
|
|
if err != nil {
|
|
|
|
return options, nil, nil, fmt.Errorf("unable to parse value provided `%s` to --cache-from: %w", iopts.CacheTo, err)
|
|
|
|
}
|
|
|
|
}
|
2022-08-04 15:14:39 +08:00
|
|
|
var cacheTTL time.Duration
|
|
|
|
if c.Flag("cache-ttl").Changed {
|
|
|
|
cacheTTL, err = time.ParseDuration(iopts.CacheTTL)
|
|
|
|
if err != nil {
|
|
|
|
return options, nil, nil, fmt.Errorf("unable to parse value provided %q as --cache-ttl: %w", iopts.CacheTTL, err)
|
|
|
|
}
|
2022-09-15 16:42:19 +08:00
|
|
|
// If user explicitly specified `--cache-ttl=0s`
|
|
|
|
// it would effectively mean that user is asking
|
|
|
|
// to use no cache at all. In such use cases
|
2023-02-09 22:05:03 +08:00
|
|
|
// buildah can skip looking for cache entirely
|
2022-09-15 16:42:19 +08:00
|
|
|
// by setting `--no-cache=true` internally.
|
|
|
|
if int64(cacheTTL) == 0 {
|
|
|
|
logrus.Debug("Setting --no-cache=true since --cache-ttl was set to 0s which effectively means user wants to ignore cache")
|
|
|
|
if c.Flag("no-cache").Changed && !iopts.NoCache {
|
|
|
|
return options, nil, nil, fmt.Errorf("cannot use --cache-ttl with duration as 0 and --no-cache=false")
|
|
|
|
}
|
|
|
|
iopts.NoCache = true
|
|
|
|
}
|
2022-08-04 15:14:39 +08:00
|
|
|
}
|
2022-08-22 14:46:39 +08:00
|
|
|
|
2022-09-19 17:08:50 +08:00
|
|
|
if c.Flag("network").Changed && c.Flag("isolation").Changed {
|
|
|
|
if isolation == define.IsolationChroot {
|
|
|
|
if ns := namespaceOptions.Find(string(specs.NetworkNamespace)); ns != nil {
|
|
|
|
if !ns.Host {
|
|
|
|
return options, nil, nil, fmt.Errorf("cannot set --network other than host with --isolation %s", c.Flag("isolation").Value.String())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-05 03:05:38 +08:00
|
|
|
var sbomScanOptions []define.SBOMScanOptions
|
|
|
|
if c.Flag("sbom").Changed || c.Flag("sbom-scanner-command").Changed || c.Flag("sbom-scanner-image").Changed || c.Flag("sbom-image-output").Changed || c.Flag("sbom-merge-strategy").Changed || c.Flag("sbom-output").Changed || c.Flag("sbom-image-output").Changed || c.Flag("sbom-purl-output").Changed || c.Flag("sbom-image-purl-output").Changed {
|
|
|
|
sbomScanOption, err := parse.SBOMScanOptions(c)
|
|
|
|
if err != nil {
|
|
|
|
return options, nil, nil, err
|
|
|
|
}
|
2024-01-31 23:03:20 +08:00
|
|
|
if !slices.Contains(sbomScanOption.ContextDir, contextDir) {
|
2023-12-05 03:05:38 +08:00
|
|
|
sbomScanOption.ContextDir = append(sbomScanOption.ContextDir, contextDir)
|
|
|
|
}
|
|
|
|
for _, abc := range additionalBuildContext {
|
|
|
|
if !abc.IsURL && !abc.IsImage {
|
|
|
|
sbomScanOption.ContextDir = append(sbomScanOption.ContextDir, abc.Value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sbomScanOption.PullPolicy = pullPolicy
|
|
|
|
sbomScanOptions = append(sbomScanOptions, *sbomScanOption)
|
|
|
|
}
|
|
|
|
|
2022-06-07 02:58:38 +08:00
|
|
|
options = define.BuildOptions{
|
|
|
|
AddCapabilities: iopts.CapAdd,
|
2022-06-07 20:51:57 +08:00
|
|
|
AdditionalBuildContexts: additionalBuildContext,
|
2022-06-07 02:58:38 +08:00
|
|
|
AdditionalTags: tags,
|
|
|
|
AllPlatforms: iopts.AllPlatforms,
|
|
|
|
Annotations: iopts.Annotation,
|
|
|
|
Architecture: systemContext.ArchitectureChoice,
|
|
|
|
Args: args,
|
|
|
|
BlobDirectory: iopts.BlobCache,
|
2022-06-07 20:51:57 +08:00
|
|
|
BuildOutput: iopts.BuildOutput,
|
2022-07-18 13:47:55 +08:00
|
|
|
CacheFrom: cacheFrom,
|
|
|
|
CacheTo: cacheTo,
|
2022-08-04 15:14:39 +08:00
|
|
|
CacheTTL: cacheTTL,
|
2024-03-26 09:13:35 +08:00
|
|
|
CDIConfigDir: iopts.CDIConfigDir,
|
2022-06-07 02:58:38 +08:00
|
|
|
CNIConfigDir: iopts.CNIConfigDir,
|
|
|
|
CNIPluginPath: iopts.CNIPlugInPath,
|
2024-06-07 04:32:13 +08:00
|
|
|
CompatVolumes: types.NewOptionalBool(iopts.CompatVolumes),
|
2023-07-18 04:27:19 +08:00
|
|
|
ConfidentialWorkload: confidentialWorkloadOptions,
|
2022-06-07 20:51:57 +08:00
|
|
|
CPPFlags: iopts.CPPFlags,
|
2022-06-07 02:58:38 +08:00
|
|
|
CommonBuildOpts: commonOpts,
|
|
|
|
Compression: compression,
|
|
|
|
ConfigureNetwork: networkPolicy,
|
|
|
|
ContextDirectory: contextDir,
|
|
|
|
Devices: iopts.Devices,
|
|
|
|
DropCapabilities: iopts.CapDrop,
|
|
|
|
Err: stderr,
|
2022-06-07 20:51:57 +08:00
|
|
|
Excludes: excludes,
|
2022-06-07 02:58:38 +08:00
|
|
|
ForceRmIntermediateCtrs: iopts.ForceRm,
|
|
|
|
From: iopts.From,
|
2022-12-22 03:51:59 +08:00
|
|
|
GroupAdd: iopts.GroupAdd,
|
2022-06-07 02:58:38 +08:00
|
|
|
IDMappingOptions: idmappingOptions,
|
|
|
|
IIDFile: iopts.Iidfile,
|
2022-06-07 20:51:57 +08:00
|
|
|
IgnoreFile: iopts.IgnoreFile,
|
2022-06-07 02:58:38 +08:00
|
|
|
In: stdin,
|
2023-09-23 00:28:44 +08:00
|
|
|
InheritLabels: types.NewOptionalBool(iopts.InheritLabels),
|
2022-06-07 02:58:38 +08:00
|
|
|
Isolation: isolation,
|
2022-06-07 20:51:57 +08:00
|
|
|
Jobs: &iopts.Jobs,
|
2022-06-07 02:58:38 +08:00
|
|
|
Labels: iopts.Label,
|
2023-08-02 15:29:19 +08:00
|
|
|
LayerLabels: iopts.LayerLabel,
|
2022-06-07 02:58:38 +08:00
|
|
|
Layers: layers,
|
|
|
|
LogFile: iopts.Logfile,
|
|
|
|
LogRusage: iopts.LogRusage,
|
2022-06-07 20:51:57 +08:00
|
|
|
LogSplitByPlatform: iopts.LogSplitByPlatform,
|
2022-06-07 02:58:38 +08:00
|
|
|
Manifest: iopts.Manifest,
|
2022-08-22 14:46:39 +08:00
|
|
|
MaxPullPushRetries: iopts.Retry,
|
2022-06-07 02:58:38 +08:00
|
|
|
NamespaceOptions: namespaceOptions,
|
|
|
|
NoCache: iopts.NoCache,
|
|
|
|
OS: systemContext.OSChoice,
|
2022-06-07 20:51:57 +08:00
|
|
|
OSFeatures: iopts.OSFeatures,
|
|
|
|
OSVersion: iopts.OSVersion,
|
|
|
|
OciDecryptConfig: decryptConfig,
|
2022-06-07 02:58:38 +08:00
|
|
|
Out: stdout,
|
|
|
|
Output: output,
|
|
|
|
OutputFormat: format,
|
2022-06-07 20:51:57 +08:00
|
|
|
Platforms: platforms,
|
2022-06-07 02:58:38 +08:00
|
|
|
PullPolicy: pullPolicy,
|
|
|
|
Quiet: iopts.Quiet,
|
|
|
|
RemoveIntermediateCtrs: iopts.Rm,
|
|
|
|
ReportWriter: reporter,
|
|
|
|
Runtime: iopts.Runtime,
|
|
|
|
RuntimeArgs: runtimeFlags,
|
|
|
|
RusageLogFile: iopts.RusageLogFile,
|
2023-12-05 03:05:38 +08:00
|
|
|
SBOMScanOptions: sbomScanOptions,
|
2022-06-07 02:58:38 +08:00
|
|
|
SignBy: iopts.SignBy,
|
|
|
|
SignaturePolicyPath: iopts.SignaturePolicy,
|
2022-09-15 18:00:23 +08:00
|
|
|
SkipUnusedStages: types.NewOptionalBool(iopts.SkipUnusedStages),
|
2022-06-07 02:58:38 +08:00
|
|
|
Squash: iopts.Squash,
|
|
|
|
SystemContext: systemContext,
|
|
|
|
Target: iopts.Target,
|
|
|
|
Timestamp: timestamp,
|
2022-06-07 20:51:57 +08:00
|
|
|
TransientMounts: iopts.Volumes,
|
2022-06-07 02:58:38 +08:00
|
|
|
UnsetEnvs: iopts.UnsetEnvs,
|
2023-09-23 01:34:15 +08:00
|
|
|
UnsetLabels: iopts.UnsetLabels,
|
2022-06-07 02:58:38 +08:00
|
|
|
}
|
2024-02-21 05:01:00 +08:00
|
|
|
if iopts.RetryDelay != "" {
|
|
|
|
options.PullPushRetryDelay, err = time.ParseDuration(iopts.RetryDelay)
|
|
|
|
if err != nil {
|
|
|
|
return options, nil, nil, fmt.Errorf("unable to parse value provided %q as --retry-delay: %w", iopts.RetryDelay, err)
|
|
|
|
}
|
|
|
|
// Following log line is used in integration test.
|
|
|
|
logrus.Debugf("Setting MaxPullPushRetries to %d and PullPushRetryDelay to %v", iopts.Retry, options.PullPushRetryDelay)
|
|
|
|
}
|
|
|
|
|
2022-06-07 02:58:38 +08:00
|
|
|
if iopts.Quiet {
|
2022-11-15 00:22:45 +08:00
|
|
|
options.ReportWriter = io.Discard
|
2022-06-07 02:58:38 +08:00
|
|
|
}
|
2023-04-03 07:24:10 +08:00
|
|
|
|
|
|
|
options.Envs = LookupEnvVarReferences(iopts.Envs, os.Environ())
|
|
|
|
|
2022-06-07 02:58:38 +08:00
|
|
|
return options, containerfiles, removeAll, nil
|
|
|
|
}
|
|
|
|
|
2023-03-25 18:32:47 +08:00
|
|
|
func readBuildArgFile(buildargfile string, args map[string]string) error {
|
|
|
|
argfile, err := os.ReadFile(buildargfile)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
for _, arg := range strings.Split(string(argfile), "\n") {
|
2023-05-19 04:28:21 +08:00
|
|
|
if len(arg) == 0 || arg[0] == '#' {
|
2023-03-25 18:32:47 +08:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
readBuildArg(arg, args)
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func readBuildArg(buildarg string, args map[string]string) {
|
|
|
|
av := strings.SplitN(buildarg, "=", 2)
|
|
|
|
if len(av) > 1 {
|
|
|
|
args[av[0]] = av[1]
|
|
|
|
} else {
|
|
|
|
// check if the env is set in the local environment and use that value if it is
|
|
|
|
if val, present := os.LookupEnv(av[0]); present {
|
|
|
|
args[av[0]] = val
|
|
|
|
} else {
|
|
|
|
delete(args, av[0])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-07 02:58:38 +08:00
|
|
|
func getContainerfiles(files []string) []string {
|
|
|
|
var containerfiles []string
|
|
|
|
for _, f := range files {
|
|
|
|
if f == "-" {
|
|
|
|
containerfiles = append(containerfiles, "/dev/stdin")
|
|
|
|
} else {
|
|
|
|
containerfiles = append(containerfiles, f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return containerfiles
|
|
|
|
}
|