| 
									
										
										
										
											2018-04-19 03:00:15 +08:00
										 |  |  | package cli | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // the cli package contains urfave/cli related structs that help make up
 | 
					
						
							|  |  |  | // the command line for buildah commands. it resides here so other projects
 | 
					
						
							|  |  |  | // that vendor in this code can use them too.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2018-06-09 00:55:46 +08:00
										 |  |  | 	"fmt" | 
					
						
							|  |  |  | 	"os" | 
					
						
							|  |  |  | 	"strings" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-13 01:53:12 +08:00
										 |  |  | 	"github.com/opencontainers/runtime-spec/specs-go" | 
					
						
							| 
									
										
										
										
											2018-04-14 06:20:25 +08:00
										 |  |  | 	"github.com/projectatomic/buildah/util" | 
					
						
							| 
									
										
										
										
											2018-04-19 03:00:15 +08:00
										 |  |  | 	"github.com/urfave/cli" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var ( | 
					
						
							| 
									
										
										
										
											2018-06-13 05:21:08 +08:00
										 |  |  | 	runtime     = util.Runtime() | 
					
						
							| 
									
										
										
										
											2018-03-13 01:53:12 +08:00
										 |  |  | 	usernsFlags = []cli.Flag{ | 
					
						
							|  |  |  | 		cli.StringFlag{ | 
					
						
							|  |  |  | 			Name:  "userns", | 
					
						
							|  |  |  | 			Usage: "'container', `path` of user namespace to join, or 'host'", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		cli.StringSliceFlag{ | 
					
						
							|  |  |  | 			Name:  "userns-uid-map", | 
					
						
							|  |  |  | 			Usage: "`containerID:hostID:length` UID mapping to use in user namespace", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		cli.StringSliceFlag{ | 
					
						
							|  |  |  | 			Name:  "userns-gid-map", | 
					
						
							|  |  |  | 			Usage: "`containerID:hostID:length` GID mapping to use in user namespace", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		cli.StringFlag{ | 
					
						
							|  |  |  | 			Name:  "userns-uid-map-user", | 
					
						
							|  |  |  | 			Usage: "`name` of entries from /etc/subuid to use to set user namespace UID mapping", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		cli.StringFlag{ | 
					
						
							|  |  |  | 			Name:  "userns-gid-map-group", | 
					
						
							|  |  |  | 			Usage: "`name` of entries from /etc/subgid to use to set user namespace GID mapping", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	NamespaceFlags = []cli.Flag{ | 
					
						
							|  |  |  | 		cli.StringFlag{ | 
					
						
							|  |  |  | 			Name:  string(specs.IPCNamespace), | 
					
						
							|  |  |  | 			Usage: "'container', `path` of IPC namespace to join, or 'host'", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		cli.StringFlag{ | 
					
						
							|  |  |  | 			Name:  string(specs.NetworkNamespace) + ", net", | 
					
						
							|  |  |  | 			Usage: "'container', `path` of network namespace to join, or 'host'", | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2018-04-14 06:20:25 +08:00
										 |  |  | 		cli.StringFlag{ | 
					
						
							|  |  |  | 			Name:  "cni-config-dir", | 
					
						
							|  |  |  | 			Usage: "`directory` of CNI configuration files", | 
					
						
							|  |  |  | 			Value: util.DefaultCNIConfigDir, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		cli.StringFlag{ | 
					
						
							|  |  |  | 			Name:  "cni-plugin-path", | 
					
						
							|  |  |  | 			Usage: "`path` of CNI network plugins", | 
					
						
							|  |  |  | 			Value: util.DefaultCNIPluginPath, | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2018-03-13 01:53:12 +08:00
										 |  |  | 		cli.StringFlag{ | 
					
						
							|  |  |  | 			Name:  string(specs.PIDNamespace), | 
					
						
							|  |  |  | 			Usage: "'container', `path` of PID namespace to join, or 'host'", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		cli.StringFlag{ | 
					
						
							|  |  |  | 			Name:  string(specs.UTSNamespace), | 
					
						
							|  |  |  | 			Usage: "'container', `path` of UTS namespace to join, or 'host'", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-19 03:00:15 +08:00
										 |  |  | 	BudFlags = []cli.Flag{ | 
					
						
							| 
									
										
										
										
											2018-05-23 00:05:18 +08:00
										 |  |  | 		cli.StringSliceFlag{ | 
					
						
							|  |  |  | 			Name:  "annotation", | 
					
						
							|  |  |  | 			Usage: "Set metadata for an image (default [])", | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2018-04-19 03:00:15 +08:00
										 |  |  | 		cli.StringFlag{ | 
					
						
							|  |  |  | 			Name:  "authfile", | 
					
						
							|  |  |  | 			Usage: "path of the authentication file. Default is ${XDG_RUNTIME_DIR}/containers/auth.json", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		cli.StringSliceFlag{ | 
					
						
							|  |  |  | 			Name:  "build-arg", | 
					
						
							|  |  |  | 			Usage: "`argument=value` to supply to the builder", | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2018-05-08 06:14:44 +08:00
										 |  |  | 		cli.StringFlag{ | 
					
						
							| 
									
										
										
										
											2018-05-06 19:42:01 +08:00
										 |  |  | 			Name:  "cache-from", | 
					
						
							| 
									
										
										
										
											2018-06-07 02:50:42 +08:00
										 |  |  | 			Usage: "Images to utilise as potential cache sources. The build process does not currently support caching so this is a NOOP.", | 
					
						
							| 
									
										
										
										
											2018-05-06 19:42:01 +08:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2018-04-19 03:00:15 +08:00
										 |  |  | 		cli.StringFlag{ | 
					
						
							|  |  |  | 			Name:  "cert-dir", | 
					
						
							|  |  |  | 			Value: "", | 
					
						
							|  |  |  | 			Usage: "use certificates at the specified path to access the registry", | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2018-04-27 00:35:16 +08:00
										 |  |  | 		cli.BoolFlag{ | 
					
						
							|  |  |  | 			Name:  "compress", | 
					
						
							|  |  |  | 			Usage: "This is legacy option, which has no effect on the image", | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2018-04-19 03:00:15 +08:00
										 |  |  | 		cli.StringFlag{ | 
					
						
							|  |  |  | 			Name:  "creds", | 
					
						
							|  |  |  | 			Value: "", | 
					
						
							|  |  |  | 			Usage: "use `[username[:password]]` for accessing the registry", | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2018-06-07 02:50:42 +08:00
										 |  |  | 		cli.BoolFlag{ | 
					
						
							|  |  |  | 			Name:  "disable-content-trust", | 
					
						
							|  |  |  | 			Usage: "This is a Docker specific option and is a NOOP", | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2018-04-19 03:00:15 +08:00
										 |  |  | 		cli.StringSliceFlag{ | 
					
						
							|  |  |  | 			Name:  "file, f", | 
					
						
							|  |  |  | 			Usage: "`pathname or URL` of a Dockerfile", | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2018-05-06 19:16:11 +08:00
										 |  |  | 		cli.BoolFlag{ | 
					
						
							|  |  |  | 			Name:  "force-rm", | 
					
						
							| 
									
										
										
										
											2018-06-14 02:09:45 +08:00
										 |  |  | 			Usage: "Always remove intermediate containers after a build, even if the build is unsuccessful.", | 
					
						
							| 
									
										
										
										
											2018-05-06 19:16:11 +08:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2018-04-19 03:00:15 +08:00
										 |  |  | 		cli.StringFlag{ | 
					
						
							|  |  |  | 			Name:  "format", | 
					
						
							|  |  |  | 			Usage: "`format` of the built image's manifest and metadata", | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2018-04-25 22:00:46 +08:00
										 |  |  | 		cli.StringFlag{ | 
					
						
							|  |  |  | 			Name:  "iidfile", | 
					
						
							| 
									
										
										
										
											2018-03-13 01:53:12 +08:00
										 |  |  | 			Usage: "`file` to write the image ID to", | 
					
						
							| 
									
										
										
										
											2018-04-25 22:00:46 +08:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2018-05-17 02:13:12 +08:00
										 |  |  | 		cli.StringSliceFlag{ | 
					
						
							|  |  |  | 			Name:  "label", | 
					
						
							|  |  |  | 			Usage: "Set metadata for an image (default [])", | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2018-06-09 00:55:46 +08:00
										 |  |  | 		cli.BoolFlag{ | 
					
						
							|  |  |  | 			Name:  "layers", | 
					
						
							|  |  |  | 			Usage: fmt.Sprintf("cache intermediate layers during build (default %t)", UseLayers()), | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2018-05-06 19:42:01 +08:00
										 |  |  | 		cli.BoolFlag{ | 
					
						
							|  |  |  | 			Name:  "no-cache", | 
					
						
							| 
									
										
										
										
											2018-06-09 00:55:46 +08:00
										 |  |  | 			Usage: "Do not use existing cached images for the container build. Build from the start with a new set of cached layers.", | 
					
						
							| 
									
										
										
										
											2018-05-06 19:42:01 +08:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2018-06-06 01:53:39 +08:00
										 |  |  | 		cli.StringFlag{ | 
					
						
							|  |  |  | 			Name:  "logfile", | 
					
						
							|  |  |  | 			Usage: "log to `file` instead of stdout/stderr", | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2018-04-19 03:00:15 +08:00
										 |  |  | 		cli.BoolTFlag{ | 
					
						
							|  |  |  | 			Name:  "pull", | 
					
						
							|  |  |  | 			Usage: "pull the image if not present", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		cli.BoolFlag{ | 
					
						
							|  |  |  | 			Name:  "pull-always", | 
					
						
							|  |  |  | 			Usage: "pull the image, even if a version is present", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		cli.BoolFlag{ | 
					
						
							|  |  |  | 			Name:  "quiet, q", | 
					
						
							|  |  |  | 			Usage: "refrain from announcing build instructions and image read/write progress", | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2018-06-14 02:09:45 +08:00
										 |  |  | 		cli.BoolTFlag{ | 
					
						
							| 
									
										
										
										
											2018-04-27 00:35:16 +08:00
										 |  |  | 			Name:  "rm", | 
					
						
							| 
									
										
										
										
											2018-06-14 02:09:45 +08:00
										 |  |  | 			Usage: "Remove intermediate containers after a successful build (default true)", | 
					
						
							| 
									
										
										
										
											2018-04-27 00:35:16 +08:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2018-04-19 03:00:15 +08:00
										 |  |  | 		cli.StringFlag{ | 
					
						
							|  |  |  | 			Name:  "runtime", | 
					
						
							|  |  |  | 			Usage: "`path` to an alternate runtime", | 
					
						
							| 
									
										
										
										
											2018-06-13 05:21:08 +08:00
										 |  |  | 			Value: runtime, | 
					
						
							| 
									
										
										
										
											2018-04-19 03:00:15 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		cli.StringSliceFlag{ | 
					
						
							|  |  |  | 			Name:  "runtime-flag", | 
					
						
							|  |  |  | 			Usage: "add global flags for the container runtime", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		cli.StringFlag{ | 
					
						
							|  |  |  | 			Name:  "signature-policy", | 
					
						
							|  |  |  | 			Usage: "`pathname` of signature policy file (not usually used)", | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2018-04-27 00:35:16 +08:00
										 |  |  | 		cli.BoolFlag{ | 
					
						
							|  |  |  | 			Name:  "squash", | 
					
						
							| 
									
										
										
										
											2018-06-07 02:50:42 +08:00
										 |  |  | 			Usage: "Squash newly built layers into a single new layer. The build process does not currently support caching so this is a NOOP.", | 
					
						
							| 
									
										
										
										
											2018-04-27 00:35:16 +08:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2018-05-25 17:44:17 +08:00
										 |  |  | 		cli.BoolTFlag{ | 
					
						
							|  |  |  | 			Name:  "stream", | 
					
						
							|  |  |  | 			Usage: "There is no daemon in use, so this command is a NOOP.", | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2018-04-19 03:00:15 +08:00
										 |  |  | 		cli.StringSliceFlag{ | 
					
						
							|  |  |  | 			Name:  "tag, t", | 
					
						
							| 
									
										
										
										
											2018-03-13 01:53:12 +08:00
										 |  |  | 			Usage: "tagged `name` to apply to the built image", | 
					
						
							| 
									
										
										
										
											2018-04-19 03:00:15 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		cli.BoolTFlag{ | 
					
						
							|  |  |  | 			Name:  "tls-verify", | 
					
						
							|  |  |  | 			Usage: "require HTTPS and verify certificates when accessing the registry", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-13 01:53:12 +08:00
										 |  |  | 	FromAndBudFlags = append(append([]cli.Flag{ | 
					
						
							| 
									
										
										
										
											2018-04-19 03:00:15 +08:00
										 |  |  | 		cli.StringSliceFlag{ | 
					
						
							|  |  |  | 			Name:  "add-host", | 
					
						
							|  |  |  | 			Usage: "add a custom host-to-IP mapping (host:ip) (default [])", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		cli.StringFlag{ | 
					
						
							|  |  |  | 			Name:  "cgroup-parent", | 
					
						
							|  |  |  | 			Usage: "optional parent cgroup for the container", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		cli.Uint64Flag{ | 
					
						
							|  |  |  | 			Name:  "cpu-period", | 
					
						
							|  |  |  | 			Usage: "limit the CPU CFS (Completely Fair Scheduler) period", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		cli.Int64Flag{ | 
					
						
							|  |  |  | 			Name:  "cpu-quota", | 
					
						
							|  |  |  | 			Usage: "limit the CPU CFS (Completely Fair Scheduler) quota", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		cli.Uint64Flag{ | 
					
						
							| 
									
										
										
										
											2018-05-09 21:51:58 +08:00
										 |  |  | 			Name:  "cpu-shares, c", | 
					
						
							| 
									
										
										
										
											2018-04-19 03:00:15 +08:00
										 |  |  | 			Usage: "CPU shares (relative weight)", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		cli.StringFlag{ | 
					
						
							|  |  |  | 			Name:  "cpuset-cpus", | 
					
						
							|  |  |  | 			Usage: "CPUs in which to allow execution (0-3, 0,1)", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		cli.StringFlag{ | 
					
						
							|  |  |  | 			Name:  "cpuset-mems", | 
					
						
							|  |  |  | 			Usage: "memory nodes (MEMs) in which to allow execution (0-3, 0,1). Only effective on NUMA systems.", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		cli.StringFlag{ | 
					
						
							|  |  |  | 			Name:  "memory, m", | 
					
						
							|  |  |  | 			Usage: "memory limit (format: <number>[<unit>], where unit = b, k, m or g)", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		cli.StringFlag{ | 
					
						
							|  |  |  | 			Name:  "memory-swap", | 
					
						
							|  |  |  | 			Usage: "swap limit equal to memory plus swap: '-1' to enable unlimited swap", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		cli.StringSliceFlag{ | 
					
						
							|  |  |  | 			Name:  "security-opt", | 
					
						
							| 
									
										
										
										
											2018-03-07 07:13:24 +08:00
										 |  |  | 			Usage: "security options (default [])", | 
					
						
							| 
									
										
										
										
											2018-04-19 03:00:15 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		cli.StringFlag{ | 
					
						
							|  |  |  | 			Name:  "shm-size", | 
					
						
							| 
									
										
										
										
											2018-03-07 07:13:24 +08:00
										 |  |  | 			Usage: "size of '/dev/shm'. The format is `<number><unit>`.", | 
					
						
							| 
									
										
										
										
											2018-04-19 03:00:15 +08:00
										 |  |  | 			Value: "65536k", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		cli.StringSliceFlag{ | 
					
						
							|  |  |  | 			Name:  "ulimit", | 
					
						
							|  |  |  | 			Usage: "ulimit options (default [])", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		cli.StringSliceFlag{ | 
					
						
							|  |  |  | 			Name:  "volume, v", | 
					
						
							|  |  |  | 			Usage: "bind mount a volume into the container (default [])", | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2018-03-13 01:53:12 +08:00
										 |  |  | 	}, usernsFlags...), NamespaceFlags...) | 
					
						
							| 
									
										
										
										
											2018-04-19 03:00:15 +08:00
										 |  |  | ) | 
					
						
							| 
									
										
										
										
											2018-06-09 00:55:46 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | // UseLayers returns true if BUILDAH_LAYERS is set to "1" or "true"
 | 
					
						
							|  |  |  | // otherwise it returns false
 | 
					
						
							|  |  |  | func UseLayers() bool { | 
					
						
							|  |  |  | 	layers := os.Getenv("BUILDAH_LAYERS") | 
					
						
							|  |  |  | 	if strings.ToLower(layers) == "true" || layers == "1" { | 
					
						
							|  |  |  | 		return true | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return false | 
					
						
							|  |  |  | } |