diff options
| author | Bruce Ashfield <bruce.ashfield@gmail.com> | 2026-01-12 16:13:45 +0000 |
|---|---|---|
| committer | Bruce Ashfield <bruce.ashfield@gmail.com> | 2026-02-09 03:32:52 +0000 |
| commit | f865a238a564e4d8a8c522ed560e089bc2f69f99 (patch) | |
| tree | 3a3db72589952b300d5e6abd76d4d0bd3ec4bb21 /recipes-containers/vcontainer/files/vcontainer-common.sh | |
| parent | 87ed625c043e4cdbabf569227b189823cd08db8e (diff) | |
| download | meta-virtualization-f865a238a564e4d8a8c522ed560e089bc2f69f99.tar.gz | |
vdkr: add registry configuration and pull fallback
Add registry support to vdkr:
- vconfig registry command for persistent config
- --registry flag for one-off usage
- Registry-first, Docker Hub fallback for pulls
- Baked-in registry config via CONTAINER_REGISTRY_URL
- Image commands (inspect, history, rmi, images) work without transform
Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
Diffstat (limited to 'recipes-containers/vcontainer/files/vcontainer-common.sh')
| -rwxr-xr-x | recipes-containers/vcontainer/files/vcontainer-common.sh | 95 |
1 files changed, 93 insertions, 2 deletions
diff --git a/recipes-containers/vcontainer/files/vcontainer-common.sh b/recipes-containers/vcontainer/files/vcontainer-common.sh index b0623164..f10243f1 100755 --- a/recipes-containers/vcontainer/files/vcontainer-common.sh +++ b/recipes-containers/vcontainer/files/vcontainer-common.sh | |||
| @@ -134,6 +134,7 @@ config_default() { | |||
| 134 | verbose) echo "false" ;; | 134 | verbose) echo "false" ;; |
| 135 | idle-timeout) echo "1800" ;; # 30 minutes | 135 | idle-timeout) echo "1800" ;; # 30 minutes |
| 136 | auto-daemon) echo "true" ;; # Auto-start daemon by default | 136 | auto-daemon) echo "true" ;; # Auto-start daemon by default |
| 137 | registry) echo "" ;; # Default registry for unqualified images | ||
| 137 | *) echo "" ;; | 138 | *) echo "" ;; |
| 138 | esac | 139 | esac |
| 139 | } | 140 | } |
| @@ -404,11 +405,12 @@ ${BOLD}CONFIGURATION (vconfig):${NC} | |||
| 404 | ${CYAN}vconfig${NC} <key> <value> Set configuration value | 405 | ${CYAN}vconfig${NC} <key> <value> Set configuration value |
| 405 | ${CYAN}vconfig${NC} <key> --reset Reset to default value | 406 | ${CYAN}vconfig${NC} <key> --reset Reset to default value |
| 406 | 407 | ||
| 407 | Supported keys: arch, timeout, state-dir, verbose, idle-timeout, auto-daemon | 408 | Supported keys: arch, timeout, state-dir, verbose, idle-timeout, auto-daemon, registry |
| 408 | Config file: \$CONFIG_DIR/config (default: ~/.config/${VCONTAINER_RUNTIME_NAME}/config) | 409 | Config file: \$CONFIG_DIR/config (default: ~/.config/${VCONTAINER_RUNTIME_NAME}/config) |
| 409 | 410 | ||
| 410 | idle-timeout: Daemon idle timeout in seconds [default: 1800] | 411 | idle-timeout: Daemon idle timeout in seconds [default: 1800] |
| 411 | auto-daemon: Auto-start daemon on first command [default: true] | 412 | auto-daemon: Auto-start daemon on first command [default: true] |
| 413 | registry: Default registry for unqualified images (e.g., 10.0.2.2:5000/yocto) | ||
| 412 | 414 | ||
| 413 | ${BOLD}GLOBAL OPTIONS:${NC} | 415 | ${BOLD}GLOBAL OPTIONS:${NC} |
| 414 | --arch, -a <arch> Target architecture: x86_64 or aarch64 [default: ${DEFAULT_ARCH}] | 416 | --arch, -a <arch> Target architecture: x86_64 or aarch64 [default: ${DEFAULT_ARCH}] |
| @@ -421,6 +423,8 @@ ${BOLD}GLOBAL OPTIONS:${NC} | |||
| 421 | --input-storage <tar> Load ${RUNTIME_UPPER} state from tar before command | 423 | --input-storage <tar> Load ${RUNTIME_UPPER} state from tar before command |
| 422 | --no-kvm Disable KVM acceleration (use TCG emulation) | 424 | --no-kvm Disable KVM acceleration (use TCG emulation) |
| 423 | --no-daemon Run in ephemeral mode (don't auto-start/use daemon) | 425 | --no-daemon Run in ephemeral mode (don't auto-start/use daemon) |
| 426 | --registry <url> Default registry for unqualified images (e.g., 10.0.2.2:5000/yocto) | ||
| 427 | --insecure-registry <host:port> Mark registry as insecure (HTTP). Can repeat. | ||
| 424 | --verbose, -v Enable verbose output | 428 | --verbose, -v Enable verbose output |
| 425 | --help, -h Show this help | 429 | --help, -h Show this help |
| 426 | 430 | ||
| @@ -467,6 +471,13 @@ ${BOLD}EXAMPLES:${NC} | |||
| 467 | # Pull an image from a registry | 471 | # Pull an image from a registry |
| 468 | ${PROG_NAME} pull alpine:latest | 472 | ${PROG_NAME} pull alpine:latest |
| 469 | 473 | ||
| 474 | # Pull from local registry (configure once, use everywhere) | ||
| 475 | ${PROG_NAME} vconfig registry 10.0.2.2:5000/yocto # Set default registry | ||
| 476 | ${PROG_NAME} pull container-base # Pulls from 10.0.2.2:5000/yocto/container-base | ||
| 477 | |||
| 478 | # Or use --registry for one-off pulls | ||
| 479 | ${PROG_NAME} --registry 10.0.2.2:5000/yocto pull container-base | ||
| 480 | |||
| 470 | # vrun: convenience wrapper (clears entrypoint when command given) | 481 | # vrun: convenience wrapper (clears entrypoint when command given) |
| 471 | ${PROG_NAME} vrun myapp:latest /bin/ls -la # Runs /bin/ls directly, not via entrypoint | 482 | ${PROG_NAME} vrun myapp:latest /bin/ls -la # Runs /bin/ls directly, not via entrypoint |
| 472 | 483 | ||
| @@ -538,6 +549,12 @@ build_runner_args() { | |||
| 538 | args+=("--port-forward" "$pf") | 549 | args+=("--port-forward" "$pf") |
| 539 | done | 550 | done |
| 540 | 551 | ||
| 552 | # Add registry configuration | ||
| 553 | [ -n "$REGISTRY" ] && args+=("--registry" "$REGISTRY") | ||
| 554 | for reg in "${INSECURE_REGISTRIES[@]}"; do | ||
| 555 | args+=("--insecure-registry" "$reg") | ||
| 556 | done | ||
| 557 | |||
| 541 | echo "${args[@]}" | 558 | echo "${args[@]}" |
| 542 | } | 559 | } |
| 543 | 560 | ||
| @@ -551,6 +568,8 @@ INTERACTIVE="false" | |||
| 551 | PORT_FORWARDS=() | 568 | PORT_FORWARDS=() |
| 552 | DISABLE_KVM="false" | 569 | DISABLE_KVM="false" |
| 553 | NO_DAEMON="false" | 570 | NO_DAEMON="false" |
| 571 | REGISTRY="" | ||
| 572 | INSECURE_REGISTRIES=() | ||
| 554 | COMMAND="" | 573 | COMMAND="" |
| 555 | COMMAND_ARGS=() | 574 | COMMAND_ARGS=() |
| 556 | 575 | ||
| @@ -611,6 +630,14 @@ while [ $# -gt 0 ]; do | |||
| 611 | NO_DAEMON="true" | 630 | NO_DAEMON="true" |
| 612 | shift | 631 | shift |
| 613 | ;; | 632 | ;; |
| 633 | --registry) | ||
| 634 | REGISTRY="$2" | ||
| 635 | shift 2 | ||
| 636 | ;; | ||
| 637 | --insecure-registry) | ||
| 638 | INSECURE_REGISTRIES+=("$2") | ||
| 639 | shift 2 | ||
| 640 | ;; | ||
| 614 | -it|--interactive) | 641 | -it|--interactive) |
| 615 | INTERACTIVE="true" | 642 | INTERACTIVE="true" |
| 616 | shift | 643 | shift |
| @@ -683,6 +710,11 @@ if [ "$STATELESS" != "true" ] && [ -z "$STATE_DIR" ] && [ -z "$INPUT_STORAGE" ]; | |||
| 683 | STATE_DIR="$DEFAULT_STATE_DIR/$TARGET_ARCH" | 710 | STATE_DIR="$DEFAULT_STATE_DIR/$TARGET_ARCH" |
| 684 | fi | 711 | fi |
| 685 | 712 | ||
| 713 | # Read registry from config if not set via CLI | ||
| 714 | if [ -z "$REGISTRY" ]; then | ||
| 715 | REGISTRY=$(config_get "registry" "") | ||
| 716 | fi | ||
| 717 | |||
| 686 | # Check runner exists | 718 | # Check runner exists |
| 687 | if [ ! -x "$RUNNER" ]; then | 719 | if [ ! -x "$RUNNER" ]; then |
| 688 | echo -e "${RED}[$VCONTAINER_RUNTIME_NAME]${NC} Runner script not found: $RUNNER" >&2 | 720 | echo -e "${RED}[$VCONTAINER_RUNTIME_NAME]${NC} Runner script not found: $RUNNER" >&2 |
| @@ -1122,6 +1154,65 @@ parse_and_prepare_volumes() { | |||
| 1122 | 1154 | ||
| 1123 | # Handle commands | 1155 | # Handle commands |
| 1124 | case "$COMMAND" in | 1156 | case "$COMMAND" in |
| 1157 | image) | ||
| 1158 | # Handle "docker image *" compound commands | ||
| 1159 | # docker image ls → docker images | ||
| 1160 | # docker image rm → docker rmi | ||
| 1161 | # docker image pull → docker pull | ||
| 1162 | # etc. | ||
| 1163 | if [ ${#COMMAND_ARGS[@]} -lt 1 ]; then | ||
| 1164 | echo -e "${RED}[$VCONTAINER_RUNTIME_NAME]${NC} image requires a subcommand (ls, rm, pull, inspect, tag, push, prune)" >&2 | ||
| 1165 | exit 1 | ||
| 1166 | fi | ||
| 1167 | SUBCMD="${COMMAND_ARGS[0]}" | ||
| 1168 | SUBCMD_ARGS=("${COMMAND_ARGS[@]:1}") | ||
| 1169 | case "$SUBCMD" in | ||
| 1170 | ls|list) | ||
| 1171 | run_runtime_command "$VCONTAINER_RUNTIME_CMD images ${SUBCMD_ARGS[*]}" | ||
| 1172 | ;; | ||
| 1173 | rm|remove) | ||
| 1174 | run_runtime_command "$VCONTAINER_RUNTIME_CMD rmi ${SUBCMD_ARGS[*]}" | ||
| 1175 | ;; | ||
| 1176 | pull) | ||
| 1177 | # Reuse pull logic - set COMMAND_ARGS and fall through | ||
| 1178 | COMMAND_ARGS=("${SUBCMD_ARGS[@]}") | ||
| 1179 | if [ ${#COMMAND_ARGS[@]} -lt 1 ]; then | ||
| 1180 | echo -e "${RED}[$VCONTAINER_RUNTIME_NAME]${NC} image pull requires <image>" >&2 | ||
| 1181 | exit 1 | ||
| 1182 | fi | ||
| 1183 | IMAGE_NAME="${COMMAND_ARGS[0]}" | ||
| 1184 | if daemon_is_running; then | ||
| 1185 | run_runtime_command "$VCONTAINER_RUNTIME_CMD pull $IMAGE_NAME && $VCONTAINER_RUNTIME_CMD images" | ||
| 1186 | else | ||
| 1187 | NETWORK="true" | ||
| 1188 | RUNNER_ARGS=$(build_runner_args) | ||
| 1189 | "$RUNNER" $RUNNER_ARGS -- "$VCONTAINER_RUNTIME_CMD pull $IMAGE_NAME && $VCONTAINER_RUNTIME_CMD images" | ||
| 1190 | fi | ||
| 1191 | ;; | ||
| 1192 | inspect) | ||
| 1193 | run_runtime_command "$VCONTAINER_RUNTIME_CMD inspect ${SUBCMD_ARGS[*]}" | ||
| 1194 | ;; | ||
| 1195 | tag) | ||
| 1196 | run_runtime_command "$VCONTAINER_RUNTIME_CMD tag ${SUBCMD_ARGS[*]}" | ||
| 1197 | ;; | ||
| 1198 | push) | ||
| 1199 | NETWORK="true" | ||
| 1200 | run_runtime_command "$VCONTAINER_RUNTIME_CMD push ${SUBCMD_ARGS[*]}" | ||
| 1201 | ;; | ||
| 1202 | prune) | ||
| 1203 | run_runtime_command "$VCONTAINER_RUNTIME_CMD image prune ${SUBCMD_ARGS[*]}" | ||
| 1204 | ;; | ||
| 1205 | history) | ||
| 1206 | run_runtime_command "$VCONTAINER_RUNTIME_CMD history ${SUBCMD_ARGS[*]}" | ||
| 1207 | ;; | ||
| 1208 | *) | ||
| 1209 | echo -e "${RED}[$VCONTAINER_RUNTIME_NAME]${NC} Unknown image subcommand: $SUBCMD" >&2 | ||
| 1210 | echo -e "${YELLOW}[$VCONTAINER_RUNTIME_NAME]${NC} Valid subcommands: ls, rm, pull, inspect, tag, push, prune, history" >&2 | ||
| 1211 | exit 1 | ||
| 1212 | ;; | ||
| 1213 | esac | ||
| 1214 | ;; | ||
| 1215 | |||
| 1125 | images) | 1216 | images) |
| 1126 | # runtime images | 1217 | # runtime images |
| 1127 | run_runtime_command "$VCONTAINER_RUNTIME_CMD images ${COMMAND_ARGS[*]}" | 1218 | run_runtime_command "$VCONTAINER_RUNTIME_CMD images ${COMMAND_ARGS[*]}" |
| @@ -1542,7 +1633,7 @@ case "$COMMAND" in | |||
| 1542 | 1633 | ||
| 1543 | vconfig) | 1634 | vconfig) |
| 1544 | # Configuration management (runs on host, not in VM) | 1635 | # Configuration management (runs on host, not in VM) |
| 1545 | VALID_KEYS="arch timeout state-dir verbose idle-timeout auto-daemon" | 1636 | VALID_KEYS="arch timeout state-dir verbose idle-timeout auto-daemon registry" |
| 1546 | 1637 | ||
| 1547 | if [ ${#COMMAND_ARGS[@]} -lt 1 ]; then | 1638 | if [ ${#COMMAND_ARGS[@]} -lt 1 ]; then |
| 1548 | # Show all config | 1639 | # Show all config |
