From 1d5ef29f0134d9a46ab36ace35ed4f9257c01991 Mon Sep 17 00:00:00 2001 From: Urvashi Mohnani Date: Wed, 26 Jul 2023 09:40:51 -0400 Subject: [PATCH] Add podman farm subcommand Signed-off-by: Urvashi Mohnani --- cmd/podman/farm/farm.go | 49 +++++++++++++++++++++++++++ cmd/podman/main.go | 1 + docs/source/markdown/podman-farm.1.md | 27 +++++++++++++++ docs/source/markdown/podman.1.md | 1 + hack/xref-helpmsgs-manpages | 1 + 5 files changed, 79 insertions(+) create mode 100644 cmd/podman/farm/farm.go create mode 100644 docs/source/markdown/podman-farm.1.md diff --git a/cmd/podman/farm/farm.go b/cmd/podman/farm/farm.go new file mode 100644 index 0000000000..fd263bd3af --- /dev/null +++ b/cmd/podman/farm/farm.go @@ -0,0 +1,49 @@ +package farm + +import ( + "github.com/containers/podman/v4/cmd/podman/registry" + "github.com/containers/podman/v4/cmd/podman/validate" + "github.com/spf13/cobra" +) + +var ( + // Command: podman _farm_ + farmCmd = &cobra.Command{ + Use: "farm", + Short: "Farm out builds to remote machines", + Long: "Farm out builds to remote machines that podman can connect to via podman system connection", + RunE: validate.SubCommandExists, + } +) + +var ( + // Temporary struct to hold cli values. + farmOpts = struct { + Farm string + Local bool + }{} +) + +func init() { + registry.Commands = append(registry.Commands, registry.CliCommand{ + Command: farmCmd, + }) + farmCmd.Hidden = true + + flags := farmCmd.Flags() + podmanConfig := registry.PodmanConfig() + + farmFlagName := "farm" + // If remote, don't read the client's containers.conf file + defaultFarm := "" + if !registry.IsRemote() { + defaultFarm = podmanConfig.ContainersConfDefaultsRO.Farms.Default + } + flags.StringVarP(&farmOpts.Farm, farmFlagName, "f", defaultFarm, "Farm to use for builds") + + localFlagName := "local" + // Default for local is true and hide this flag for the remote use case + if !registry.IsRemote() { + flags.BoolVarP(&farmOpts.Local, localFlagName, "l", true, "Build image on local machine including on farm nodes") + } +} diff --git a/cmd/podman/main.go b/cmd/podman/main.go index 3a359e4157..dcc0d1eca3 100644 --- a/cmd/podman/main.go +++ b/cmd/podman/main.go @@ -7,6 +7,7 @@ import ( "strings" _ "github.com/containers/podman/v4/cmd/podman/completion" + _ "github.com/containers/podman/v4/cmd/podman/farm" _ "github.com/containers/podman/v4/cmd/podman/generate" _ "github.com/containers/podman/v4/cmd/podman/healthcheck" _ "github.com/containers/podman/v4/cmd/podman/images" diff --git a/docs/source/markdown/podman-farm.1.md b/docs/source/markdown/podman-farm.1.md new file mode 100644 index 0000000000..5ba43785a3 --- /dev/null +++ b/docs/source/markdown/podman-farm.1.md @@ -0,0 +1,27 @@ +% podman-farm 1 + +## NAME +podman\-farm - Farm out builds to machines running podman for different architectures + +## SYNOPSIS +**podman farm** *subcommand* + +## DESCRIPTION +Farm out builds to machines running podman for different architectures. + +Manage farms by creating, updating, and removing them. + +## COMMANDS + +| Command | Man Page | Description | +| -------- | ------------------------------------------------------------- | ------------------------ | +| create | [podman-farm\-create(1)](podman-farm-create.1.md) | Create a new farm | +| list | [podman-farm\-list(1)](podman-farm-list.1.md) | List the existing farms | +| remove | [podman-farm\-remove(1)](podman-farm-remove.1.md) | Delete one or more farms | +| update | [podman-farm\-update(1)](podman-farm-update.1.md) | Update an existing farm | + +## SEE ALSO +**[podman(1)](podman.1.md)** + +## HISTORY +July 2023, Originally compiled by Urvashi Mohnani (umohnani at redhat dot com) diff --git a/docs/source/markdown/podman.1.md b/docs/source/markdown/podman.1.md index 100b34cf84..2d2f42a436 100644 --- a/docs/source/markdown/podman.1.md +++ b/docs/source/markdown/podman.1.md @@ -313,6 +313,7 @@ the exit codes follow the `chroot` standard, see below: | [podman-attach(1)](podman-attach.1.md) | Attach to a running container. | | [podman-auto-update(1)](podman-auto-update.1.md) | Auto update containers according to their auto-update policy | | [podman-build(1)](podman-build.1.md) | Build a container image using a Containerfile. | +| [podman-farm(1)](podman-farm.1.md) | Farm out builds to machines running podman for different architectures | | [podman-commit(1)](podman-commit.1.md) | Create new image based on the changed container. | | [podman-completion(1)](podman-completion.1.md) | Generate shell completion scripts | | [podman-compose(1)](podman-compose.1.md) | Run Compose workloads via an external compose provider. | diff --git a/hack/xref-helpmsgs-manpages b/hack/xref-helpmsgs-manpages index dbf6d9b981..781e200b33 100755 --- a/hack/xref-helpmsgs-manpages +++ b/hack/xref-helpmsgs-manpages @@ -107,6 +107,7 @@ my %Skip_Subcommand = map { $_ => 1 } ( "help", # has no man page "completion", # internal (hidden) subcommand "compose", # external tool, outside of our control + "farm", # hidden subcommand till it is fully implemented - remove this once done ); # END user-customizable section