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