Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/create, doc/toolbox-create, sh: Add flag --volume to create command. #633

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/toolbox-create.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ toolbox\-create - Create a new toolbox container
[*--distro DISTRO* | *-d DISTRO*]
[*--image NAME* | *-i NAME*]
[*--release RELEASE* | *-r RELEASE*]
[*--volume BINDMOUNT*]...

## DESCRIPTION

Expand Down Expand Up @@ -52,6 +53,11 @@ used with `--release`.
Create a toolbox container for a different operating system RELEASE than the
host. Cannot be used with `--image`.

**--volume** BINDMOUNT

Create the toolbox container with additional bind mounts. Use the same format as
--volume of podman. Can be specified multiple times.

## EXAMPLES

### Create a toolbox container using the default image matching the host OS
Expand Down
10 changes: 10 additions & 0 deletions src/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ var (
distro string
image string
release string
volumes []string
}

createToolboxShMounts = []struct {
Expand Down Expand Up @@ -90,6 +91,11 @@ func init() {
"",
"Create a toolbox container for a different operating system release than the host")

flags.StringArrayVar(&createFlags.volumes,
"volume",
[]string{},
"Create the toolbox container with additional bind mounts.")

createCmd.SetHelpFunc(createHelp)
rootCmd.AddCommand(createCmd)
}
Expand Down Expand Up @@ -432,6 +438,10 @@ func createContainer(container, image, release string, showCommandToEnter bool)
createArgs = append(createArgs, runMediaMount...)
createArgs = append(createArgs, toolboxShMount...)

for _, additionalMount := range createFlags.volumes {
createArgs = append(createArgs, "--volume", additionalMount)
}

createArgs = append(createArgs, []string{
imageFull,
}...)
Expand Down
7 changes: 7 additions & 0 deletions toolbox
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ release_default=""
spinner_animation="[>----] [=>---] [==>--] [===>-] [====>] [----<] [---<=] [--<==] [-<===] [<====]"
spinner_template="toolbox-spinner-XXXXXXXXXX"
tab="$(printf '\t')"
toolbox_additional_binds=()
toolbox_command_path=""
toolbox_container=""
toolbox_container_default=""
Expand Down Expand Up @@ -1104,6 +1105,7 @@ create()
--volume /tmp:/run/host/tmp:rslave \
--volume /usr:/run/host/usr:"$usr_mount_destination_flags",rslave \
--volume /var:/run/host/var:rslave \
"${toolbox_additional_binds[@]}"
"$base_toolbox_image_full" \
toolbox --verbose init-container \
--home "$HOME" \
Expand Down Expand Up @@ -2411,6 +2413,11 @@ case $op in
exit_if_non_positive_argument --release "$arg"
release=$arg
;;
--volume )
shift
exit_if_missing_argument --volume "$1"
toolbox_additional_binds+=(--volume "$1")
;;
* )
exit_if_unrecognized_option "$1"
esac
Expand Down