2021-01-11 20:54:49 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-10-13 03:40:58 +00:00
|
|
|
"codeberg.org/woodpecker-plugins/plugin-docker-buildx/plugin"
|
2021-01-11 20:54:49 +00:00
|
|
|
"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"},
|
2021-09-11 19:15:02 +00:00
|
|
|
Usage: "disables docker push",
|
2021-01-11 20:54:49 +00:00
|
|
|
Destination: &settings.Dryrun,
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "remote.url",
|
2021-10-13 03:40:58 +00:00
|
|
|
EnvVars: []string{"CI_REMOTE_URL", "DRONE_REMOTE_URL"},
|
2021-09-11 19:15:02 +00:00
|
|
|
Usage: "sets the git remote url",
|
2021-01-11 20:54:49 +00:00
|
|
|
Destination: &settings.Build.Remote,
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "daemon.mirror",
|
|
|
|
EnvVars: []string{"PLUGIN_MIRROR", "DOCKER_PLUGIN_MIRROR"},
|
2021-09-11 19:15:02 +00:00
|
|
|
Usage: "sets a registry mirror to pull images",
|
2021-01-11 20:54:49 +00:00
|
|
|
Destination: &settings.Daemon.Mirror,
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "daemon.storage-driver",
|
|
|
|
EnvVars: []string{"PLUGIN_STORAGE_DRIVER"},
|
2021-09-11 19:15:02 +00:00
|
|
|
Usage: "sets the docker daemon storage driver",
|
2021-01-11 20:54:49 +00:00
|
|
|
Destination: &settings.Daemon.StorageDriver,
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "daemon.storage-path",
|
|
|
|
EnvVars: []string{"PLUGIN_STORAGE_PATH"},
|
2021-09-11 19:15:02 +00:00
|
|
|
Usage: "sets the docker daemon storage path",
|
|
|
|
Value: "/var/lib/docker",
|
2021-01-11 20:54:49 +00:00
|
|
|
Destination: &settings.Daemon.StoragePath,
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "daemon.bip",
|
|
|
|
EnvVars: []string{"PLUGIN_BIP"},
|
2021-09-11 19:15:02 +00:00
|
|
|
Usage: "allows the docker daemon to bride ip address",
|
2021-01-11 20:54:49 +00:00
|
|
|
Destination: &settings.Daemon.Bip,
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "daemon.mtu",
|
|
|
|
EnvVars: []string{"PLUGIN_MTU"},
|
2021-09-11 19:15:02 +00:00
|
|
|
Usage: "sets docker daemon custom mtu setting",
|
2021-01-11 20:54:49 +00:00
|
|
|
Destination: &settings.Daemon.MTU,
|
|
|
|
},
|
|
|
|
&cli.StringSliceFlag{
|
|
|
|
Name: "daemon.dns",
|
|
|
|
EnvVars: []string{"PLUGIN_CUSTOM_DNS"},
|
2021-09-11 19:15:02 +00:00
|
|
|
Usage: "sets custom docker daemon dns server",
|
2021-01-11 20:54:49 +00:00
|
|
|
Destination: &settings.Daemon.DNS,
|
|
|
|
},
|
|
|
|
&cli.StringSliceFlag{
|
|
|
|
Name: "daemon.dns-search",
|
|
|
|
EnvVars: []string{"PLUGIN_CUSTOM_DNS_SEARCH"},
|
2021-09-11 19:15:02 +00:00
|
|
|
Usage: "sets custom docker daemon dns search domain",
|
2021-01-11 20:54:49 +00:00
|
|
|
Destination: &settings.Daemon.DNSSearch,
|
|
|
|
},
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "daemon.insecure",
|
|
|
|
EnvVars: []string{"PLUGIN_INSECURE"},
|
2021-09-11 19:15:02 +00:00
|
|
|
Usage: "allows the docker daemon to use insecure registries",
|
2021-01-11 20:54:49 +00:00
|
|
|
Destination: &settings.Daemon.Insecure,
|
|
|
|
},
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "daemon.ipv6",
|
|
|
|
EnvVars: []string{"PLUGIN_IPV6"},
|
2021-09-11 19:15:02 +00:00
|
|
|
Usage: "enables docker daemon IPv6 support",
|
2021-01-11 20:54:49 +00:00
|
|
|
Destination: &settings.Daemon.IPv6,
|
|
|
|
},
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "daemon.experimental",
|
|
|
|
EnvVars: []string{"PLUGIN_EXPERIMENTAL"},
|
2021-09-11 19:15:02 +00:00
|
|
|
Usage: "enables docker daemon experimental mode",
|
2021-01-11 20:54:49 +00:00
|
|
|
Destination: &settings.Daemon.Experimental,
|
|
|
|
},
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "daemon.debug",
|
|
|
|
EnvVars: []string{"PLUGIN_DEBUG", "DOCKER_LAUNCH_DEBUG"},
|
2021-09-11 19:15:02 +00:00
|
|
|
Usage: "enables verbose debug mode for the docker daemon",
|
2021-01-11 20:54:49 +00:00
|
|
|
Destination: &settings.Daemon.Debug,
|
|
|
|
},
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "daemon.off",
|
|
|
|
EnvVars: []string{"PLUGIN_DAEMON_OFF"},
|
2021-09-11 19:15:02 +00:00
|
|
|
Usage: "disables the startup of the docker daemon",
|
2021-01-11 20:54:49 +00:00
|
|
|
Destination: &settings.Daemon.Disabled,
|
|
|
|
},
|
2021-07-08 07:00:51 +00:00
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "daemon.buildkit-config",
|
|
|
|
EnvVars: []string{"PLUGIN_BUILDKIT_CONFIG"},
|
2021-09-11 19:15:02 +00:00
|
|
|
Usage: "sets content of the docker buildkit json config",
|
2021-07-08 07:00:51 +00:00
|
|
|
Destination: &settings.Daemon.BuildkitConfig,
|
|
|
|
},
|
2021-01-11 20:54:49 +00:00
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "dockerfile",
|
|
|
|
EnvVars: []string{"PLUGIN_DOCKERFILE"},
|
2021-09-11 19:15:02 +00:00
|
|
|
Usage: "sets dockerfile to use for the image build",
|
|
|
|
Value: "Dockerfile",
|
2021-01-11 20:54:49 +00:00
|
|
|
Destination: &settings.Build.Dockerfile,
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "context",
|
|
|
|
EnvVars: []string{"PLUGIN_CONTEXT"},
|
2021-09-11 19:15:02 +00:00
|
|
|
Usage: "sets the path of the build context to use",
|
|
|
|
Value: ".",
|
2021-01-11 20:54:49 +00:00
|
|
|
Destination: &settings.Build.Context,
|
|
|
|
},
|
|
|
|
&cli.StringSliceFlag{
|
|
|
|
Name: "tags",
|
|
|
|
EnvVars: []string{"PLUGIN_TAG", "PLUGIN_TAGS"},
|
2021-09-11 19:15:02 +00:00
|
|
|
Usage: "sets repository tags to use for the image",
|
2022-10-11 09:38:36 +00:00
|
|
|
Value: cli.NewStringSlice("latest"),
|
2021-01-11 20:54:49 +00:00
|
|
|
FilePath: ".tags",
|
|
|
|
Destination: &settings.Build.Tags,
|
|
|
|
},
|
2023-05-02 19:25:49 +00:00
|
|
|
&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,
|
|
|
|
},
|
2021-01-11 20:54:49 +00:00
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "tags.auto",
|
2022-11-06 12:10:00 +00:00
|
|
|
EnvVars: []string{"PLUGIN_AUTO_TAG"},
|
2021-09-11 19:15:02 +00:00
|
|
|
Usage: "generates tag names automatically based on git branch and git tag",
|
2021-01-11 20:54:49 +00:00
|
|
|
Destination: &settings.Build.TagsAuto,
|
|
|
|
},
|
2022-11-05 02:25:44 +00:00
|
|
|
&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",
|
|
|
|
},
|
2021-01-11 20:54:49 +00:00
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "tags.suffix",
|
|
|
|
EnvVars: []string{"PLUGIN_DEFAULT_SUFFIX", "PLUGIN_AUTO_TAG_SUFFIX"},
|
2021-09-11 19:15:02 +00:00
|
|
|
Usage: "generates tag names with the given suffix",
|
2021-01-11 20:54:49 +00:00
|
|
|
Destination: &settings.Build.TagsSuffix,
|
|
|
|
},
|
2022-09-28 00:16:57 +00:00
|
|
|
&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,
|
|
|
|
},
|
2021-01-11 20:54:49 +00:00
|
|
|
&cli.StringSliceFlag{
|
|
|
|
Name: "args",
|
|
|
|
EnvVars: []string{"PLUGIN_BUILD_ARGS"},
|
2021-09-11 19:15:02 +00:00
|
|
|
Usage: "sets custom build arguments for the build",
|
2021-01-11 20:54:49 +00:00
|
|
|
Destination: &settings.Build.Args,
|
|
|
|
},
|
|
|
|
&cli.StringSliceFlag{
|
|
|
|
Name: "args-from-env",
|
|
|
|
EnvVars: []string{"PLUGIN_BUILD_ARGS_FROM_ENV"},
|
2021-09-11 19:15:02 +00:00
|
|
|
Usage: "forwards environment variables as custom arguments to the build",
|
2021-01-11 20:54:49 +00:00
|
|
|
Destination: &settings.Build.ArgsEnv,
|
|
|
|
},
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "quiet",
|
|
|
|
EnvVars: []string{"PLUGIN_QUIET"},
|
2021-09-11 19:15:02 +00:00
|
|
|
Usage: "enables suppression of the build output",
|
2021-01-11 20:54:49 +00:00
|
|
|
Destination: &settings.Build.Quiet,
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "target",
|
|
|
|
EnvVars: []string{"PLUGIN_TARGET"},
|
2021-09-11 19:15:02 +00:00
|
|
|
Usage: "sets the build target to use",
|
2021-01-11 20:54:49 +00:00
|
|
|
Destination: &settings.Build.Target,
|
|
|
|
},
|
|
|
|
&cli.StringSliceFlag{
|
|
|
|
Name: "cache-from",
|
|
|
|
EnvVars: []string{"PLUGIN_CACHE_FROM"},
|
2021-09-11 19:15:02 +00:00
|
|
|
Usage: "sets images to consider as cache sources",
|
2021-01-11 20:54:49 +00:00
|
|
|
Destination: &settings.Build.CacheFrom,
|
|
|
|
},
|
2022-11-23 15:55:12 +00:00
|
|
|
&cli.StringSliceFlag{
|
|
|
|
Name: "cache-to",
|
|
|
|
EnvVars: []string{"PLUGIN_CACHE_TO"},
|
|
|
|
Usage: "cache destination for the build cache",
|
|
|
|
Destination: &settings.Build.CacheTo,
|
|
|
|
},
|
2021-01-11 20:54:49 +00:00
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "pull-image",
|
|
|
|
EnvVars: []string{"PLUGIN_PULL_IMAGE"},
|
2021-09-11 19:15:02 +00:00
|
|
|
Usage: "enforces to pull base image at build time",
|
2021-01-11 20:54:49 +00:00
|
|
|
Value: true,
|
|
|
|
Destination: &settings.Build.Pull,
|
|
|
|
},
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "compress",
|
|
|
|
EnvVars: []string{"PLUGIN_COMPRESS"},
|
2021-09-11 19:15:02 +00:00
|
|
|
Usage: "enables compression og the build context using gzip",
|
2021-01-11 20:54:49 +00:00
|
|
|
Destination: &settings.Build.Compress,
|
|
|
|
},
|
2022-09-28 13:17:39 +00:00
|
|
|
&cli.StringSliceFlag{
|
2021-01-11 20:54:49 +00:00
|
|
|
Name: "repo",
|
|
|
|
EnvVars: []string{"PLUGIN_REPO"},
|
2021-09-11 19:15:02 +00:00
|
|
|
Usage: "sets repository name for the image",
|
2021-01-11 20:54:49 +00:00
|
|
|
Destination: &settings.Build.Repo,
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "docker.registry",
|
|
|
|
EnvVars: []string{"PLUGIN_REGISTRY", "DOCKER_REGISTRY"},
|
2021-09-11 19:15:02 +00:00
|
|
|
Usage: "sets docker registry to authenticate with",
|
|
|
|
Value: "https://index.docker.io/v1/",
|
2022-10-08 14:02:02 +00:00
|
|
|
Destination: &settings.DefaultLogin.Registry,
|
2021-01-11 20:54:49 +00:00
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "docker.username",
|
|
|
|
EnvVars: []string{"PLUGIN_USERNAME", "DOCKER_USERNAME"},
|
2021-09-11 19:15:02 +00:00
|
|
|
Usage: "sets username to authenticates with",
|
2022-10-08 14:02:02 +00:00
|
|
|
Destination: &settings.DefaultLogin.Username,
|
2021-01-11 20:54:49 +00:00
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "docker.password",
|
|
|
|
EnvVars: []string{"PLUGIN_PASSWORD", "DOCKER_PASSWORD"},
|
2021-09-11 19:15:02 +00:00
|
|
|
Usage: "sets password to authenticates with",
|
2022-10-08 14:02:02 +00:00
|
|
|
Destination: &settings.DefaultLogin.Password,
|
2021-01-11 20:54:49 +00:00
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "docker.email",
|
|
|
|
EnvVars: []string{"PLUGIN_EMAIL", "DOCKER_EMAIL"},
|
2021-09-11 19:15:02 +00:00
|
|
|
Usage: "sets email address to authenticates with",
|
2022-10-08 14:02:02 +00:00
|
|
|
Destination: &settings.DefaultLogin.Email,
|
2021-01-11 20:54:49 +00:00
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "docker.config",
|
|
|
|
EnvVars: []string{"PLUGIN_CONFIG", "DOCKER_PLUGIN_CONFIG"},
|
2021-09-11 19:15:02 +00:00
|
|
|
Usage: "sets content of the docker daemon json config",
|
2022-10-08 14:02:02 +00:00
|
|
|
Destination: &settings.DefaultLogin.Config,
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "logins",
|
|
|
|
EnvVars: []string{"PLUGIN_LOGINS"},
|
|
|
|
Usage: "list of login",
|
|
|
|
Destination: &settings.LoginsRaw,
|
|
|
|
Value: "[]",
|
2021-01-11 20:54:49 +00:00
|
|
|
},
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "docker.purge",
|
|
|
|
EnvVars: []string{"PLUGIN_PURGE"},
|
2021-09-11 19:15:02 +00:00
|
|
|
Usage: "enables cleanup of the docker environment at the end of a build",
|
2021-01-11 20:54:49 +00:00
|
|
|
Value: true,
|
|
|
|
Destination: &settings.Cleanup,
|
|
|
|
},
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "no-cache",
|
|
|
|
EnvVars: []string{"PLUGIN_NO_CACHE"},
|
2021-09-11 19:15:02 +00:00
|
|
|
Usage: "disables the usage of cached intermediate containers",
|
2021-01-11 20:54:49 +00:00
|
|
|
Destination: &settings.Build.NoCache,
|
|
|
|
},
|
|
|
|
&cli.StringSliceFlag{
|
|
|
|
Name: "add-host",
|
|
|
|
EnvVars: []string{"PLUGIN_ADD_HOST"},
|
2021-09-11 19:15:02 +00:00
|
|
|
Usage: "sets additional host:ip mapping",
|
2021-01-11 20:54:49 +00:00
|
|
|
Destination: &settings.Build.AddHost,
|
|
|
|
},
|
|
|
|
&cli.StringSliceFlag{
|
|
|
|
Name: "platforms",
|
|
|
|
EnvVars: []string{"PLUGIN_PLATFORMS"},
|
2021-09-11 19:15:02 +00:00
|
|
|
Usage: "sets target platform for build",
|
2021-01-11 20:54:49 +00:00
|
|
|
Destination: &settings.Build.Platforms,
|
|
|
|
},
|
2022-09-20 16:02:35 +00:00
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "output",
|
|
|
|
EnvVars: []string{"PLUGIN_OUTPUT"},
|
|
|
|
Usage: "sets build output type and destination configuration",
|
|
|
|
Destination: &settings.Build.Output,
|
|
|
|
},
|
2021-01-11 20:54:49 +00:00
|
|
|
}
|
|
|
|
}
|