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/)
19 gs_url=artifacts.opnfv.org/nfvbench/images
21 # image version number
23 loopvm_image_name=nfvbenchvm_centos-$__version__
24 generator_image_name=nfvbenchvm_centos-generator-$__version__
27 # ----------------------------------------------------------------------------
28 # Parse command line options and configure the script
29 # ----------------------------------------------------------------------------
33 $(basename $0) - build NFVbench VM images
35 $(basename $0) [OPTIONS]
38 -l: build NFVbench loop VM image
39 -g: build NFVbench generator image
40 -v: verify only (build but do not push to google storage)
42 -t: enable debug trace (set -x + DIB_DEBUG_TRACE=1)
43 -d: start debug shell in image chroot in case of build error
44 -h: show this help message
49 while getopts ":lgvtdh" opt; do
62 export DIB_DEBUG_TRACE=1
79 # ----------------------------------------------------------------------------
80 # Configure and start the nfvbenchvm image build
81 # ----------------------------------------------------------------------------
83 function build_image {
84 # if image exists skip building
85 echo "Checking if image exists in google storage..."
86 if command -v gsutil >/dev/null; then
87 if gsutil -q stat gs://$gs_url/$1.qcow2; then
88 echo "Image already exists at http://$gs_url/$1.qcow2"
89 echo "Build is skipped"
92 echo "Image does not exist in google storage, starting build..."
95 echo "Cannot check image availability in OPNFV artifact repository (gsutil not available)"
98 # check if image is already built locally
99 if [ -f $1.qcow2 ]; then
100 echo "Image $1.qcow2 already exists locally"
102 # install diskimage-builder
103 if [ -d dib-venv ]; then
104 . dib-venv/bin/activate
106 python3 -m venv dib-venv
107 . dib-venv/bin/activate
108 pip install diskimage-builder==3.16.0
111 # Add nfvbenchvm_centos elements directory to the DIB elements path
112 export ELEMENTS_PATH=`pwd`/elements
114 # canned user/password for direct login
115 export DIB_DEV_USER_USERNAME=nfvbench
116 export DIB_DEV_USER_PASSWORD=nfvbench
117 export DIB_DEV_USER_PWDLESS_SUDO=Y
119 # Set the data sources to have ConfigDrive only
120 export DIB_CLOUD_INIT_DATASOURCES="ConfigDrive"
123 export DIB_YUM_REPO_CONF=$ELEMENTS_PATH/nfvbenchvm/fdio-release.repo
125 # Use ELRepo to have latest kernel
126 # only for loop vm image
127 if [ $1 = $loopvm_image_name ]; then
128 export DIB_USE_ELREPO_KERNEL=True
129 export DIB_DEV_IMAGE=loopvm
131 export DIB_USE_ELREPO_KERNEL=False
132 export DIB_DEV_IMAGE=generator
133 # get current git branch to build image with current code
134 export GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
135 # retrieve TREX_VER from Dockerfile
136 export TREX_VER=$(awk '/ENV TREX_VER/ {print $3}' ../../docker/Dockerfile | sed 's/"//g' | sed 's/\r//g')
139 # Specify CentOS version
142 # Debug on error: if an error occurs during the build, disk-image-create
143 # will drop us in a Bash inside the chroot, and we will be able to inspect
144 # the current state of the image.
145 if [[ "${DEBUG}" == "yes" ]]; then
146 export break=after-error
149 echo "Building $1.qcow2..."
150 time disk-image-create -o $1 centos nfvbenchvm
155 if [ $verify_only -eq 1 ]; then
156 echo "Image verification SUCCESS"
157 echo "NO upload to google storage (-v)"
159 if command -v gsutil >/dev/null; then
160 echo "Uploading $1.qcow2..."
161 gsutil cp $1.qcow2 gs://$gs_url/$1.qcow2
162 echo "You can access to image at http://$gs_url/$1.qcow2"
164 echo "Cannot upload new image to the OPNFV artifact repository (gsutil not available)"
171 # ----------------------------------------------------------------------------
173 # ----------------------------------------------------------------------------
175 if [ ! $generator_only -eq 1 ] && [ ! $loopvm_only -eq 1 ]; then
176 echo "Build loop VM image"
177 build_image $loopvm_image_name
178 echo "Build generator image"
179 build_image $generator_image_name
181 if [ $loopvm_only -eq 1 ]; then
182 echo "Build loop VM image"
183 build_image $loopvm_image_name
185 if [ $generator_only -eq 1 ]; then
186 echo "Build generator image"
187 build_image $generator_image_name