Pre install docker into base image

* Cache MKE images

Related-Prod: PRODX-3456
Change-Id: Iff159433685d3e3895f36cb4000b32b88b71a389
diff --git a/de/heat-templates/scripts/instance_boot.sh b/de/heat-templates/scripts/instance_boot.sh
index f0e2fa6..2fb3123 100644
--- a/de/heat-templates/scripts/instance_boot.sh
+++ b/de/heat-templates/scripts/instance_boot.sh
@@ -179,8 +179,11 @@
 function setup_bind_mounts {
     mkdir -p /var/lib/persistant-data
     for component in nova glance cinder docker; do
+        if [[ -d /var/lib/${component} ]]; then
+            continue
+        fi
         mkdir -p /var/lib/data/${component} /var/lib/${component}
-    echo "/var/lib/data/${component} /var/lib/${component} none bind 0 0" >> /etc/fstab
+        echo "/var/lib/data/${component} /var/lib/${component} none bind 0 0" >> /etc/fstab
     done
 
     if [[ "${KUBERNETES_INSTALLER}" == "k0s" ]]; then
diff --git a/mosk-images/build_image.sh b/mosk-images/build_image.sh
index 571f45b..7f583ff 100755
--- a/mosk-images/build_image.sh
+++ b/mosk-images/build_image.sh
@@ -15,4 +15,4 @@
 
 ./config_drive.sh
 
-$PACKER_BINARY build -on-error=abort template.json
+$PACKER_BINARY build -on-error=cleanup template.json
diff --git a/mosk-images/env/23.3.sh b/mosk-images/env/23.3.sh
index 7ac544d..6781321 100644
--- a/mosk-images/env/23.3.sh
+++ b/mosk-images/env/23.3.sh
@@ -1,3 +1,6 @@
 export IMAGE_BASE_URL="https://cloud-images.ubuntu.com/focal/20230915/focal-server-cloudimg-amd64.img"
 export IMAGE_MD5_URL="https://cloud-images.ubuntu.com/focal/20230915/MD5SUMS"
 export KERNEL_VERSION=${KERNEL_VERSION:-'5.15.0-83-generic'}
+export DOCKER_EE_RELEASE=${DOCKER_EE_RELEASE:-'stable-23.0'}
+export DOCKER_EE_URL=${DOCKER_EE_URL:-'https://repos.mirantis.com/ubuntu'}
+export DOCKER_UCP_IMAGE=${DOCKER_UCP_IMAGE:-'docker-dev-kaas-virtual.docker.mirantis.net/lcm/docker/ucp:3.7.0'}
diff --git a/mosk-images/scripts/docker.sh b/mosk-images/scripts/docker.sh
new file mode 100644
index 0000000..a057c16
--- /dev/null
+++ b/mosk-images/scripts/docker.sh
@@ -0,0 +1,35 @@
+set -ex
+
+OS_CODENAME=$(lsb_release -c -s)
+DOCKER_DEFAULT_ADDRESS_POOL=10.10.1.0/16
+DOCKER_DEFAULT_ADDRESS_SIZE=24
+
+
+mkdir -p /etc/docker
+cat <<EOF > /etc/docker/daemon.json
+{
+  "default-address-pools": [
+    { "base": "${DOCKER_DEFAULT_ADDRESS_POOL}", "size": ${DOCKER_DEFAULT_ADDRESS_SIZE} }
+  ],
+  "log-driver": "json-file",
+  "log-opts": {
+    "max-size": "1g",
+    "max-file": "3"
+  }
+}
+EOF
+
+curl --retry 6 --retry-delay 5 -fsSL "${DOCKER_EE_URL}/gpg" | sudo apt-key add -
+add-apt-repository "deb [arch=amd64] ${DOCKER_EE_URL}/ ${OS_CODENAME} ${DOCKER_EE_RELEASE}"
+
+apt update
+
+DEBIAN_FRONTEND=noninteractive apt install -y docker-ee
+
+image_prefix=${DOCKER_UCP_IMAGE%/*}
+if [[ "$image_prefix" =~ .*\.mirantis\.net* ]]; then
+    for image in $(docker container run --rm --name ucp -v /var/run/docker.sock:/var/run/docker.sock ${DOCKER_UCP_IMAGE} images --list); do
+        docker pull "${image_prefix}/${image##*/}"
+        docker tag ${image_prefix}/${image##*/} mirantis/${image##*/}
+    done
+fi
diff --git a/mosk-images/template.json b/mosk-images/template.json
index de3953c..81f51b9 100644
--- a/mosk-images/template.json
+++ b/mosk-images/template.json
@@ -2,22 +2,30 @@
   "variables": {
     "user": "root",
     "password": "r00tme",
-    "disk_size": "2500M",
+    "disk_size": "7000M",
     "images_cache": "{{ env `PACKER_IMAGES_CACHE` }}",
     "image_base_url": "{{ env `IMAGE_BASE_URL` }}",
     "image_md5_url": "{{ env `IMAGE_MD5_URL` }}",
     "vm_name": "{{ env `VM_NAME` }}",
-    "kernel_version": "{{ env `KERNEL_VERSION` }}"
+    "kernel_version": "{{ env `KERNEL_VERSION` }}",
+    "docker_ee_release": "{{ env `DOCKER_EE_RELEASE` }}",
+    "docker_ee_url": "{{ env `DOCKER_EE_URL` }}",
+    "docker_ucp_image": "{{ env `DOCKER_UCP_IMAGE` }}"
+
   },
   "provisioners": [
     {
       "type": "shell",
       "environment_vars": [
-          "KERNEL_VERSION={{user `kernel_version`}}"
+          "KERNEL_VERSION={{user `kernel_version`}}",
+          "DOCKER_EE_RELEASE={{user `docker_ee_release`}}",
+          "DOCKER_EE_URL={{user `docker_ee_url`}}",
+          "DOCKER_UCP_IMAGE={{user `docker_ucp_image`}}"
       ],
       "scripts": [
          "scripts/apt.sh",
-	 "scripts/cleanup.sh"
+         "scripts/docker.sh",
+         "scripts/cleanup.sh"
       ]
     }
   ],