diff options
author | Alexandru Avadanii <Alexandru.Avadanii@enea.com> | 2018-01-07 01:07:15 +0100 |
---|---|---|
committer | Alexandru Avadanii <Alexandru.Avadanii@enea.com> | 2018-01-07 02:08:03 +0100 |
commit | 1815bdaf0c1765cc1fcb48031f8291409861b0b2 (patch) | |
tree | e5eaf32011db73b589cce32f868adf5fb1aab819 /mcp | |
parent | 3aa172fb1659925a837b432649793f9f1f46cca9 (diff) |
lib.sh: Cache base image(s) between deploys
Fingerprint and re-use base image artifacts.
Change-Id: Ic7a73c04e27d25addd50e4e9880619a0028956d3
Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
Diffstat (limited to 'mcp')
-rw-r--r-- | mcp/scripts/lib.sh | 49 |
1 files changed, 36 insertions, 13 deletions
diff --git a/mcp/scripts/lib.sh b/mcp/scripts/lib.sh index 05780bb62..e9ce1e53a 100644 --- a/mcp/scripts/lib.sh +++ b/mcp/scripts/lib.sh @@ -250,22 +250,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 <mcp/scripts> # shellcheck disable=SC2016 @@ -282,10 +296,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 } |