-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
this command can run user commands inside container. Signed-off-by: Karel Šimon <ksimon@redhat.com>
- Loading branch information
Showing
3 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"os" | ||
|
||
"github.com/fromanirh/pack8s/internal/pkg/podman" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type runCommandOptions struct { | ||
command string | ||
} | ||
|
||
var runCommandOpt runCommandOptions | ||
|
||
// NewRunCommandCommand runs given command inside container | ||
func NewRunCommandCommand() *cobra.Command { | ||
runCMD := &cobra.Command{ | ||
Use: "run-command", | ||
Short: "run-command runs given command in container", | ||
RunE: runCommand, | ||
Args: cobra.ExactArgs(1), | ||
} | ||
|
||
runCMD.Flags().StringVarP(&runCommandOpt.command, "command", "x", "", "command which will be executed in container") | ||
|
||
return runCMD | ||
} | ||
|
||
func runCommand(cmd *cobra.Command, args []string) error { | ||
containerID := args[0] | ||
|
||
podmanSocket, err := cmd.Flags().GetString("podman-socket") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ctx := context.Background() | ||
|
||
hnd, err := podman.NewHandle(ctx, podmanSocket) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return hnd.Exec(containerID, []string{runCommandOpt.command}, os.Stdout) | ||
} |