Add -v/--volume to create a named volume mapped to a host directory
Creates the host directory if missing (warning if it already exists,
another if it's non-empty) and records name -> directory in the config
file's new "volumes" section. Fails if the name or directory is already
used by an existing volume.
This is a distinct concept from OciImageConfig::volumes (an image's own
declared mount points, still unconsumed) -- a user-defined volume, meant
to be referenced by name once -r/--run starts actually mounting volumes.
config_file.{h,cpp} gains write_config_file(), symmetric to the existing
load_config_file(), built on libyaml's document-building/emitter API.
Rewrites the whole file each time; global.log-level round-trips
untouched alongside the new volumes section.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gv3s5jckJKzh6JkMoi2Akz
This commit is contained in:
@@ -17,9 +17,11 @@ running kernel actually supports, instead of requiring the full set.
|
||||
## Status
|
||||
|
||||
Early-stage. Mounting, running, and dropping privileges to a specific user/group all
|
||||
work. Volumes and image-declared networking (`Volumes`/`ExposedPorts`/`Env` from the
|
||||
image config) are parsed but not yet applied, and there's no background/daemonized
|
||||
run mode yet.
|
||||
work. Named volumes (`-v/--volume`) can be created and are persisted in the config
|
||||
file, but aren't consumed by `-r/--run` yet. Image-declared networking
|
||||
(`ExposedPorts`/`Env` from the image config, and the image's own separately-declared
|
||||
`Volumes`) are parsed but not yet applied, and there's no background/daemonized run
|
||||
mode yet.
|
||||
|
||||
## Requirements
|
||||
|
||||
@@ -55,6 +57,7 @@ slocker-lite -r|--run <image.tar> [-- <command> [args...]]
|
||||
slocker-lite -u|--umount <layer-id>
|
||||
slocker-lite -c|--cleanup <layer-id>
|
||||
slocker-lite -l|--list-images <directory>
|
||||
slocker-lite -v|--volume <name> <directory>
|
||||
slocker-lite -t|--test
|
||||
slocker-lite -h|--help
|
||||
slocker-lite -V|--version
|
||||
@@ -70,6 +73,7 @@ slocker-lite -V|--version
|
||||
| `--user <user>` | With `--run`, run the command as this user (name or numeric uid) instead of the image's own declared user (or root, if it declares none). Resolved against the image's own `/etc/passwd`. Only takes effect when `--run` executes as root. |
|
||||
| `--group <group>` | With `--user`, use this group (name or numeric gid) instead of the user's primary group. |
|
||||
| `-l, --list-images <dir>` | List OCI Image Layout tars (`*.tar`, `*.tar.*`) found directly in `<dir>`, with their `name:tag`. |
|
||||
| `-v, --volume <name> <dir>` | Create a named volume mapped to a host directory (created if missing), recorded in the config file's `volumes` section. Fails if the name or directory is already used by an existing volume. |
|
||||
| `-t, --test` | Print which `bwrap --unshare-xxx` namespaces the running kernel supports. |
|
||||
| `--log-level <level>` | Set log verbosity (`trace`, `debug`, `info`, `warn`, `error`, `critical`, `off`). |
|
||||
| `-h, --help` | Print usage and exit. |
|
||||
@@ -92,6 +96,9 @@ sudo ./buildDir/slocker-lite -r myimage.tar --user git
|
||||
|
||||
# List every OCI image tar in a directory
|
||||
./buildDir/slocker-lite -l ./images
|
||||
|
||||
# Create a named volume backed by a host directory
|
||||
./buildDir/slocker-lite -v mydata ~/slocker-volumes/mydata
|
||||
```
|
||||
|
||||
## Configuration
|
||||
@@ -99,17 +106,21 @@ sudo ./buildDir/slocker-lite -r myimage.tar --user git
|
||||
Persistent settings can be kept in a local YAML config file at
|
||||
`$XDG_CONFIG_HOME/slocker-lite/config.yaml` (falling back to
|
||||
`$HOME/.config/slocker-lite/config.yaml` if `XDG_CONFIG_HOME` isn't set). The file is
|
||||
organized into sections; only `global` exists today:
|
||||
organized into sections:
|
||||
|
||||
```yaml
|
||||
global:
|
||||
log-level: debug
|
||||
volumes:
|
||||
mydata: /home/user/slocker-volumes/mydata
|
||||
```
|
||||
|
||||
Only options that make sense as a standing preference are supported here — right now
|
||||
just `log-level` (one-shot commands like `--mount`/`--run`/`--user` don't belong in a
|
||||
config file). A missing config file is fine (nothing is overridden); an explicit
|
||||
`--log-level` on the command line always overrides the config file.
|
||||
`global.log-level` is the only standing preference supported today (one-shot
|
||||
commands like `--mount`/`--run`/`--user` don't belong in a config file). An explicit
|
||||
`--log-level` on the command line always overrides the config file. The `volumes`
|
||||
section is managed by `-v/--volume` (see above) rather than hand-edited — it's not
|
||||
consumed by `-r/--run` yet. A missing config file is fine either way (nothing is
|
||||
overridden, and one gets created the first time `-v/--volume` is used).
|
||||
|
||||
## How it works
|
||||
|
||||
|
||||
Reference in New Issue
Block a user