From d9d2294e96268012c6e1fc2239748ea49d53bbaf Mon Sep 17 00:00:00 2001 From: Alexandru Avadanii Date: Sun, 7 Jan 2018 01:07:15 +0100 Subject: [PATCH] lib.sh: Cache base image(s) between deploys Fingerprint and re-use base image artifacts. Change-Id: Ic7a73c04e27d25addd50e4e9880619a0028956d3 Signed-off-by: Alexandru Avadanii (cherry picked from commit 1815bdaf0c1765cc1fcb48031f8291409861b0b2) --- mcp/scripts/lib.sh | 49 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/mcp/scripts/lib.sh b/mcp/scripts/lib.sh index be95f8b0e..c258b66fb 100644 --- a/mcp/scripts/lib.sh +++ b/mcp/scripts/lib.sh @@ -249,22 +249,36 @@ function prepare_vms { local repos_pkgs_str=$1; shift # ^-sep list of repos, pkgs to install/rm local vnodes=("$@") local image=base_image_opnfv_fuel.img + local vcp_image=${image%.*}_vcp.img + local _o=${base_image/*\/} + local _h=$(echo "${repos_pkgs_str}.$(md5sum "${image_dir}/${_o}")" | \ + md5sum | cut -c -8) + local _tmp - __kernel_modules "${image_dir}" cleanup_uefi cleanup_vms get_base_image "${base_image}" "${image_dir}" + IFS='^' read -r -a repos_pkgs <<< "${repos_pkgs_str}" - rm -f "${image_dir}/${image%.*}"* - if [[ ! "${repos_pkgs_str}" =~ ^\^+$ ]]; then - IFS='^' read -r -a repos_pkgs <<< "${repos_pkgs_str}" - cp "${image_dir}/${base_image/*\/}" "${image_dir}/${image}" - mount_image "${image}" "${image_dir}" - apt_repos_pkgs_image "${repos_pkgs[@]:0:4}" - cleanup_mounts + echo "[INFO] Lookup cache / build patched base image for fingerprint: ${_h}" + _tmp="${image%.*}.${_h}.img" + if [ -f "$(readlink -f "${image_dir}/${_tmp}")" ]; then + echo "[INFO] Patched base image found" else - ln -sf "${image_dir}/${base_image/*\/}" "${image_dir}/${image}" + rm -f "${image_dir}/${image%.*}"* + if [[ ! "${repos_pkgs_str}" =~ ^\^+$ ]]; then + echo "[INFO] Patching base image ..." + cp "${image_dir}/${_o}" "${image_dir}/${_tmp}" + __kernel_modules "${image_dir}" + mount_image "${_tmp}" "${image_dir}" + apt_repos_pkgs_image "${repos_pkgs[@]:0:4}" + cleanup_mounts + else + echo "[INFO] No patching required, using vanilla base image" + ln -sf "${image_dir}/${_o}" "${image_dir}/${_tmp}" + fi fi + ln -sf "${image_dir}/${_tmp}" "${image_dir}/${image}" # CWD should be # shellcheck disable=SC2016 @@ -281,10 +295,19 @@ function prepare_vms { # VCP VMs base image specific changes if [[ ! "${repos_pkgs_str}" =~ \^{3}$ ]] && [ -n "${repos_pkgs[*]:4}" ]; then - mount_image "${image}" "${image_dir}" - apt_repos_pkgs_image "${repos_pkgs[@]:4:4}" - cleanup_mounts - ln -sf "${image_dir}/${image}" "${image_dir}/${image%.*}_vcp.img" + echo "[INFO] Lookup cache / build patched VCP image for md5sum: ${_h}" + _tmp="${vcp_image%.*}.${_h}.img" + if [ -f "$(readlink -f "${image_dir}/${_tmp}")" ]; then + echo "[INFO] Patched VCP image found" + else + echo "[INFO] Patching VCP image ..." + cp "${image_dir}/${image}" "${image_dir}/${_tmp}" + __kernel_modules "${image_dir}" + mount_image "${_tmp}" "${image_dir}" + apt_repos_pkgs_image "${repos_pkgs[@]:4:4}" + cleanup_mounts + fi + ln -sf "${image_dir}/${_tmp}" "${image_dir}/${vcp_image}" fi } -- 2.16.6