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. |
| 60 | fi |
| 61 | } |
| 62 | |
| 63 | ### Body |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 64 | echo "Configuring network interfaces" |
Dmitry Stremkouski | f50ea26 | 2017-12-05 19:35:40 +0300 | [diff] [blame] | 65 | find /etc/network/interfaces.d/ -type f -delete |
| 66 | kill $(pidof /sbin/dhclient) || /bin/true |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 67 | envsubst < /root/interfaces > /etc/network/interfaces |
Dmitry Stremkouski | a94b5f3 | 2017-12-02 00:41:54 +0300 | [diff] [blame] | 68 | ip a flush dev ens3 |
Dmitry Stremkouski | b43c4ee | 2017-12-02 02:21:05 +0300 | [diff] [blame] | 69 | rm -f /var/run/network/ifstate.ens3 |
| 70 | if [[ $(grep -E '^\ *gateway\ ' /etc/network/interfaces) ]]; then |
| 71 | (ip r s | grep ^default) && ip r d default || /bin/true |
| 72 | fi; |
Dmitry Stremkouski | a94b5f3 | 2017-12-02 00:41:54 +0300 | [diff] [blame] | 73 | ifup ens3 |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 74 | |
| 75 | echo "Preparing metadata model" |
| 76 | mount /dev/cdrom /mnt/ |
Leontii Istomin | 68553f1 | 2018-02-21 18:10:12 +0100 | [diff] [blame] | 77 | cp -rT /mnt/model/model /srv/salt/reclass |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 78 | chown -R root:root /srv/salt/reclass/* |
alexz | d90608b | 2018-04-12 23:49:03 +0200 | [diff] [blame] | 79 | chown -R root:root /srv/salt/reclass/.git* || true |
| 80 | chmod -R 644 /srv/salt/reclass/classes/cluster/* || true |
| 81 | chmod -R 644 /srv/salt/reclass/classes/system/* || true |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 82 | |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 83 | echo "Configuring salt" |
| 84 | #service salt-master restart |
| 85 | envsubst < /root/minion.conf > /etc/salt/minion.d/minion.conf |
| 86 | service salt-minion restart |
| 87 | while true; do |
| 88 | salt-key | grep "$SALT_MASTER_MINION_ID" && break |
| 89 | sleep 5 |
| 90 | done |
| 91 | sleep 5 |
alexz | d90608b | 2018-04-12 23:49:03 +0200 | [diff] [blame] | 92 | 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] | 93 | salt-key -d $i -y |
| 94 | done |
| 95 | |
| 96 | 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' |
| 97 | |
Jiri Broulik | cee2053 | 2018-01-08 13:30:15 +0100 | [diff] [blame] | 98 | echo "updating git repos" |
alexz | d90608b | 2018-04-12 23:49:03 +0200 | [diff] [blame] | 99 | if [[ "$PIPELINES_FROM_ISO" == "true" ]] ; then |
Jiri Broulik | cee2053 | 2018-01-08 13:30:15 +0100 | [diff] [blame] | 100 | cp -r /mnt/mk-pipelines/* /home/repo/mk/mk-pipelines/ |
| 101 | cp -r /mnt/pipeline-library/* /home/repo/mcp-ci/pipeline-library/ |
alexz | d90608b | 2018-04-12 23:49:03 +0200 | [diff] [blame] | 102 | umount /dev/cdrom || true |
Jiri Broulik | cee2053 | 2018-01-08 13:30:15 +0100 | [diff] [blame] | 103 | chown -R git:www-data /home/repo/mk/mk-pipelines/* |
| 104 | chown -R git:www-data /home/repo/mcp-ci/pipeline-library/* |
| 105 | else |
alexz | d90608b | 2018-04-12 23:49:03 +0200 | [diff] [blame] | 106 | umount /dev/cdrom || true |
| 107 | git clone --mirror "${PIPELINE_REPO_URL}/mk-pipelines.git" /home/repo/mk/mk-pipelines/ |
| 108 | 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] | 109 | chown -R git:www-data /home/repo/mk/mk-pipelines/* |
| 110 | chown -R git:www-data /home/repo/mcp-ci/pipeline-library/* |
| 111 | fi |
| 112 | |
Richard Felkl | 98b4534 | 2018-04-06 13:30:28 +0200 | [diff] [blame] | 113 | echo "installing formulas" |
alexz | cd1d47e | 2018-04-17 12:21:59 +0200 | [diff] [blame^] | 114 | _apt_cfg |
Richard Felkl | 98b4534 | 2018-04-06 13:30:28 +0200 | [diff] [blame] | 115 | curl -s $MCP_SALT_REPO_KEY | sudo apt-key add - |
| 116 | echo $MCP_SALT_REPO > /etc/apt/sources.list.d/mcp_salt.list |
| 117 | apt-get update |
| 118 | apt-get install -y $FORMULAS |
| 119 | rm -r /srv/salt/reclass/classes/service/* |
Richard Felkl | 5802684 | 2018-04-10 11:17:01 +0200 | [diff] [blame] | 120 | 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] | 121 | |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 122 | salt-call saltutil.refresh_pillar |
| 123 | salt-call saltutil.sync_all |
alexz | d90608b | 2018-04-12 23:49:03 +0200 | [diff] [blame] | 124 | if ! $(reclass -n ${SALT_MASTER_MINION_ID} > /dev/null ) ; then |
| 125 | echo "ERROR: Reclass render failed!" |
| 126 | exit 1 |
Jiri Broulik | 0173a27 | 2018-04-11 10:56:35 +0200 | [diff] [blame] | 127 | fi |
| 128 | |
alexz | d90608b | 2018-04-12 23:49:03 +0200 | [diff] [blame] | 129 | salt-call state.sls linux.network,linux,openssh,salt |
| 130 | salt-call state.sls salt |
| 131 | # Sometimes, maas can stuck :( |
| 132 | salt-call state.sls maas.cluster,maas.region || salt-call state.sls maas.cluster,maas.region |
| 133 | salt-call state.sls reclass |
Jiri Broulik | 1261ca3 | 2018-01-18 15:30:25 +0100 | [diff] [blame] | 134 | |
alexz | d90608b | 2018-04-12 23:49:03 +0200 | [diff] [blame] | 135 | _post_maas_cfg |
| 136 | |
| 137 | ssh-keyscan cfg01 > /var/lib/jenkins/.ssh/known_hosts || true |
| 138 | |
| 139 | pillar=$(salt-call pillar.data jenkins:client) |
Jiri Broulik | e40813f | 2018-01-16 13:35:19 +0100 | [diff] [blame] | 140 | |
| 141 | if [[ $pillar == *"job"* ]]; then |
| 142 | salt-call state.sls jenkins.client |
| 143 | fi |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 144 | |
Dmitry Stremkouski | a94b5f3 | 2017-12-02 00:41:54 +0300 | [diff] [blame] | 145 | reboot |