Update jenkins installation on CFG day01 image

Change-Id: I4c505dff0adb2dcee02cdb7d5f6b288455e5dd12
Related-task: #PROD-24934 (PROD:24934)
diff --git a/day01-image/files/tmp/bootstrap.saltstack.com.sh b/day01-image/files/opt/bootstrap.saltstack.com.sh
similarity index 100%
rename from day01-image/files/tmp/bootstrap.saltstack.com.sh
rename to day01-image/files/opt/bootstrap.saltstack.com.sh
diff --git a/day01-image/scripts/salt.sh b/day01-image/scripts/salt.sh
index 7e58372..ffa106b 100644
--- a/day01-image/scripts/salt.sh
+++ b/day01-image/scripts/salt.sh
@@ -4,17 +4,26 @@
 APT_MIRANTIS_SALT_REPO=${APT_MIRANTIS_SALT_REPO:-"http://apt.mirantis.com/xenial/ $FORMULA_VERSION salt"}
 SALT_OPTS="-t 10 --retcode-passthrough --no-color"
 
-salt-call ${SALT_OPTS} reclass.validate_pillar
-
 echo "deb [arch=amd64] ${APT_MIRANTIS_SALT_REPO}" > /etc/apt/sources.list.d/mcp_salt.list
 apt-get update
 apt-get install salt-formula* -y
 
-salt-call saltutil.refresh_pillar
-salt-call saltutil.sync_all
-salt-call ${SALT_OPTS} state.sls salt
-salt-call ${SALT_OPTS} state.sls linux.system.repo,linux.system.package,linux.system.user,linux.system.directory,linux.system.config
+# Wait for salt-master and salt-minion to wake up after restart
+# since we just perform 'reboot.sh'
+salt-call --timeout=120 test.ping
+
+salt-call ${SALT_OPTS} saltutil.clear_cache
+salt-call ${SALT_OPTS} saltutil.refresh_pillar
+salt-call ${SALT_OPTS} saltutil.sync_all
+salt-call ${SALT_OPTS} reclass.validate_pillar
+
+salt-call ${SALT_OPTS} state.sls linux.system.repo,linux.system.package,linux.system.user,linux.system.directory,linux.system.file,linux.system.config
 salt-call ${SALT_OPTS} state.sls linux.network
+salt-call ${SALT_OPTS} state.sls salt.minion.ca
+
+salt-call ${SALT_OPTS} state.sls salt
+salt-call ${SALT_OPTS} state.sls docker.host
+
 salt-call ${SALT_OPTS} state.sls openssh
 salt-call ${SALT_OPTS} state.sls git.server
 salt-call ${SALT_OPTS} state.sls postgresql
@@ -24,25 +33,17 @@
 salt-call ${SALT_OPTS} state.sls_id maas_cluster_packages maas
 salt-call ${SALT_OPTS} state.sls_id maas_region_packages maas
 
-# linux.system.file only for backwards compatibility of jenkins - mcp-common-scripts
-salt-call ${SALT_OPTS} state.sls jenkins.master,linux.system.file
-sleep 60
-salt-call -t 5 --no-color state.sls jenkins.client.plugin
-systemctl restart jenkins
-sleep 60
-# Jenkins Mirantis theme
 # FIXME move those into cluster model
 git clone https://github.com/Mirantis/docker-jenkins.git
-cp -r docker-jenkins/theme /var/lib/jenkins/userContent
-chown -R jenkins:jenkins /var/lib/jenkins/userContent/*
-# finish Jenkins setup
-salt-call -t 5 --no-color state.sls jenkins.client.plugin
-systemctl restart jenkins
-sleep 60
-salt-call -t 5 --no-color state.sls jenkins.client
-systemctl restart jenkins
-sleep 60
-salt-call ${SALT_OPTS} state.sls jenkins.client
+mkdir -p /srv/volumes/jenkins/userContent/theme/
+cp -r docker-jenkins/theme/* /srv/volumes/jenkins/userContent/theme/
+rm -rf docker-jenkins
+chown -R 1000:1000 /srv/volumes/jenkins/userContent/
+
+docker pull "docker-prod-local.artifactory.mirantis.com/mirantis/cicd/jenkins:${MCP_VERSION}"
+docker pull "docker-prod-local.artifactory.mirantis.com/mirantis/cicd/jnlp-slave:${MCP_VERSION}"
+# Flag for cloud-init script
+touch /root/jenkins_in_docker
 
 # Duplicate of ubuntu_info.sh
 mkdir -p /var/log/bootstrap_logs/ ; pushd /var/log/bootstrap_logs/
diff --git a/day01-image/template.json b/day01-image/template.json
index fd61aaa..e7d90d3 100644
--- a/day01-image/template.json
+++ b/day01-image/template.json
@@ -30,8 +30,24 @@
     },
     {
       "type": "file",
-      "source": "files/tmp/bootstrap.saltstack.com.sh",
-      "destination": "/tmp/bootstrap.saltstack.com.sh"
+      "source": "files/opt/bootstrap.saltstack.com.sh",
+      "destination": "/opt/bootstrap.saltstack.com.sh"
+    },
+    {
+      "environment_vars": [
+        "UBUNTU_BASEURL={{ user `ubuntu_baseurl` }}",
+        "PACKER_OFFLINE_BUILD=true"
+      ],
+      "type": "shell",
+      "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}",
+      "expect_disconnect": "true",
+      "scripts": [
+        "scripts/base_set_hostname.sh",
+        "scripts/base.sh",
+        "scripts/motd.sh",
+        "scripts/network.sh",
+        "scripts/reboot.sh"
+      ]
     },
     {
       "environment_vars": [
@@ -40,7 +56,6 @@
         "CLUSTER_NAME={{ user `cluster_name` }}",
         "BS_HOSTNAME={{ user `bs_hostname` }}",
         "FORMULA_VERSION={{ user `formula_version` }}",
-        "UBUNTU_BASEURL={{ user `ubuntu_baseurl` }}",
         "SALTSTACK_GPG={{ user `saltstack_gpg` }}",
         "SALTSTACK_REPO={{ user `saltstack_repo` }}",
         "APT_MIRANTIS_GPG={{ user `apt_mirantis_gpg` }}",
@@ -48,16 +63,17 @@
         "GIT_SALT_FORMULAS_SCRIPTS={{ user `git_salt_formulas_scripts` }}",
         "APT_REPOSITORY={{ user `apt_repository` }}",
         "APT_REPOSITORY_GPG={{ user `apt_repository_gpg` }}",
+        "FORMULA_VERSION={{ user `formula_version` }}",
         "APT_MIRANTIS_SALT_REPO={{ user `apt_mirantis_salt_repo` }}",
+        "BOOTSTRAP_SALTSTACK_COM=file:///opt/bootstrap.saltstack.com.sh",
+        "MCP_VERSION={{ user `mcp_version` }}",
         "PACKER_OFFLINE_BUILD=true"
       ],
       "type": "shell",
+      "pause_before": "60s",
       "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}",
+      "expect_disconnect": "true",
       "scripts": [
-        "scripts/base_set_hostname.sh",
-        "scripts/base.sh",
-        "scripts/motd.sh",
-        "scripts/network.sh",
         "scripts/salt_bootstrap.sh",
         "scripts/salt.sh"
       ]
@@ -70,7 +86,7 @@
     {
       "type": "file",
       "source": "files/var/jenkins",
-      "destination": "/var/lib/jenkins/org.codefirst.SimpleThemeDecorator.xml"
+      "destination": "/srv/volumes/jenkins/org.codefirst.SimpleThemeDecorator.xml"
     },
     {
       "environment_vars": [
diff --git a/trymcp-day01-image/scripts/salt.sh b/trymcp-day01-image/scripts/salt.sh
index b4137dd..67ef5b2 100644
--- a/trymcp-day01-image/scripts/salt.sh
+++ b/trymcp-day01-image/scripts/salt.sh
@@ -8,10 +8,9 @@
 apt-get update
 apt-get install salt-formula* -y
 
-# Basic states
-salt-call saltutil.clear_cache
-salt-call saltutil.refresh_pillar
-salt-call saltutil.sync_all
+salt-call ${SALT_OPTS} saltutil.clear_cache
+salt-call ${SALT_OPTS} saltutil.refresh_pillar
+salt-call ${SALT_OPTS} saltutil.sync_all
 salt-call ${SALT_OPTS} reclass.validate_pillar
 
 salt-call ${SALT_OPTS} state.sls linux.system.repo,linux.system.package,linux.system.user,linux.system.directory,linux.system.config