blob: d39d8016c5734922f0f14259250bf4bf2d643e34 [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 {
Monty Taylor50495b02014-09-30 09:53:34 -070035 pip_install diskimage-builder
Steve Baker122ab702014-05-05 16:06:17 +120036
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 Bakerda786b22014-05-27 12:24:40 +120044# build_dib_pip_repo() - Builds a local pip repo from local projects
45function 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
84function 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 Baker122ab702014-05-05 16:06:17 +1200124# Restore xtrace
125$XTRACE
126
127# Tell emacs to use shell-script-mode
128## Local variables:
129## mode: shell-script
130## End: