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 # Ubuntu: sudo apt-get -y install python3 python3-venv qemu-utils kpartx
7 # CentOS: sudo yum install -y python3 qemu-img kpartx
9 # Stop on error (see https://wizardzines.com/comics/bash-errors/)
13 echo "Usage: $0 [-l] [-g] [-v]"
14 echo " -l build NFVbench loop VM image"
15 echo " -g build NFVbench generator image"
16 echo " -v verify only (build but do not push to google storage)"
24 # ----------------------------------------------------------------------------
25 # Parse command line options and configure the script
26 # ----------------------------------------------------------------------------
28 while getopts ":hglv" opt; do
53 gs_url=artifacts.opnfv.org/nfvbench/images
55 # image version number
57 loopvm_image_name=nfvbenchvm_centos-$__version__
58 generator_image_name=nfvbenchvm_centos-generator-$__version__
60 function build_image {
61 # if image exists skip building
62 echo "Checking if image exists in google storage..."
63 if command -v gsutil >/dev/null; then
64 if gsutil -q stat gs://$gs_url/$1.qcow2; then
65 echo "Image already exists at http://$gs_url/$1.qcow2"
66 echo "Build is skipped"
69 echo "Image does not exist in google storage, starting build..."
72 echo "Cannot check image availability in OPNFV artifact repository (gsutil not available)"
75 # check if image is already built locally
76 if [ -f $1.qcow2 ]; then
77 echo "Image $1.qcow2 already exists locally"
80 # install diskimage-builder
81 if [ -d dib-venv ]; then
82 . dib-venv/bin/activate
84 python3 -m venv dib-venv
85 . dib-venv/bin/activate
86 pip install diskimage-builder==3.16.0
89 # Add nfvbenchvm_centos elements directory to the DIB elements path
90 export ELEMENTS_PATH=`pwd`/elements
92 # canned user/password for direct login
93 export DIB_DEV_USER_USERNAME=nfvbench
94 export DIB_DEV_USER_PASSWORD=nfvbench
95 export DIB_DEV_USER_PWDLESS_SUDO=Y
97 # Set the data sources to have ConfigDrive only
98 export DIB_CLOUD_INIT_DATASOURCES="ConfigDrive"
101 export DIB_YUM_REPO_CONF=$ELEMENTS_PATH/nfvbenchvm/fdio-release.repo
103 # Use ELRepo to have latest kernel
104 # only for loop vm image
105 if [ $1 = $loopvm_image_name ]; then
106 export DIB_USE_ELREPO_KERNEL=True
107 export DIB_DEV_IMAGE=loopvm
109 export DIB_USE_ELREPO_KERNEL=False
110 export DIB_DEV_IMAGE=generator
111 # get current git branch to build image with current code
112 export GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
113 # retrieve TREX_VER from Dockerfile
114 export TREX_VER=$(awk '/ENV TREX_VER/ {print $3}' ../../docker/Dockerfile | sed 's/"//g' | sed 's/\r//g')
117 # Specify CentOS version
120 echo "Building $1.qcow2..."
121 time disk-image-create -o $1 centos nfvbenchvm
126 if [ $verify_only -eq 1 ]; then
127 echo "Image verification SUCCESS"
128 echo "NO upload to google storage (-v)"
130 if command -v gsutil >/dev/null; then
131 echo "Uploading $1.qcow2..."
132 gsutil cp $1.qcow2 gs://$gs_url/$1.qcow2
133 echo "You can access to image at http://$gs_url/$1.qcow2"
135 echo "Cannot upload new image to the OPNFV artifact repository (gsutil not available)"
142 if [ ! $generator_only -eq 1 ] && [ ! $loopvm_only -eq 1 ]; then
143 echo "Build loop VM image"
144 build_image $loopvm_image_name
145 echo "Build generator image"
146 build_image $generator_image_name
148 if [ $loopvm_only -eq 1 ]; then
149 echo "Build loop VM image"
150 build_image $loopvm_image_name
152 if [ $generator_only -eq 1 ]; then
153 echo "Build generator image"
154 build_image $generator_image_name