Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 1 | #!/bin/bash -xe |
alexz | d90608b | 2018-04-12 23:49:03 +0200 | [diff] [blame] | 2 | |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 3 | export SALT_MASTER_DEPLOY_IP=172.16.164.15 |
| 4 | export SALT_MASTER_MINION_ID=cfg01.deploy-name.local |
| 5 | export DEPLOY_NETWORK_GW=172.16.164.1 |
| 6 | export DEPLOY_NETWORK_NETMASK=255.255.255.192 |
| 7 | export DNS_SERVERS=8.8.8.8 |
Jiri Broulik | cee2053 | 2018-01-08 13:30:15 +0100 | [diff] [blame] | 8 | export http_proxy= |
| 9 | export https_proxy= |
| 10 | export PIPELINES_FROM_ISO=true |
| 11 | export PIPELINE_REPO_URL=https://github.com/Mirantis |
Richard Felkl | 98b4534 | 2018-04-06 13:30:28 +0200 | [diff] [blame] | 12 | export MCP_VERSION=stable |
| 13 | export MCP_SALT_REPO_KEY=http://apt.mirantis.com/public.gpg |
| 14 | export MCP_SALT_REPO_URL=http://apt.mirantis.com/xenial |
| 15 | export MCP_SALT_REPO="deb [arch=amd64] $MCP_SALT_REPO_URL $MCP_VERSION salt" |
| 16 | export FORMULAS="salt-formula-*" |
alexz | cd1d47e | 2018-04-17 12:21:59 +0200 | [diff] [blame] | 17 | # Not avaible in 2018.4 and pre. |
Jiri Broulik | 0173a27 | 2018-04-11 10:56:35 +0200 | [diff] [blame] | 18 | export LOCAL_REPOS=false |
Jiri Broulik | cee2053 | 2018-01-08 13:30:15 +0100 | [diff] [blame] | 19 | #for cloning from aptly image use port 8088 |
| 20 | #export PIPELINE_REPO_URL=http://172.16.47.182:8088 |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 21 | |
alexz | cd1d47e | 2018-04-17 12:21:59 +0200 | [diff] [blame] | 22 | function _apt_cfg(){ |
| 23 | # TODO remove those function after 2018.4 release |
| 24 | echo "Acquire::CompressionTypes::Order gz;" >/etc/apt/apt.conf.d/99compression-workaround-salt |
| 25 | echo "Acquire::EnableSrvRecords false;" >/etc/apt/apt.conf.d/99enablesrvrecords-false |
| 26 | echo "Acquire::http::Pipeline-Depth 0;" > /etc/apt/apt.conf.d/99aws-s3-mirrors-workaround-salt |
| 27 | echo "APT::Install-Recommends false;" > /etc/apt/apt.conf.d/99dont_install_recommends-salt |
| 28 | echo "APT::Install-Suggests false;" > /etc/apt/apt.conf.d/99dont_install_suggests-salt |
| 29 | echo "Acquire::Languages none;" > /etc/apt/apt.conf.d/99dont_acquire_all_languages-salt |
| 30 | echo "APT::Periodic::Update-Package-Lists 0;" > /etc/apt/apt.conf.d/99dont_update_package_list-salt |
| 31 | echo "APT::Periodic::Download-Upgradeable-Packages 0;" > /etc/apt/apt.conf.d/99dont_update_download_upg_packages-salt |
| 32 | echo "APT::Periodic::Unattended-Upgrade 0;" > /etc/apt/apt.conf.d/99disable_unattended_upgrade-salt |
| 33 | echo "INFO: cleaning sources lists" |
| 34 | rm -rv /etc/apt/sources.list.d/* || true |
| 35 | echo > /etc/apt/sources.list || true |
| 36 | } |
| 37 | |
alexz | d90608b | 2018-04-12 23:49:03 +0200 | [diff] [blame] | 38 | function _post_maas_cfg(){ |
| 39 | local PROFILE=mirantis |
alexz | cd1d47e | 2018-04-17 12:21:59 +0200 | [diff] [blame] | 40 | # TODO: remove those check, and use only new version, adfter 2018.4 release |
| 41 | if [[ -f /var/lib/maas/.maas_login.sh ]]; then |
| 42 | /var/lib/maas/.maas_login.sh |
| 43 | else |
| 44 | echo "WARNING: Attempt to use old maas login schema.." |
| 45 | TOKEN=$(cat /var/lib/maas/.maas_credentials); |
| 46 | maas list | cut -d' ' -f1 | xargs -I{} maas logout {} |
| 47 | maas login $PROFILE http://127.0.0.1:5240/MAAS/api/2.0/ "${TOKEN}" |
| 48 | fi |
alexz | d90608b | 2018-04-12 23:49:03 +0200 | [diff] [blame] | 49 | # disable backports for maas enlist pkg repo |
| 50 | maas ${PROFILE} package-repository update 1 "disabled_pockets=backports" |
| 51 | maas ${PROFILE} package-repository update 1 "arches=amd64" |
| 52 | # Download ubuntu image from MAAS local mirror |
| 53 | if [[ "$LOCAL_REPOS" == "true" ]] ; then |
| 54 | maas ${PROFILE} boot-source-selections create 2 os="ubuntu" release="xenial" arches="amd64" subarches="*" labels="*" |
| 55 | echo "WARNING: Removing default MAAS stream:" |
| 56 | maas ${PROFILE} boot-source read 1 |
| 57 | maas ${PROFILE} boot-source delete 1 |
| 58 | maas ${PROFILE} boot-resources import |
| 59 | # TODO wait for finish,and stop import. |
Pavel Cizinsky | 1abc086 | 2018-05-30 14:14:33 +0200 | [diff] [blame] | 60 | else |
| 61 | maas ${PROFILE} boot-source-selections create 1 os="ubuntu" release="xenial" arches="amd64" subarches="*" labels="*" |
| 62 | maas ${PROFILE} boot-resources import |
alexz | d90608b | 2018-04-12 23:49:03 +0200 | [diff] [blame] | 63 | fi |
Pavel Cizinsky | 5f8fb09 | 2018-05-30 17:27:19 +0200 | [diff] [blame] | 64 | while [ ! -d /var/lib/maas/boot-resources/current/ubuntu/amd64/generic/xenial ] |
| 65 | do |
| 66 | sleep 10 |
| 67 | echo "WARNING: Image is still not ready" |
| 68 | done |
alexz | d90608b | 2018-04-12 23:49:03 +0200 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | ### Body |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 72 | echo "Configuring network interfaces" |
Dmitry Stremkouski | f50ea26 | 2017-12-05 19:35:40 +0300 | [diff] [blame] | 73 | find /etc/network/interfaces.d/ -type f -delete |
| 74 | kill $(pidof /sbin/dhclient) || /bin/true |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 75 | envsubst < /root/interfaces > /etc/network/interfaces |
Dmitry Stremkouski | a94b5f3 | 2017-12-02 00:41:54 +0300 | [diff] [blame] | 76 | ip a flush dev ens3 |
Dmitry Stremkouski | b43c4ee | 2017-12-02 02:21:05 +0300 | [diff] [blame] | 77 | rm -f /var/run/network/ifstate.ens3 |
| 78 | if [[ $(grep -E '^\ *gateway\ ' /etc/network/interfaces) ]]; then |
| 79 | (ip r s | grep ^default) && ip r d default || /bin/true |
| 80 | fi; |
Dmitry Stremkouski | a94b5f3 | 2017-12-02 00:41:54 +0300 | [diff] [blame] | 81 | ifup ens3 |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 82 | |
| 83 | echo "Preparing metadata model" |
| 84 | mount /dev/cdrom /mnt/ |
Leontii Istomin | 68553f1 | 2018-02-21 18:10:12 +0100 | [diff] [blame] | 85 | cp -rT /mnt/model/model /srv/salt/reclass |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 86 | chown -R root:root /srv/salt/reclass/* |
alexz | d90608b | 2018-04-12 23:49:03 +0200 | [diff] [blame] | 87 | chown -R root:root /srv/salt/reclass/.git* || true |
| 88 | chmod -R 644 /srv/salt/reclass/classes/cluster/* || true |
| 89 | chmod -R 644 /srv/salt/reclass/classes/system/* || true |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 90 | |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 91 | echo "Configuring salt" |
| 92 | #service salt-master restart |
| 93 | envsubst < /root/minion.conf > /etc/salt/minion.d/minion.conf |
| 94 | service salt-minion restart |
| 95 | while true; do |
| 96 | salt-key | grep "$SALT_MASTER_MINION_ID" && break |
| 97 | sleep 5 |
| 98 | done |
| 99 | sleep 5 |
alexz | d90608b | 2018-04-12 23:49:03 +0200 | [diff] [blame] | 100 | for i in $(salt-key -l accepted | grep -v Accepted | grep -v "$SALT_MASTER_MINION_ID"); do |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 101 | salt-key -d $i -y |
| 102 | done |
| 103 | |
| 104 | find /var/lib/jenkins/jenkins.model.JenkinsLocationConfiguration.xml -type f -print0 | xargs -0 sed -i -e 's/10.167.4.15/'$SALT_MASTER_DEPLOY_IP'/g' |
| 105 | |
Jiri Broulik | cee2053 | 2018-01-08 13:30:15 +0100 | [diff] [blame] | 106 | echo "updating git repos" |
alexz | d90608b | 2018-04-12 23:49:03 +0200 | [diff] [blame] | 107 | if [[ "$PIPELINES_FROM_ISO" == "true" ]] ; then |
Jiri Broulik | cee2053 | 2018-01-08 13:30:15 +0100 | [diff] [blame] | 108 | cp -r /mnt/mk-pipelines/* /home/repo/mk/mk-pipelines/ |
| 109 | cp -r /mnt/pipeline-library/* /home/repo/mcp-ci/pipeline-library/ |
alexz | d90608b | 2018-04-12 23:49:03 +0200 | [diff] [blame] | 110 | umount /dev/cdrom || true |
Jiri Broulik | cee2053 | 2018-01-08 13:30:15 +0100 | [diff] [blame] | 111 | chown -R git:www-data /home/repo/mk/mk-pipelines/* |
| 112 | chown -R git:www-data /home/repo/mcp-ci/pipeline-library/* |
| 113 | else |
alexz | d90608b | 2018-04-12 23:49:03 +0200 | [diff] [blame] | 114 | umount /dev/cdrom || true |
| 115 | git clone --mirror "${PIPELINE_REPO_URL}/mk-pipelines.git" /home/repo/mk/mk-pipelines/ |
| 116 | git clone --mirror "${PIPELINE_REPO_URL}/pipeline-library.git" /home/repo/mcp-ci/pipeline-library/ |
Jiri Broulik | cee2053 | 2018-01-08 13:30:15 +0100 | [diff] [blame] | 117 | chown -R git:www-data /home/repo/mk/mk-pipelines/* |
| 118 | chown -R git:www-data /home/repo/mcp-ci/pipeline-library/* |
| 119 | fi |
| 120 | |
Richard Felkl | 98b4534 | 2018-04-06 13:30:28 +0200 | [diff] [blame] | 121 | echo "installing formulas" |
alexz | cd1d47e | 2018-04-17 12:21:59 +0200 | [diff] [blame] | 122 | _apt_cfg |
Richard Felkl | 98b4534 | 2018-04-06 13:30:28 +0200 | [diff] [blame] | 123 | curl -s $MCP_SALT_REPO_KEY | sudo apt-key add - |
| 124 | echo $MCP_SALT_REPO > /etc/apt/sources.list.d/mcp_salt.list |
| 125 | apt-get update |
| 126 | apt-get install -y $FORMULAS |
Jiri Broulik | 727978e | 2018-04-17 12:56:02 +0200 | [diff] [blame] | 127 | rm -rf /srv/salt/reclass/classes/service/* |
Richard Felkl | 5802684 | 2018-04-10 11:17:01 +0200 | [diff] [blame] | 128 | cd /srv/salt/reclass/classes/service/;ls /usr/share/salt-formulas/reclass/service/ -1 | xargs -I{} ln -s /usr/share/salt-formulas/reclass/service/{};cd /root |
Richard Felkl | 98b4534 | 2018-04-06 13:30:28 +0200 | [diff] [blame] | 129 | |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 130 | salt-call saltutil.refresh_pillar |
| 131 | salt-call saltutil.sync_all |
alexz | d90608b | 2018-04-12 23:49:03 +0200 | [diff] [blame] | 132 | if ! $(reclass -n ${SALT_MASTER_MINION_ID} > /dev/null ) ; then |
| 133 | echo "ERROR: Reclass render failed!" |
| 134 | exit 1 |
Jiri Broulik | 0173a27 | 2018-04-11 10:56:35 +0200 | [diff] [blame] | 135 | fi |
| 136 | |
alexz | d90608b | 2018-04-12 23:49:03 +0200 | [diff] [blame] | 137 | salt-call state.sls linux.network,linux,openssh,salt |
Jiri Broulik | 6b7ca67 | 2018-04-19 13:16:32 +0200 | [diff] [blame] | 138 | salt-call -t5 pkg.install salt-master,salt-minion |
| 139 | sleep 5 |
alexz | d90608b | 2018-04-12 23:49:03 +0200 | [diff] [blame] | 140 | salt-call state.sls salt |
| 141 | # Sometimes, maas can stuck :( |
| 142 | salt-call state.sls maas.cluster,maas.region || salt-call state.sls maas.cluster,maas.region |
| 143 | salt-call state.sls reclass |
Jiri Broulik | 1261ca3 | 2018-01-18 15:30:25 +0100 | [diff] [blame] | 144 | |
alexz | d90608b | 2018-04-12 23:49:03 +0200 | [diff] [blame] | 145 | _post_maas_cfg |
Pavel Cizinsky | 44d6340 | 2018-05-30 18:07:39 +0200 | [diff] [blame^] | 146 | salt-call state.sls maas.cluster,maas.region || salt-call state.sls maas.cluster,maas.region |
alexz | d90608b | 2018-04-12 23:49:03 +0200 | [diff] [blame] | 147 | |
| 148 | ssh-keyscan cfg01 > /var/lib/jenkins/.ssh/known_hosts || true |
| 149 | |
| 150 | pillar=$(salt-call pillar.data jenkins:client) |
Jiri Broulik | e40813f | 2018-01-16 13:35:19 +0100 | [diff] [blame] | 151 | |
| 152 | if [[ $pillar == *"job"* ]]; then |
| 153 | salt-call state.sls jenkins.client |
| 154 | fi |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 155 | |
Dmitry Stremkouski | a94b5f3 | 2017-12-02 00:41:54 +0300 | [diff] [blame] | 156 | reboot |