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
10 echo "Usage: $0 [-l] [-g] [-v]"
11 echo " -l build NFVbench loop VM image"
12 echo " -g build NFVbench generator image"
13 echo " -v verify only (build but do not push to google storage)"
21 # ----------------------------------------------------------------------------
22 # Parse command line options and configure the script
23 # ----------------------------------------------------------------------------
25 while getopts ":hglv" opt; do
50 gs_url=artifacts.opnfv.org/nfvbench/images
52 # image version number
54 loopvm_image_name=nfvbenchvm_centos-$__version__
55 generator_image_name=nfvbenchvm_centos-generator-$__version__
57 function build_image {
58 # if image exists skip building
59 echo "Checking if image exists in google storage..."
60 if command -v gsutil >/dev/null; then
61 if gsutil -q stat gs://$gs_url/$1.qcow2; then
62 echo "Image already exists at http://$gs_url/$1.qcow2"
63 echo "Build is skipped"
66 echo "Image does not exist in google storage, starting build..."
69 echo "Cannot check image availability in OPNFV artifact repository (gsutil not available)"
72 # check if image is already built locally
73 if [ -f $1.qcow2 ]; then
74 echo "Image $1.qcow2 already exists locally"
77 # install diskimage-builder
78 if [ -d dib-venv ]; then
79 . dib-venv/bin/activate
81 python3 -m venv dib-venv
82 . dib-venv/bin/activate
83 pip install diskimage-builder==3.16.0
86 # Add nfvbenchvm_centos elements directory to the DIB elements path
87 export ELEMENTS_PATH=`pwd`/elements
89 # canned user/password for direct login
90 export DIB_DEV_USER_USERNAME=nfvbench
91 export DIB_DEV_USER_PASSWORD=nfvbench
92 export DIB_DEV_USER_PWDLESS_SUDO=Y
94 # Set the data sources to have ConfigDrive only
95 export DIB_CLOUD_INIT_DATASOURCES="ConfigDrive"
98 export DIB_YUM_REPO_CONF=$ELEMENTS_PATH/nfvbenchvm/fdio-release.repo
100 # Use ELRepo to have latest kernel
101 # only for loop vm image
102 if [ $1 = $loopvm_image_name ]; then
103 export DIB_USE_ELREPO_KERNEL=True
104 export DIB_DEV_IMAGE=loopvm
106 export DIB_USE_ELREPO_KERNEL=False
107 export DIB_DEV_IMAGE=generator
108 # get current git branch to build image with current code
109 export GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
110 # retrieve TREX_VER from Dockerfile
111 export TREX_VER=$(awk '/ENV TREX_VER/ {print $3}' ../../docker/Dockerfile | sed 's/"//g' | sed 's/\r//g')
114 # Specify CentOS version
117 echo "Building $1.qcow2..."
118 time disk-image-create -o $1 centos nfvbenchvm
123 if [ $verify_only -eq 1 ]; then
124 echo "Image verification SUCCESS"
125 echo "NO upload to google storage (-v)"
127 if command -v gsutil >/dev/null; then
128 echo "Uploading $1.qcow2..."
129 gsutil cp $1.qcow2 gs://$gs_url/$1.qcow2
130 echo "You can access to image at http://$gs_url/$1.qcow2"
132 echo "Cannot upload new image to the OPNFV artifact repository (gsutil not available)"
139 if [ ! $generator_only -eq 1 ] && [ ! $loopvm_only -eq 1 ]; then
140 echo "Build loop VM image"
141 build_image $loopvm_image_name
142 echo "Build generator image"
143 build_image $generator_image_name
145 if [ $loopvm_only -eq 1 ]; then
146 echo "Build loop VM image"
147 build_image $loopvm_image_name
149 if [ $generator_only -eq 1 ]; then
150 echo "Build generator image"
151 build_image $generator_image_name