| Steve Baker | 122ab70 | 2014-05-05 16:06:17 +1200 | [diff] [blame] | 1 | # lib/dib | 
 | 2 | # Install and build images with **diskimage-builder** | 
 | 3 |  | 
 | 4 | # Dependencies: | 
 | 5 | # | 
 | 6 | # - functions | 
 | 7 | # - DEST, DATA_DIR must be defined | 
 | 8 |  | 
 | 9 | # stack.sh | 
 | 10 | # --------- | 
 | 11 | # - install_dib | 
 | 12 |  | 
 | 13 | # Save trace setting | 
 | 14 | XTRACE=$(set +o | grep xtrace) | 
 | 15 | set +o xtrace | 
 | 16 |  | 
 | 17 | # Defaults | 
 | 18 | # -------- | 
 | 19 |  | 
 | 20 | # set up default directories | 
 | 21 | DIB_DIR=$DEST/diskimage-builder | 
 | 22 | TIE_DIR=$DEST/tripleo-image-elements | 
 | 23 | DIB_IMAGE_CACHE=$DATA_DIR/diskimage-builder/image-create | 
| Steve Baker | da786b2 | 2014-05-27 12:24:40 +1200 | [diff] [blame] | 24 | DIB_PIP_REPO=$DATA_DIR/diskimage-builder/pip-repo | 
 | 25 | DIB_PIP_REPO_PORT=${DIB_PIP_REPO_PORT:-8899} | 
| Steve Baker | 122ab70 | 2014-05-05 16:06:17 +1200 | [diff] [blame] | 26 | OCC_DIR=$DEST/os-collect-config | 
 | 27 | ORC_DIR=$DEST/os-refresh-config | 
 | 28 | OAC_DIR=$DEST/os-apply-config | 
 | 29 |  | 
 | 30 | # Functions | 
 | 31 | # --------- | 
 | 32 |  | 
 | 33 | # install_dib() - Collect source and prepare | 
 | 34 | function install_dib { | 
| Monty Taylor | 50495b0 | 2014-09-30 09:53:34 -0700 | [diff] [blame^] | 35 |     pip_install diskimage-builder | 
| Steve Baker | 122ab70 | 2014-05-05 16:06:17 +1200 | [diff] [blame] | 36 |  | 
 | 37 |     git_clone $TIE_REPO $TIE_DIR $TIE_BRANCH | 
 | 38 |     git_clone $OCC_REPO $OCC_DIR $OCC_BRANCH | 
 | 39 |     git_clone $ORC_REPO $ORC_DIR $ORC_BRANCH | 
 | 40 |     git_clone $OAC_REPO $OAC_DIR $OAC_BRANCH | 
 | 41 |     mkdir -p $DIB_IMAGE_CACHE | 
 | 42 | } | 
 | 43 |  | 
| Steve Baker | da786b2 | 2014-05-27 12:24:40 +1200 | [diff] [blame] | 44 | # build_dib_pip_repo() - Builds a local pip repo from local projects | 
 | 45 | function build_dib_pip_repo { | 
 | 46 |     local project_dirs=$1 | 
 | 47 |     local projpath proj package | 
 | 48 |  | 
 | 49 |     rm -rf $DIB_PIP_REPO | 
 | 50 |     mkdir -p $DIB_PIP_REPO | 
 | 51 |  | 
 | 52 |     echo "<html><body>" > $DIB_PIP_REPO/index.html | 
 | 53 |     for projpath in $project_dirs; do | 
 | 54 |         proj=$(basename $projpath) | 
 | 55 |         mkdir -p $DIB_PIP_REPO/$proj | 
 | 56 |         pushd $projpath | 
 | 57 |         rm -rf dist | 
 | 58 |         python setup.py sdist | 
 | 59 |         pushd dist | 
 | 60 |         package=$(ls *) | 
 | 61 |         mv $package $DIB_PIP_REPO/$proj/$package | 
 | 62 |         popd | 
 | 63 |  | 
 | 64 |         echo "<html><body><a href=\"$package\">$package</a></body></html>" > $DIB_PIP_REPO/$proj/index.html | 
 | 65 |         echo "<a href=\"$proj\">$proj</a><br/>" >> $DIB_PIP_REPO/index.html | 
 | 66 |  | 
 | 67 |         popd | 
 | 68 |     done | 
 | 69 |  | 
 | 70 |     echo "</body></html>" >> $DIB_PIP_REPO/index.html | 
 | 71 |  | 
 | 72 |     local dib_pip_repo_apache_conf=$(apache_site_config_for dib_pip_repo) | 
 | 73 |  | 
 | 74 |     sudo cp $FILES/apache-dib-pip-repo.template $dib_pip_repo_apache_conf | 
 | 75 |     sudo sed -e " | 
 | 76 |         s|%DIB_PIP_REPO%|$DIB_PIP_REPO|g; | 
 | 77 |         s|%DIB_PIP_REPO_PORT%|$DIB_PIP_REPO_PORT|g; | 
 | 78 |         s|%APACHE_NAME%|$APACHE_NAME|g; | 
 | 79 |     " -i $dib_pip_repo_apache_conf | 
 | 80 |     enable_apache_site dib_pip_repo | 
 | 81 | } | 
 | 82 |  | 
 | 83 | # disk_image_create_upload() - Creates and uploads a diskimage-builder built image | 
 | 84 | function disk_image_create_upload { | 
 | 85 |  | 
 | 86 |     local image_name=$1 | 
 | 87 |     local image_elements=$2 | 
 | 88 |     local elements_path=$3 | 
 | 89 |  | 
 | 90 |     local image_path=$TOP_DIR/files/$image_name.qcow2 | 
 | 91 |  | 
 | 92 |     # Set the local pip repo as the primary index mirror so the | 
 | 93 |     # image is built with local packages | 
 | 94 |     local pypi_mirror_url=http://$SERVICE_HOST:$DIB_PIP_REPO_PORT/ | 
 | 95 |     local pypi_mirror_url_1 | 
 | 96 |  | 
 | 97 |     if [ -a $HOME/.pip/pip.conf ]; then | 
 | 98 |         # Add the current pip.conf index-url as an extra-index-url | 
 | 99 |         # in the image build | 
 | 100 |         pypi_mirror_url_1=$(iniget $HOME/.pip/pip.conf global index-url) | 
 | 101 |     else | 
 | 102 |         # If no pip.conf, set upstream pypi as an extra mirror | 
 | 103 |         # (this also sets the .pydistutils.cfg index-url) | 
 | 104 |         pypi_mirror_url_1=http://pypi.python.org/simple | 
 | 105 |     fi | 
 | 106 |  | 
 | 107 |     # The disk-image-create command to run | 
 | 108 |     ELEMENTS_PATH=$elements_path \ | 
 | 109 |     PYPI_MIRROR_URL=$pypi_mirror_url \ | 
 | 110 |     PYPI_MIRROR_URL_1=$pypi_mirror_url_1 \ | 
 | 111 |     disk-image-create -a amd64 $image_elements \ | 
 | 112 |         --image-cache $DIB_IMAGE_CACHE \ | 
 | 113 |         -o $image_path | 
 | 114 |  | 
 | 115 |     local token=$(keystone token-get | grep ' id ' | get_field 2) | 
 | 116 |     die_if_not_set $LINENO token "Keystone fail to get token" | 
 | 117 |  | 
 | 118 |     glance --os-auth-token $token --os-image-url http://$GLANCE_HOSTPORT \ | 
 | 119 |         image-create --name $image_name --is-public True \ | 
 | 120 |         --container-format=bare --disk-format qcow2 \ | 
 | 121 |         < $image_path | 
 | 122 | } | 
 | 123 |  | 
| Steve Baker | 122ab70 | 2014-05-05 16:06:17 +1200 | [diff] [blame] | 124 | # Restore xtrace | 
 | 125 | $XTRACE | 
 | 126 |  | 
 | 127 | # Tell emacs to use shell-script-mode | 
 | 128 | ## Local variables: | 
 | 129 | ## mode: shell-script | 
 | 130 | ## End: |