From 55b8a2182b1b6eecbcb048ea665c8e66032ceffe Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Mon, 21 Feb 2022 11:29:18 +0000 Subject: [PATCH] scripts: dev_cli.sh Support building container before use If `--local` is provided or if the version is not available then build the container before use. This allows combining updates to the Dockerfile with a full CI run. Drop the "--dev" parameter as we only support one container type for simplicity. Signed-off-by: Rob Bradford --- scripts/dev_cli.sh | 62 +++++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/scripts/dev_cli.sh b/scripts/dev_cli.sh index 52d320a52..6fb323f59 100755 --- a/scripts/dev_cli.sh +++ b/scripts/dev_cli.sh @@ -118,9 +118,17 @@ ensure_build_dir() { # Make sure we're using the latest dev container, by just pulling it. ensure_latest_ctr() { - $DOCKER_RUNTIME pull "$CTR_IMAGE" + if [ "$CTR_IMAGE_VERSION" = "local" ]; then + build_container + else + $DOCKER_RUNTIME pull "$CTR_IMAGE" - ok_or_die "Error pulling container image. Aborting." + if [ $? -ne 0 ]; then + build_container + fi + + ok_or_die "Error pulling/building container image. Aborting." + fi } # Fix main directory permissions after a container ran as root. @@ -192,7 +200,6 @@ cmd_help() { echo "" echo " build-container [--type]" echo " Build the Cloud Hypervisor container." - echo " --dev Build dev container. This is the default." echo "" echo " clean []]" echo " Remove the Cloud Hypervisor artifacts." @@ -511,27 +518,7 @@ cmd_tests() { fix_dir_perms $? } -cmd_build-container() { - container_type="dev" - - while [ $# -gt 0 ]; do - case "$1" in - "-h" | "--help") { - cmd_help - exit 1 - } ;; - "--dev") { container_type="dev"; } ;; - "--") { - shift - break - } ;; - *) - die "Unknown build-container argument: $1. Please use --help for help." - ;; - esac - shift - done - +build_container() { ensure_build_dir BUILD_DIR=/tmp/cloud-hypervisor/container/ @@ -543,13 +530,34 @@ cmd_build-container() { [ "$(uname -m)" = "x86_64" ] && TARGETARCH="amd64" $DOCKER_RUNTIME build \ - --target $container_type \ + --target dev \ -t $CTR_IMAGE \ -f $BUILD_DIR/Dockerfile \ --build-arg TARGETARCH=$TARGETARCH \ $BUILD_DIR } +cmd_build-container() { + while [ $# -gt 0 ]; do + case "$1" in + "-h" | "--help") { + cmd_help + exit 1 + } ;; + "--") { + shift + break + } ;; + *) + die "Unknown build-container argument: $1. Please use --help for help." + ;; + esac + shift + done + + build_container +} + cmd_shell() { while [ $# -gt 0 ]; do case "$1" in @@ -602,6 +610,10 @@ while [ $# -gt 0 ]; do cmd_help exit 1 } ;; + --local) { + CTR_IMAGE_VERSION="local" + CTR_IMAGE="${CTR_IMAGE_TAG}:${CTR_IMAGE_VERSION}" + } ;; -*) die "Unknown arg: $1. Please use \`$0 help\` for help." ;;