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
18 echo "Usage: $0 [-i image_name] [-g gs-url] [-v]"
19 echo " -i image_appendix image name to be pushed to google storage)"
20 echo " -g gs_url url to store the image"
21 echo " -v verify only (build but do not push to google storage)"
28 gs_url="artifacts.opnfv.org/samplevnf/images"
30 while getopts i:g:v flag
33 i) image_appendix=${OPTARG};;
39 echo "gs_url: $gs_url";
40 echo "Verify only: $verify_only";
41 image_name=rapid-${image_appendix}
42 echo "image name: $image_name.qcow2"
44 # install diskimage-builder
46 python3 -m venv dib-rapid-venv
47 . dib-rapid-venv/bin/activate
48 pip3 install --upgrade pip
50 pip3 install diskimage-builder
53 echo "Checking if image exists in google storage..."
54 if command -v gsutil >/dev/null; then
55 if gsutil -q stat gs://$gs_url/$image_name.qcow2; then
56 echo "Image already exists at http://$gs_url/$image_name.qcow2"
58 echo "Starting build..."
61 echo "Cannot check image availability in OPNFV artifact repository (gsutil not available)"
64 # Add rapid elements directory to the DIB elements path
65 export ELEMENTS_PATH=`pwd`/elements
66 # canned user/password for direct login
67 export DIB_DEV_USER_USERNAME=prox
68 export DIB_DEV_USER_PASSWORD=prox
69 export DIB_DEV_USER_PWDLESS_SUDO=Y
70 # Set the data sources to have ConfigDrive only
71 export DIB_CLOUD_INIT_DATASOURCES="Ec2, ConfigDrive, OpenStack"
72 # Use ELRepo to have latest kernel
73 export DIB_USE_ELREPO_KERNEL=True
74 echo "Building $image_name.qcow2..."
75 time disk-image-create -o $image_name centos7 cloud-init rapid vm
77 ls -l $image_name.qcow2
80 if [ $verify_only -eq 1 ]; then
81 echo "Image verification SUCCESS"
82 echo "NO upload to google storage (-v)"
84 if command -v gsutil >/dev/null; then
85 echo "Uploading $image_name.qcow2..."
86 gsutil cp $image_name.qcow2 gs://$gs_url/$image_name.qcow2
87 echo "You can access image at http://$gs_url/$image_name.qcow2"
89 echo "Cannot upload new image to the OPNFV artifact repository (gsutil not available)"