docker-buildx/cmd/docker-buildx/config.go
David Kovari ef56bac838 Improve support for cache_to and cache_from & add cache_images (#129)
### 📖 Summary

Originally, the cache_to and cache_from were being converted into string arrays. Then their contents were looped over to add to the build command. This has the side affect of stopping the user from setting additional options for the cache-to and cache-from args since their command input format uses commas. i.e. `type=registry,ref=imagepath,mode=max` would result in `--cache-to type=registry --cache-to ref=imagepath --cache-to mode=max`. The command was not designed to be used that way.

The one reason I can think of for cache_to and cache_from to be arrays is so you could have multiple cache registries. But I can't confirm that the build command even works like this.

### 📑 Build PR Images?

PR images are not needed

### 💬 Details

_No response_

Reviewed-on: https://codeberg.org/woodpecker-plugins/docker-buildx/pulls/129
Reviewed-by: Patrick Schratz <pat-s@noreply.codeberg.org>
Co-authored-by: David Kovari <dakovari@gmail.com>
Co-committed-by: David Kovari <dakovari@gmail.com>
2024-02-02 20:25:30 +00:00

348 lines
12 KiB
Go

package main
import (
"codeberg.org/woodpecker-plugins/plugin-docker-buildx/plugin"
"github.com/urfave/cli/v2"
)
// settingsFlags has the cli.Flags for the plugin.Settings.
func settingsFlags(settings *plugin.Settings) []cli.Flag {
return []cli.Flag{
&cli.BoolFlag{
Name: "dry-run",
EnvVars: []string{"PLUGIN_DRY_RUN"},
Usage: "disables docker push",
Destination: &settings.Dryrun,
},
&cli.StringFlag{
Name: "remote.url",
EnvVars: []string{"CI_REMOTE_URL", "DRONE_REMOTE_URL"},
Usage: "sets the git remote url",
Destination: &settings.Build.Remote,
},
&cli.StringFlag{
Name: "daemon.mirror",
EnvVars: []string{"PLUGIN_MIRROR", "DOCKER_PLUGIN_MIRROR"},
Usage: "sets a registry mirror to pull images",
Destination: &settings.Daemon.Mirror,
},
&cli.StringFlag{
Name: "daemon.storage-driver",
EnvVars: []string{"PLUGIN_STORAGE_DRIVER"},
Usage: "sets the docker daemon storage driver",
Destination: &settings.Daemon.StorageDriver,
},
&cli.StringFlag{
Name: "daemon.storage-path",
EnvVars: []string{"PLUGIN_STORAGE_PATH"},
Usage: "sets the docker daemon storage path",
Value: "/var/lib/docker",
Destination: &settings.Daemon.StoragePath,
},
&cli.StringFlag{
Name: "daemon.bip",
EnvVars: []string{"PLUGIN_BIP"},
Usage: "allows the docker daemon to bride ip address",
Destination: &settings.Daemon.Bip,
},
&cli.StringFlag{
Name: "daemon.mtu",
EnvVars: []string{"PLUGIN_MTU"},
Usage: "sets docker daemon custom mtu setting",
Destination: &settings.Daemon.MTU,
},
&cli.StringSliceFlag{
Name: "daemon.dns",
EnvVars: []string{"PLUGIN_CUSTOM_DNS"},
Usage: "sets custom docker daemon dns server",
Destination: &settings.Daemon.DNS,
},
&cli.StringSliceFlag{
Name: "daemon.dns-search",
EnvVars: []string{"PLUGIN_CUSTOM_DNS_SEARCH"},
Usage: "sets custom docker daemon dns search domain",
Destination: &settings.Daemon.DNSSearch,
},
&cli.BoolFlag{
Name: "daemon.insecure",
EnvVars: []string{"PLUGIN_INSECURE"},
Usage: "allows the docker daemon to use insecure registries",
Destination: &settings.Daemon.Insecure,
},
&cli.BoolFlag{
Name: "daemon.ipv6",
EnvVars: []string{"PLUGIN_IPV6"},
Usage: "enables docker daemon IPv6 support",
Destination: &settings.Daemon.IPv6,
},
&cli.BoolFlag{
Name: "daemon.experimental",
EnvVars: []string{"PLUGIN_EXPERIMENTAL"},
Usage: "enables docker daemon experimental mode",
Destination: &settings.Daemon.Experimental,
},
&cli.BoolFlag{
Name: "daemon.debug",
EnvVars: []string{"PLUGIN_DEBUG", "DOCKER_LAUNCH_DEBUG"},
Usage: "enables verbose debug mode for the docker daemon",
Destination: &settings.Daemon.Debug,
},
&cli.BoolFlag{
Name: "daemon.off",
EnvVars: []string{"PLUGIN_DAEMON_OFF"},
Usage: "disables the startup of the docker daemon",
Destination: &settings.Daemon.Disabled,
},
&cli.StringFlag{
Name: "daemon.buildkit-config",
EnvVars: []string{"PLUGIN_BUILDKIT_CONFIG"},
Usage: "sets content of the docker buildkit json config",
Destination: &settings.Daemon.BuildkitConfig,
},
&cli.BoolFlag{
Name: "daemon.buildkit-debug",
EnvVars: []string{"PLUGIN_BUILDKIT_DEBUG"},
Usage: "enables buildkit debug",
Destination: &settings.Daemon.BuildkitDebug,
},
&cli.StringSliceFlag{
Name: "daemon.buildkit-driveropt",
EnvVars: []string{"PLUGIN_BUILDKIT_DRIVEROPT"},
Usage: "adds optional driver-ops args like 'env.http_proxy'",
Destination: &settings.Daemon.BuildkitDriverOpt,
},
&cli.StringFlag{
Name: "dockerfile",
EnvVars: []string{"PLUGIN_DOCKERFILE"},
Usage: "sets dockerfile to use for the image build",
Value: "Dockerfile",
Destination: &settings.Build.Dockerfile,
},
&cli.StringFlag{
Name: "context",
EnvVars: []string{"PLUGIN_CONTEXT"},
Usage: "sets the path of the build context to use",
Value: ".",
Destination: &settings.Build.Context,
},
&cli.StringSliceFlag{
Name: "tags",
EnvVars: []string{"PLUGIN_TAG", "PLUGIN_TAGS"},
Usage: "sets repository tags to use for the image",
Value: cli.NewStringSlice("latest"),
FilePath: ".tags",
Destination: &settings.Build.Tags,
},
&cli.StringFlag{
Name: "tags.file",
EnvVars: []string{"PLUGIN_TAGS_FILE", "PLUGIN_TAG_FILE"},
Usage: "overwrites tags flag with values find in set file",
Destination: &settings.Build.TagsFile,
},
&cli.BoolFlag{
Name: "tags.auto",
EnvVars: []string{"PLUGIN_AUTO_TAG"},
Usage: "generates tag names automatically based on git branch and git tag",
Destination: &settings.Build.TagsAuto,
},
&cli.StringFlag{
Name: "tags.defaultName",
EnvVars: []string{"PLUGIN_DEFAULT_TAG"},
Usage: "allows setting an alternative to `latest` for the auto tag",
Destination: &settings.Build.TagsDefaultName,
Value: "latest",
},
&cli.StringFlag{
Name: "tags.suffix",
EnvVars: []string{"PLUGIN_DEFAULT_SUFFIX", "PLUGIN_AUTO_TAG_SUFFIX"},
Usage: "generates tag names with the given suffix",
Destination: &settings.Build.TagsSuffix,
},
&cli.StringSliceFlag{
Name: "labels",
EnvVars: []string{"PLUGIN_LABEL", "PLUGIN_LABELS"},
Usage: "sets labels to use for the image",
Destination: &settings.Build.Labels,
},
&cli.BoolFlag{
Name: "labels.auto",
EnvVars: []string{"PLUGIN_DEFAULT_LABELS", "PLUGIN_AUTO_LABEL"},
Usage: "generates labels automatically based on git repository info",
Value: true,
Destination: &settings.Build.LabelsAuto,
},
&cli.StringSliceFlag{
Name: "args",
EnvVars: []string{"PLUGIN_BUILD_ARGS"},
Usage: "sets custom build arguments for the build",
Destination: &settings.Build.Args,
},
&cli.StringSliceFlag{
Name: "args-from-env",
EnvVars: []string{"PLUGIN_BUILD_ARGS_FROM_ENV"},
Usage: "forwards environment variables as custom arguments to the build",
Destination: &settings.Build.ArgsEnv,
},
&cli.BoolFlag{
Name: "quiet",
EnvVars: []string{"PLUGIN_QUIET"},
Usage: "enables suppression of the build output",
Destination: &settings.Build.Quiet,
},
&cli.StringFlag{
Name: "target",
EnvVars: []string{"PLUGIN_TARGET"},
Usage: "sets the build target to use",
Destination: &settings.Build.Target,
},
&cli.StringFlag{
Name: "cache-from",
EnvVars: []string{"PLUGIN_CACHE_FROM"},
Usage: "sets images to consider as cache sources",
Destination: &settings.Build.CacheFrom,
},
&cli.StringFlag{
Name: "cache-to",
EnvVars: []string{"PLUGIN_CACHE_TO"},
Usage: "cache destination for the build cache",
Destination: &settings.Build.CacheTo,
},
&cli.StringSliceFlag{
Name: "cache-images",
EnvVars: []string{"PLUGIN_CACHE_IMAGES"},
Usage: "list of images to use for build cache. applies both to and from flags for each image",
Destination: &settings.Build.CacheImages,
},
&cli.BoolFlag{
Name: "pull-image",
EnvVars: []string{"PLUGIN_PULL_IMAGE"},
Usage: "enforces to pull base image at build time",
Value: true,
Destination: &settings.Build.Pull,
},
&cli.BoolFlag{
Name: "compress",
EnvVars: []string{"PLUGIN_COMPRESS"},
Usage: "enables compression og the build context using gzip",
Destination: &settings.Build.Compress,
},
&cli.StringSliceFlag{
Name: "repo",
EnvVars: []string{"PLUGIN_REPO"},
Usage: "sets repository name for the image",
Destination: &settings.Build.Repo,
},
&cli.StringFlag{
Name: "docker.registry",
EnvVars: []string{"PLUGIN_REGISTRY", "DOCKER_REGISTRY"},
Usage: "sets docker registry to authenticate with",
Value: "https://index.docker.io/v1/",
Destination: &settings.DefaultLogin.Registry,
},
&cli.StringFlag{
Name: "docker.username",
EnvVars: []string{"PLUGIN_USERNAME", "DOCKER_USERNAME"},
Usage: "sets username to authenticates with",
Destination: &settings.DefaultLogin.Username,
},
&cli.StringFlag{
Name: "docker.password",
EnvVars: []string{"PLUGIN_PASSWORD", "DOCKER_PASSWORD"},
Usage: "sets password to authenticates with",
Destination: &settings.DefaultLogin.Password,
},
&cli.StringFlag{
Name: "docker.email",
EnvVars: []string{"PLUGIN_EMAIL", "DOCKER_EMAIL"},
Usage: "sets email address to authenticates with",
Destination: &settings.DefaultLogin.Email,
},
&cli.StringFlag{
Name: "docker.config",
EnvVars: []string{"PLUGIN_CONFIG", "DOCKER_PLUGIN_CONFIG"},
Usage: "sets content of the docker daemon json config",
Destination: &settings.DefaultLogin.Config,
},
&cli.StringFlag{
Name: "logins",
EnvVars: []string{"PLUGIN_LOGINS"},
Usage: "list of login",
Destination: &settings.LoginsRaw,
Value: "[]",
},
&cli.BoolFlag{
Name: "docker.purge",
EnvVars: []string{"PLUGIN_PURGE"},
Usage: "enables cleanup of the docker environment at the end of a build",
Value: true,
Destination: &settings.Cleanup,
},
&cli.BoolFlag{
Name: "no-cache",
EnvVars: []string{"PLUGIN_NO_CACHE"},
Usage: "disables the usage of cached intermediate containers",
Destination: &settings.Build.NoCache,
},
&cli.StringSliceFlag{
Name: "add-host",
EnvVars: []string{"PLUGIN_ADD_HOST"},
Usage: "sets additional host:ip mapping",
Destination: &settings.Build.AddHost,
},
&cli.StringSliceFlag{
Name: "platforms",
EnvVars: []string{"PLUGIN_PLATFORMS"},
Usage: "sets target platform for build",
Destination: &settings.Build.Platforms,
},
&cli.StringFlag{
Name: "output",
EnvVars: []string{"PLUGIN_OUTPUT"},
Usage: "sets build output type and destination configuration",
Destination: &settings.Build.Output,
},
&cli.StringFlag{
Name: "ecr.aws_access_key_id",
EnvVars: []string{"PLUGIN_AWS_ACCESS_KEY_ID"},
Usage: "Access Key ID for AWS",
Destination: &settings.AwsAccessKeyId,
},
&cli.StringFlag{
Name: "ecr.aws_secret_access_key_id",
EnvVars: []string{"PLUGIN_AWS_SECRET_ACCESS_KEY"},
Usage: "Secret Access Key for AWS",
Destination: &settings.AwsSecretAccessKey,
},
&cli.StringFlag{
Name: "ecr.aws_region",
EnvVars: []string{"PLUGIN_AWS_REGION"},
Usage: "AWS region to use",
Destination: &settings.AwsRegion,
},
&cli.BoolFlag{
Name: "ecr.create_repository",
EnvVars: []string{"PLUGIN_ECR_CREATE_REPOSITORY"},
Usage: "creates the ECR repository if it does not exist",
Destination: &settings.EcrCreateRepository,
},
&cli.StringFlag{
Name: "ecr.lifecycle_policy",
EnvVars: []string{"PLUGIN_ECR_LIFECYCLE_POLICY"},
Usage: "AWS ECR lifecycle policy",
Destination: &settings.EcrLifecyclePolicy,
},
&cli.StringFlag{
Name: "ecr.repository_policy",
EnvVars: []string{"PLUGIN_ECR_REPOSITORY_POLICY"},
Usage: "AWS ECR repository policy",
Destination: &settings.EcrRepositoryPolicy,
},
&cli.BoolFlag{
Name: "ecr.scan_on_push",
EnvVars: []string{"PLUGIN_ECR_SCAN_ON_PUSH"},
Usage: "AWS: whether to enable image scanning on push",
Destination: &settings.EcrScanOnPush,
},
}
}