3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # A shell script to build the PROX VM image using diskimage-builder
19 echo " -v verify only (build but do not push to google storage)"
23 # Takes only 1 optional argument
30 if [ $1 = "-v" ]; then
39 gs_url=artifacts.opnfv.org/samplevnf/images
41 # image version number
43 image_name=rapid-$__version__
45 # if image exists skip building
46 echo "Checking if image exists in google storage..."
47 if command -v gsutil >/dev/null; then
48 if gsutil -q stat gs://$gs_url/$image_name.qcow2; then
49 echo "Image already exists at http://$gs_url/$image_name.qcow2"
50 echo "Build is skipped"
53 echo "Image does not exist in google storage, starting build..."
56 echo "Cannot check image availability in OPNFV artifact repository (gsutil not available)"
59 # check if image is already built locally
60 if [ -f $image_name.qcow2 ]; then
61 echo "Image $image_name.qcow2 already exists locally"
64 # install diskimage-builder
65 if [ -d dib-venv ]; then
66 . dib-venv/bin/activate
69 . dib-venv/bin/activate
70 pip install diskimage-builder
72 # Add rapid elements directory to the DIB elements path
73 export ELEMENTS_PATH=`pwd`/elements
74 # canned user/password for direct login
75 export DIB_DEV_USER_USERNAME=prox
76 export DIB_DEV_USER_PASSWORD=prox
77 export DIB_DEV_USER_PWDLESS_SUDO=Y
78 # Set the data sources to have ConfigDrive only
79 export DIB_CLOUD_INIT_DATASOURCES="Ec2, ConfigDrive, OpenStack"
80 # Use ELRepo to have latest kernel
81 export DIB_USE_ELREPO_KERNEL=True
82 echo "Building $image_name.qcow2..."
83 time disk-image-create -o $image_name centos7 cloud-init rapid vm
86 ls -l $image_name.qcow2
89 if [ $verify_only -eq 1 ]; then
90 echo "Image verification SUCCESS"
91 echo "NO upload to google storage (-v)"
93 if command -v gsutil >/dev/null; then
94 echo "Uploading $image_name.qcow2..."
95 gsutil cp $image_name.qcow2 gs://$gs_url/$image_name.qcow2
96 echo "You can access to image at http://$gs_url/$image_name.qcow2"
98 echo "Cannot upload new image to the OPNFV artifact repository (gsutil not available)"