| 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 | 
| Adam Gandelman | 0f72625 | 2014-10-01 17:06:19 -0700 | [diff] [blame] | 23 |  | 
 | 24 | # NOTE: Setting DIB_APT_SOURCES assumes you will be building | 
 | 25 | # Debian/Ubuntu based images. Leave unset for other flavors. | 
 | 26 | DIB_APT_SOURCES=${DIB_APT_SOURCES:-""} | 
 | 27 | DIB_BUILD_OFFLINE=$(trueorfalse False $DIB_BUILD_OFFLINE) | 
| Steve Baker | 122ab70 | 2014-05-05 16:06:17 +1200 | [diff] [blame] | 28 | DIB_IMAGE_CACHE=$DATA_DIR/diskimage-builder/image-create | 
| Steve Baker | da786b2 | 2014-05-27 12:24:40 +1200 | [diff] [blame] | 29 | DIB_PIP_REPO=$DATA_DIR/diskimage-builder/pip-repo | 
 | 30 | DIB_PIP_REPO_PORT=${DIB_PIP_REPO_PORT:-8899} | 
| Adam Gandelman | 0f72625 | 2014-10-01 17:06:19 -0700 | [diff] [blame] | 31 |  | 
| Steve Baker | 122ab70 | 2014-05-05 16:06:17 +1200 | [diff] [blame] | 32 | OCC_DIR=$DEST/os-collect-config | 
 | 33 | ORC_DIR=$DEST/os-refresh-config | 
 | 34 | OAC_DIR=$DEST/os-apply-config | 
 | 35 |  | 
| Adam Gandelman | 0f72625 | 2014-10-01 17:06:19 -0700 | [diff] [blame] | 36 | # Include the apt-sources element in builds if we have an | 
 | 37 | # alternative sources.list specified. | 
 | 38 | if [ -n "$DIB_APT_SOURCES" ]; then | 
 | 39 |     if [ ! -e "$DIB_APT_SOURCES" ]; then | 
 | 40 |         die $LINENO "DIB_APT_SOURCES set but not found at $DIB_APT_SOURCES" | 
 | 41 |     fi | 
 | 42 |     EXTRA_ELEMENTS="apt-sources" | 
 | 43 | fi | 
 | 44 |  | 
| Steve Baker | 122ab70 | 2014-05-05 16:06:17 +1200 | [diff] [blame] | 45 | # Functions | 
 | 46 | # --------- | 
 | 47 |  | 
 | 48 | # install_dib() - Collect source and prepare | 
 | 49 | function install_dib { | 
| Monty Taylor | 50495b0 | 2014-09-30 09:53:34 -0700 | [diff] [blame] | 50 |     pip_install diskimage-builder | 
| Steve Baker | 122ab70 | 2014-05-05 16:06:17 +1200 | [diff] [blame] | 51 |  | 
 | 52 |     git_clone $TIE_REPO $TIE_DIR $TIE_BRANCH | 
 | 53 |     git_clone $OCC_REPO $OCC_DIR $OCC_BRANCH | 
 | 54 |     git_clone $ORC_REPO $ORC_DIR $ORC_BRANCH | 
 | 55 |     git_clone $OAC_REPO $OAC_DIR $OAC_BRANCH | 
 | 56 |     mkdir -p $DIB_IMAGE_CACHE | 
 | 57 | } | 
 | 58 |  | 
| Steve Baker | da786b2 | 2014-05-27 12:24:40 +1200 | [diff] [blame] | 59 | # build_dib_pip_repo() - Builds a local pip repo from local projects | 
 | 60 | function build_dib_pip_repo { | 
 | 61 |     local project_dirs=$1 | 
 | 62 |     local projpath proj package | 
 | 63 |  | 
 | 64 |     rm -rf $DIB_PIP_REPO | 
 | 65 |     mkdir -p $DIB_PIP_REPO | 
 | 66 |  | 
 | 67 |     echo "<html><body>" > $DIB_PIP_REPO/index.html | 
 | 68 |     for projpath in $project_dirs; do | 
 | 69 |         proj=$(basename $projpath) | 
 | 70 |         mkdir -p $DIB_PIP_REPO/$proj | 
 | 71 |         pushd $projpath | 
 | 72 |         rm -rf dist | 
 | 73 |         python setup.py sdist | 
 | 74 |         pushd dist | 
 | 75 |         package=$(ls *) | 
 | 76 |         mv $package $DIB_PIP_REPO/$proj/$package | 
 | 77 |         popd | 
 | 78 |  | 
 | 79 |         echo "<html><body><a href=\"$package\">$package</a></body></html>" > $DIB_PIP_REPO/$proj/index.html | 
 | 80 |         echo "<a href=\"$proj\">$proj</a><br/>" >> $DIB_PIP_REPO/index.html | 
 | 81 |  | 
 | 82 |         popd | 
 | 83 |     done | 
 | 84 |  | 
 | 85 |     echo "</body></html>" >> $DIB_PIP_REPO/index.html | 
 | 86 |  | 
 | 87 |     local dib_pip_repo_apache_conf=$(apache_site_config_for dib_pip_repo) | 
 | 88 |  | 
 | 89 |     sudo cp $FILES/apache-dib-pip-repo.template $dib_pip_repo_apache_conf | 
 | 90 |     sudo sed -e " | 
 | 91 |         s|%DIB_PIP_REPO%|$DIB_PIP_REPO|g; | 
 | 92 |         s|%DIB_PIP_REPO_PORT%|$DIB_PIP_REPO_PORT|g; | 
 | 93 |         s|%APACHE_NAME%|$APACHE_NAME|g; | 
 | 94 |     " -i $dib_pip_repo_apache_conf | 
 | 95 |     enable_apache_site dib_pip_repo | 
 | 96 | } | 
 | 97 |  | 
 | 98 | # disk_image_create_upload() - Creates and uploads a diskimage-builder built image | 
 | 99 | function disk_image_create_upload { | 
 | 100 |  | 
 | 101 |     local image_name=$1 | 
 | 102 |     local image_elements=$2 | 
 | 103 |     local elements_path=$3 | 
 | 104 |  | 
 | 105 |     local image_path=$TOP_DIR/files/$image_name.qcow2 | 
 | 106 |  | 
 | 107 |     # Set the local pip repo as the primary index mirror so the | 
 | 108 |     # image is built with local packages | 
 | 109 |     local pypi_mirror_url=http://$SERVICE_HOST:$DIB_PIP_REPO_PORT/ | 
 | 110 |     local pypi_mirror_url_1 | 
 | 111 |  | 
 | 112 |     if [ -a $HOME/.pip/pip.conf ]; then | 
 | 113 |         # Add the current pip.conf index-url as an extra-index-url | 
 | 114 |         # in the image build | 
 | 115 |         pypi_mirror_url_1=$(iniget $HOME/.pip/pip.conf global index-url) | 
 | 116 |     else | 
 | 117 |         # If no pip.conf, set upstream pypi as an extra mirror | 
 | 118 |         # (this also sets the .pydistutils.cfg index-url) | 
 | 119 |         pypi_mirror_url_1=http://pypi.python.org/simple | 
 | 120 |     fi | 
 | 121 |  | 
 | 122 |     # The disk-image-create command to run | 
 | 123 |     ELEMENTS_PATH=$elements_path \ | 
| Adam Gandelman | 0f72625 | 2014-10-01 17:06:19 -0700 | [diff] [blame] | 124 |     DIB_APT_SOURCES=$DIB_APT_SOURCES \ | 
 | 125 |     DIB_OFFLINE=$DIB_BUILD_OFFLINE \ | 
| Steve Baker | da786b2 | 2014-05-27 12:24:40 +1200 | [diff] [blame] | 126 |     PYPI_MIRROR_URL=$pypi_mirror_url \ | 
 | 127 |     PYPI_MIRROR_URL_1=$pypi_mirror_url_1 \ | 
| Adam Gandelman | 0f72625 | 2014-10-01 17:06:19 -0700 | [diff] [blame] | 128 |     disk-image-create -a amd64 $image_elements $EXTRA_ELEMENTS \ | 
| Steve Baker | da786b2 | 2014-05-27 12:24:40 +1200 | [diff] [blame] | 129 |         --image-cache $DIB_IMAGE_CACHE \ | 
 | 130 |         -o $image_path | 
 | 131 |  | 
 | 132 |     local token=$(keystone token-get | grep ' id ' | get_field 2) | 
 | 133 |     die_if_not_set $LINENO token "Keystone fail to get token" | 
 | 134 |  | 
 | 135 |     glance --os-auth-token $token --os-image-url http://$GLANCE_HOSTPORT \ | 
 | 136 |         image-create --name $image_name --is-public True \ | 
 | 137 |         --container-format=bare --disk-format qcow2 \ | 
 | 138 |         < $image_path | 
 | 139 | } | 
 | 140 |  | 
| Steve Baker | 122ab70 | 2014-05-05 16:06:17 +1200 | [diff] [blame] | 141 | # Restore xtrace | 
 | 142 | $XTRACE | 
 | 143 |  | 
 | 144 | # Tell emacs to use shell-script-mode | 
 | 145 | ## Local variables: | 
 | 146 | ## mode: shell-script | 
 | 147 | ## End: |