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)"
22 echo " -w cache cache directory for disk-image-create"
29 workspace="/home/jenkins-ci/opnfv/slave_root/workspace"
30 gs_url="artifacts.opnfv.org/samplevnf/images"
32 while getopts i:g:vw: flag
35 i) image_appendix=${OPTARG};;
38 w) workspace=${OPTARG};;
42 echo "gs_url: $gs_url";
43 echo "Verify only: $verify_only";
44 image_name=rapid-${image_appendix}
45 echo "image name: $image_name.qcow2"
46 echo "workspace: $workspace"
48 install diskimage-builder
49 python3 -m venv dib-rapid-venv
50 . dib-rapid-venv/bin/activate
51 pip3 install --upgrade pip
53 pip3 install diskimage-builder
56 echo "Checking if image exists in google storage..."
57 if command -v gsutil >/dev/null; then
58 if gsutil -q stat gs://$gs_url/$image_name.qcow2; then
59 echo "Image already exists at http://$gs_url/$image_name.qcow2"
61 echo "Starting build..."
64 echo "Cannot check image availability in OPNFV artifact repository (gsutil not available)"
67 # Add rapid elements directory to the DIB elements path
68 export ELEMENTS_PATH=`pwd`/elements
69 # canned user/password for direct login
70 export DIB_DEV_USER_USERNAME=prox
71 export DIB_DEV_USER_PASSWORD=prox
72 export DIB_DEV_USER_PWDLESS_SUDO=Y
73 # Set the data sources to have ConfigDrive only
74 export DIB_CLOUD_INIT_DATASOURCES="Ec2, ConfigDrive, OpenStack"
75 # Use ELRepo to have latest kernel
76 export DIB_USE_ELREPO_KERNEL=True
77 echo "Building $image_name.qcow2..."
78 cache=$workspace/cache
80 time disk-image-create -o $image_name --image-cache $cache centos7 cloud-init rapid vm
82 ls -l $image_name.qcow2
85 if [ $verify_only -eq 1 ]; then
86 echo "Image verification SUCCESS"
87 echo "NO upload to google storage (-v)"
89 if command -v gsutil >/dev/null; then
90 echo "Uploading $image_name.qcow2..."
91 gsutil cp $image_name.qcow2 gs://$gs_url/$image_name.qcow2
92 echo "You can access image at http://$gs_url/$image_name.qcow2"
94 echo "Cannot upload new image to the OPNFV artifact repository (gsutil not available)"