cmd/create: extra volume and environment variables
Add --volume (-V) and --env (-E) options to the create command to allow extra volumes and environment variables to be specified at container create time.
This commit is contained in:
parent
2099190211
commit
2dc179c175
|
|
@ -8,6 +8,8 @@ toolbox\-create - Create a new Toolbx container
|
|||
[*--distro DISTRO* | *-d DISTRO*]
|
||||
[*--image NAME* | *-i NAME*]
|
||||
[*--release RELEASE* | *-r RELEASE*]
|
||||
[*--volume* | *-V* [SOURCE-VOLUME|HOST-DIR:]CONTAINER-DIR[:OPTIONS]]
|
||||
[*--env* | *-E* NAME[=VALUE]]
|
||||
[*CONTAINER*]
|
||||
|
||||
## DESCRIPTION
|
||||
|
|
|
|||
|
|
@ -49,11 +49,13 @@ const (
|
|||
|
||||
var (
|
||||
createFlags struct {
|
||||
authFile string
|
||||
container string
|
||||
distro string
|
||||
image string
|
||||
release string
|
||||
authFile string
|
||||
container string
|
||||
distro string
|
||||
image string
|
||||
release string
|
||||
extraVolumes []string
|
||||
extraEnvVars []string
|
||||
}
|
||||
|
||||
createToolboxShMounts = []struct {
|
||||
|
|
@ -104,6 +106,18 @@ func init() {
|
|||
"",
|
||||
"Create a Toolbx container for a different operating system release than the host")
|
||||
|
||||
flags.StringArrayVarP(&createFlags.extraVolumes,
|
||||
"volume",
|
||||
"V",
|
||||
nil,
|
||||
"Mount an additional volume in the toolbox container (may be repeated)")
|
||||
|
||||
flags.StringArrayVarP(&createFlags.extraEnvVars,
|
||||
"env",
|
||||
"E",
|
||||
nil,
|
||||
"Define an additional environment variable for the container (may be repeated)")
|
||||
|
||||
createCmd.SetHelpFunc(createHelp)
|
||||
|
||||
if err := createCmd.RegisterFlagCompletionFunc("distro", completionDistroNames); err != nil {
|
||||
|
|
@ -180,14 +194,14 @@ func create(cmd *cobra.Command, args []string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if err := createContainer(container, image, release, createFlags.authFile, true); err != nil {
|
||||
if err := createContainer(container, image, release, createFlags.authFile, createFlags.extraVolumes, createFlags.extraEnvVars, true); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func createContainer(container, image, release, authFile string, showCommandToEnter bool) error {
|
||||
func createContainer(container, image, release, authFile string, extraVolumes []string, extraEnvVars []string, showCommandToEnter bool) error {
|
||||
if container == "" {
|
||||
panic("container not specified")
|
||||
}
|
||||
|
|
@ -473,6 +487,14 @@ func createContainer(container, image, release, authFile string, showCommandToEn
|
|||
createArgs = append(createArgs, runMediaMount...)
|
||||
createArgs = append(createArgs, toolboxShMount...)
|
||||
|
||||
for _, v := range extraVolumes {
|
||||
createArgs = append(createArgs, "--volume", v)
|
||||
}
|
||||
|
||||
for _, e := range extraEnvVars {
|
||||
createArgs = append(createArgs, "--env", e)
|
||||
}
|
||||
|
||||
createArgs = append(createArgs, []string{
|
||||
imageFull,
|
||||
}...)
|
||||
|
|
|
|||
|
|
@ -222,7 +222,7 @@ func runCommand(container string,
|
|||
return nil
|
||||
}
|
||||
|
||||
if err := createContainer(container, image, release, "", false); err != nil {
|
||||
if err := createContainer(container, image, release, "", nil, nil, false); err != nil {
|
||||
return err
|
||||
}
|
||||
} else if containersCount == 1 && defaultContainer {
|
||||
|
|
|
|||
Loading…
Reference in New Issue