Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | set -o xtrace |
| 4 | |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 5 | source /var/onap/functions |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 6 | |
Victor Morales | e746700 | 2017-08-30 14:50:43 -0500 | [diff] [blame] | 7 | sdc_src_folder=$git_src_folder/sdc |
| 8 | sdc_repos=("sdc-os-chef" "jtosca" "sdc-distribution-client" "sdc-titan-cassandra" "sdc-tosca" "sdc_common") |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 9 | |
Victor Morales | e746700 | 2017-08-30 14:50:43 -0500 | [diff] [blame] | 10 | # _mount_external_partition() - Create partition and mount the external volume |
| 11 | function _mount_external_partition { |
Idan Amit | bf1e7f0 | 2017-08-20 16:05:46 +0300 | [diff] [blame] | 12 | cat <<EOL > /tmp/sdc_ext_volume_partitions.txt |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 13 | # partition table of /dev/sdb |
| 14 | unit: sectors |
| 15 | |
| 16 | /dev/sdb1 : start= 2048, size=209713152, Id=83 |
| 17 | /dev/sdb2 : start= 0, size= 0, Id= 0 |
| 18 | /dev/sdb3 : start= 0, size= 0, Id= 0 |
| 19 | /dev/sdb4 : start= 0, size= 0, Id= 0 |
| 20 | EOL |
Idan Amit | bf1e7f0 | 2017-08-20 16:05:46 +0300 | [diff] [blame] | 21 | sfdisk --force /dev/sdb < /tmp/sdc_ext_volume_partitions.txt |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 22 | mkfs -t ext4 /dev/sdb1 |
| 23 | mkdir -p /data |
| 24 | mount /dev/sdb1 /data |
| 25 | echo "/dev/sdb1 /data ext4 errors=remount-ro,noatime,barrier=0 0 1" >> /etc/fstab |
| 26 | } |
| 27 | |
Victor Morales | e746700 | 2017-08-30 14:50:43 -0500 | [diff] [blame] | 28 | # _init_data_folders() - Function that initialize the data folders |
| 29 | function _init_data_folders { |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 30 | mkdir -p /data/environments |
| 31 | mkdir -p /data/scripts |
| 32 | mkdir -p /data/logs/BE |
| 33 | mkdir -p /data/logs/FE |
| 34 | chmod 777 /data |
Idan Amit | c46e98f | 2017-08-21 17:04:10 +0300 | [diff] [blame] | 35 | chmod 777 /data/logs |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 36 | } |
| 37 | |
Victor Morales | e746700 | 2017-08-30 14:50:43 -0500 | [diff] [blame] | 38 | # _setup_docker_aliases() - Function that setups the aliases required by sdc scripts |
| 39 | function _setup_docker_aliases { |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 40 | cat <<EOL > /root/.bash_aliases |
| 41 | alias dcls='/data/scripts/docker_clean.sh \$1' |
| 42 | alias dlog='/data/scripts/docker_login.sh \$1' |
| 43 | alias rund='/data/scripts/docker_run.sh' |
| 44 | alias health='/data/scripts/docker_health.sh' |
| 45 | EOL |
| 46 | } |
| 47 | |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 48 | # clone_all_sdc_repos() - Function that clones SDC source repo. |
| 49 | function clone_all_sdc_repos { |
Victor Morales | e746700 | 2017-08-30 14:50:43 -0500 | [diff] [blame] | 50 | clone_repo sdc $sdc_src_folder |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 51 | |
Victor Morales | e746700 | 2017-08-30 14:50:43 -0500 | [diff] [blame] | 52 | for dirc in ${sdc_repos[@]}; do |
| 53 | clone_repo sdc/$dirc $sdc_src_folder/$dirc |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 54 | done |
| 55 | } |
| 56 | |
| 57 | # compile_all_sdc_repos() - Function that compiles SDC source repo. |
| 58 | function compile_all_sdc_repos { |
Victor Morales | 43906e6 | 2017-08-31 16:30:23 -0500 | [diff] [blame] | 59 | compile_src sdc $sdc_src_folder |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 60 | |
Victor Morales | e746700 | 2017-08-30 14:50:43 -0500 | [diff] [blame] | 61 | for dirc in ${sdc_repos[@]}; do |
| 62 | compile_src $sdc_src_folder/$dirc |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 63 | done |
| 64 | } |
| 65 | |
Victor Morales | e746700 | 2017-08-30 14:50:43 -0500 | [diff] [blame] | 66 | # get_sdc_images() - Function that retrieves the SDC docker images |
| 67 | function get_sdc_images { |
| 68 | if [[ "$build_image" == "True" ]]; then |
| 69 | if [[ "$compile_repo" != "True" ]]; then |
| 70 | compile_src $sdc_src_folder |
| 71 | fi |
| 72 | build_docker_image $sdc_src_folder/sdc-os-chef docker |
| 73 | else |
| 74 | for image in backend frontend elasticsearch kibana cassandra sanity; do |
| 75 | pull_openecomp_image openecomp/sdc-$image |
| 76 | done |
| 77 | fi |
| 78 | } |
| 79 | |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 80 | # install_sdc() - Function that pull templates and executes |
| 81 | function install_sdc { |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 82 | local ENV_NAME=$dmaap_topic |
| 83 | local MR_IP_ADDR='10.0.11.1' |
| 84 | local RELEASE=$docker_version |
| 85 | NEXUS_DOCKER_PORT=$(echo $nexus_docker_repo | cut -d':' -f2) |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 86 | |
Victor Morales | e746700 | 2017-08-30 14:50:43 -0500 | [diff] [blame] | 87 | _init_data_folders |
| 88 | cp $sdc_src_folder/sdc-os-chef/environments/Template.json /data/environments |
| 89 | cp $sdc_src_folder/sdc-os-chef/scripts/docker_run.sh /data/scripts |
| 90 | cp $sdc_src_folder/sdc-os-chef/scripts/docker_health.sh /data/scripts |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 91 | chmod +x /data/scripts/docker_run.sh |
| 92 | chmod +x /data/scripts/docker_health.sh |
| 93 | |
| 94 | cat /data/environments/Template.json | sed "s/yyy/"$IP_ADDRESS"/g" > /data/environments/$ENV_NAME.json |
| 95 | sed -i "s/xxx/"$ENV_NAME"/g" /data/environments/$ENV_NAME.json |
| 96 | sed -i "s/\"ueb_url_list\":.*/\"ueb_url_list\": \""$MR_IP_ADDR","$MR_IP_ADDR"\",/g" /data/environments/$ENV_NAME.json |
| 97 | sed -i "s/\"fqdn\":.*/\"fqdn\": [\""$MR_IP_ADDR"\", \""$MR_IP_ADDR"\"]/g" /data/environments/$ENV_NAME.json |
| 98 | |
Idan Amit | 0a29555 | 2017-08-17 17:03:59 +0300 | [diff] [blame] | 99 | install_docker |
| 100 | if [[ "$pull_docker_image" == "True" ]]; then |
| 101 | docker_openecomp_login |
| 102 | bash /data/scripts/docker_run.sh -e $ENV_NAME -r $RELEASE -p $NEXUS_DOCKER_PORT |
| 103 | fi |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 104 | } |
| 105 | |
Idan Amit | bf1e7f0 | 2017-08-20 16:05:46 +0300 | [diff] [blame] | 106 | # init_sdc() - Function that initialize SDC services |
| 107 | function init_sdc { |
Victor Morales | e746700 | 2017-08-30 14:50:43 -0500 | [diff] [blame] | 108 | _mount_external_partition |
Idan Amit | 1690e08 | 2017-08-20 08:58:14 +0300 | [diff] [blame] | 109 | if [[ "$clone_repo" == "True" ]]; then |
| 110 | clone_all_sdc_repos |
| 111 | if [[ "$compile_repo" == "True" ]]; then |
| 112 | compile_all_sdc_repos |
| 113 | fi |
| 114 | fi |
Victor Morales | e746700 | 2017-08-30 14:50:43 -0500 | [diff] [blame] | 115 | get_sdc_images |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 116 | install_sdc |
Victor Morales | e746700 | 2017-08-30 14:50:43 -0500 | [diff] [blame] | 117 | _setup_docker_aliases |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 118 | } |