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 |
| 6 | source /var/onap/asserts |
| 7 | |
| 8 | src_folder=$git_src_folder/sdc |
| 9 | |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 10 | # mount_external_partition() - Create partition and mount the external volume |
| 11 | function mount_external_partition { |
| 12 | cat <<EOL > /tmp/asdc_ext_volume_partitions.txt |
| 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 |
| 21 | sfdisk --force /dev/sdb < /tmp/asdc_ext_volume_partitions.txt |
| 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 | |
| 28 | # init_data_folders() - Function that initialize the data folders |
| 29 | function init_data_folders { |
| 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 |
| 35 | chmod 777 /data/logs/BE |
| 36 | chmod 777 /data/logs/FE |
| 37 | } |
| 38 | |
| 39 | # setup_docker_aliases() - Function that setups the aliases required by sdc scripts |
| 40 | function setup_docker_aliases { |
| 41 | cat <<EOL > /root/.bash_aliases |
| 42 | alias dcls='/data/scripts/docker_clean.sh \$1' |
| 43 | alias dlog='/data/scripts/docker_login.sh \$1' |
| 44 | alias rund='/data/scripts/docker_run.sh' |
| 45 | alias health='/data/scripts/docker_health.sh' |
| 46 | EOL |
| 47 | } |
| 48 | |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame^] | 49 | # clone_all_sdc_repos() - Function that clones SDC source repo. |
| 50 | function clone_all_sdc_repos { |
| 51 | clone_repo sdc $src_folder |
| 52 | |
| 53 | for dirc in sdc-os-chef jtosca sdc-distribution-client sdc-titan-cassandra sdc-tosca sdc_common ; do |
| 54 | clone_repo sdc/$dirc $src_folder/$dirc |
| 55 | done |
| 56 | } |
| 57 | |
| 58 | # compile_all_sdc_repos() - Function that compiles SDC source repo. |
| 59 | function compile_all_sdc_repos { |
| 60 | local src_folder=/opt/sdc |
| 61 | clone_repo sdc $src_folder |
| 62 | |
| 63 | for dirc in jtosca sdc-distribution-client sdc-titan-cassandra sdc-tosca sdc_common ; do |
| 64 | compile_src $src_folder/$dirc |
| 65 | done |
| 66 | } |
| 67 | |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 68 | # install_sdc() - Function that pull templates and executes |
| 69 | function install_sdc { |
| 70 | IP_ADDRESS=$(ifconfig eth0 | grep "inet addr" | tr -s ' ' | cut -d' ' -f3 | cut -d':' -f2) |
| 71 | local ENV_NAME=$dmaap_topic |
| 72 | local MR_IP_ADDR='10.0.11.1' |
| 73 | local RELEASE=$docker_version |
| 74 | NEXUS_DOCKER_PORT=$(echo $nexus_docker_repo | cut -d':' -f2) |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame^] | 75 | |
| 76 | clone_all_sdc_repos |
| 77 | if [[ "$compile_repo" == "True" ]]; then |
| 78 | compile_all_sdc_repos |
| 79 | fi |
| 80 | |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 81 | if [[ "$build_image" == "True" ]]; then |
| 82 | compile_src $src_folder |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame^] | 83 | build_docker_image $src_folder/sdc-os-chef docker |
| 84 | for image in backend frontend elasticsearch kibana cassandra sanity; do |
| 85 | asserts_image openecomp/sdc-$image |
| 86 | done |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 87 | fi |
| 88 | cp $src_folder/sdc-os-chef/environments/Template.json /data/environments |
| 89 | cp $src_folder/sdc-os-chef/scripts/docker_run.sh /data/scripts |
| 90 | cp $src_folder/sdc-os-chef/scripts/docker_health.sh /data/scripts |
| 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 | |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame^] | 99 | docker_openecomp_login |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 100 | bash /data/scripts/docker_run.sh -e $ENV_NAME -r $RELEASE -p $NEXUS_DOCKER_PORT |
| 101 | } |
| 102 | |
| 103 | # init_sdc() - Function that initialize SDC services |
| 104 | function init_sdc { |
| 105 | mount_external_partition |
| 106 | init_data_folders |
| 107 | setup_docker_aliases |
| 108 | install_sdc |
| 109 | } |