3 # A shell script to build the VPP VM image or NFVbench+TRex VM image using diskinage-builder
5 # The following packages must be installed prior to using this script:
6 # sudo apt-get -y install python-virtualenv qemu-utils kpartx
9 echo "Usage: $0 [-l] [-g] [-v]"
10 echo " -l build NFVbench loop VM image"
11 echo " -g build NFVbench generator image"
12 echo " -v verify only (build but do not push to google storage)"
20 # ----------------------------------------------------------------------------
21 # Parse command line options and configure the script
22 # ----------------------------------------------------------------------------
24 while getopts ":hglv" opt; do
49 gs_url=artifacts.opnfv.org/nfvbench/images
51 # image version number
53 loopvm_image_name=nfvbenchvm_centos-$__version__
54 generator_image_name=nfvbenchvm_centos-generator-$__version__
58 function cleanup_image {
59 # if image exists skip building
60 echo "Checking if image exists in google storage..."
61 if command -v gsutil >/dev/null; then
62 if gsutil -q stat gs://$gs_url/$1.qcow2; then
63 gsutil rm http://$gs_url/$1.qcow2
64 echo "Image is deleted"
67 echo "Image does not exist in google storage, starting build..."
70 echo "Cannot check image availability in OPNFV artifact repository (gsutil not available)"
75 function build_image {
76 # if image exists skip building
77 echo "Checking if image exists in google storage..."
78 if command -v gsutil >/dev/null; then
79 if gsutil -q stat gs://$gs_url/$1.qcow2; then
80 echo "Image already exists at http://$gs_url/$1.qcow2"
81 echo "Build is skipped"
84 echo "Image does not exist in google storage, starting build..."
87 echo "Cannot check image availability in OPNFV artifact repository (gsutil not available)"
90 # check if image is already built locally
91 if [ -f $1.qcow2 ]; then
92 echo "Image $1.qcow2 already exists locally"
95 # install diskimage-builder
96 if [ -d dib-venv ]; then
97 . dib-venv/bin/activate
100 . dib-venv/bin/activate
101 pip install diskimage-builder
104 # Add nfvbenchvm_centos elements directory to the DIB elements path
105 export ELEMENTS_PATH=`pwd`/elements
107 # canned user/password for direct login
108 export DIB_DEV_USER_USERNAME=nfvbench
109 export DIB_DEV_USER_PASSWORD=nfvbench
110 export DIB_DEV_USER_PWDLESS_SUDO=Y
112 # Set the data sources to have ConfigDrive only
113 export DIB_CLOUD_INIT_DATASOURCES="ConfigDrive"
116 export DIB_YUM_REPO_CONF=$ELEMENTS_PATH/nfvbenchvm/fdio-release.repo
118 # Use ELRepo to have latest kernel
119 # only for loop vm image
120 if [ $1 = $loopvm_image_name ]; then
121 export DIB_USE_ELREPO_KERNEL=True
122 export DIB_DEV_IMAGE=loopvm
124 export DIB_USE_ELREPO_KERNEL=False
125 export DIB_DEV_IMAGE=generator
126 # get current git branch to build image with current code
127 export GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
128 # retrieve TREX_VER from Dockerfile
129 export TREX_VER=$(awk '/ENV TREX_VER/ {print $3}' ../../docker/Dockerfile | sed 's/"//g' | sed 's/\r//g')
132 echo "Building $1.qcow2..."
133 time disk-image-create -o $1 centos7 nfvbenchvm
138 if [ $verify_only -eq 1 ]; then
139 echo "Image verification SUCCESS"
140 echo "NO upload to google storage (-v)"
142 if command -v gsutil >/dev/null; then
143 echo "Uploading $1.qcow2..."
144 gsutil cp $1.qcow2 gs://$gs_url/$1.qcow2
145 echo "You can access to image at http://$gs_url/$1.qcow2"
147 echo "Cannot upload new image to the OPNFV artifact repository (gsutil not available)"
154 if [ ! $generator_only -eq 1 ] && [ ! $loopvm_only -eq 1 ]; then
155 echo "cleanup old loop VM image (wrong content)"
156 cleanup_image $loopvm_image_name
157 echo "Build loop VM image"
158 build_image $loopvm_image_name
159 echo "cleanup old generator VM image (wrong content)"
160 cleanup_image $generator_image_name
161 echo "Build generator image"
162 build_image $generator_image_name
164 if [ $loopvm_only -eq 1 ]; then
165 echo "Build loop VM image"
166 build_image $loopvm_image_name
168 if [ $generator_only -eq 1 ]; then
169 echo "Build generator image"
170 build_image $generator_image_name