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