Merge "Bypass the dep management issues in lfdocs-conf"
[samplevnf.git] / rapidvm / dib / build-image.sh
1 #!/usr/bin/env bash
2 #
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
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14 #
15 # A shell script to build the PROX VM image using diskimage-builder
16 #
17 usage() {
18     echo "Usage: $0 [-v]"
19     echo "   -v    verify only (build but do not push to google storage)"
20     exit 1
21 }
22
23 # Takes only 1 optional argument
24 if [ $# -gt 1 ]; then
25    usage
26 fi
27 verify_only=0
28
29 if [ $# -eq 1 ]; then
30    if [ $1 = "-v" ]; then
31         verify_only=1
32     else
33         usage
34     fi
35 fi
36 set -e
37
38 # Artifact URL
39 gs_url=artifacts.opnfv.org/samplevnf/images
40
41 image_name=rapid-${GIT_BRANCH##*/}
42
43 # if image exists skip building
44 echo "Checking if image exists in google storage..."
45 if  command -v gsutil >/dev/null; then
46     if gsutil -q stat gs://$gs_url/$image_name.qcow2; then
47         echo "Image already exists at http://$gs_url/$image_name.qcow2"
48     fi
49     echo "Starting build..."
50     echo
51 else
52     echo "Cannot check image availability in OPNFV artifact repository (gsutil not available)"
53 fi
54
55 # install diskimage-builder
56 if [ -d dib-venv ]; then
57     . dib-venv/bin/activate
58 else
59     virtualenv dib-venv
60     . dib-venv/bin/activate
61     pip install diskimage-builder
62 fi
63 # Add rapid elements directory to the DIB elements path
64 export ELEMENTS_PATH=`pwd`/elements
65 # canned user/password for direct login
66 export DIB_DEV_USER_USERNAME=prox
67 export DIB_DEV_USER_PASSWORD=prox
68 export DIB_DEV_USER_PWDLESS_SUDO=Y
69 # Set the data sources to have ConfigDrive only
70 export DIB_CLOUD_INIT_DATASOURCES="Ec2, ConfigDrive, OpenStack"
71 # Use ELRepo to have latest kernel
72 export DIB_USE_ELREPO_KERNEL=True
73 echo "Building $image_name.qcow2..."
74 time disk-image-create -o $image_name centos7 cloud-init rapid vm
75
76 ls -l $image_name.qcow2
77
78
79 if [ $verify_only -eq 1 ]; then
80     echo "Image verification SUCCESS"
81     echo "NO upload to google storage (-v)"
82 else
83     if command -v gsutil >/dev/null; then
84         echo "Uploading $image_name.qcow2..."
85         gsutil cp $image_name.qcow2 gs://$gs_url/$image_name.qcow2
86         echo "You can access to image at http://$gs_url/$image_name.qcow2"
87     else
88         echo "Cannot upload new image to the OPNFV artifact repository (gsutil not available)"
89         exit 1
90     fi
91 fi