[NFVBENCH-151] Allocate hugepages on two NUMAs in nfvbenchvm
[nfvbench.git] / nfvbenchvm / dib / build-image.sh
1 #!/bin/bash
2 #
3 # A shell script to build the VPP VM image using diskinage-builder
4 #
5 # The following packages must be installed prior to using this script:
6 # sudo apt-get -y install python-virtualenv qemu-utils kpartx
7
8 usage() {
9     echo "Usage: $0 [-v]"
10     echo "   -v    verify only (build but do not push to google storage)"
11     exit 1
12 }
13
14 # Takes only 1 optional argument
15 if [ $# -gt 1 ]; then
16    usage
17 fi
18 verify_only=0
19
20 if [ $# -eq 1 ]; then
21    if [ $1 = "-v" ]; then
22         verify_only=1
23     else
24         usage
25     fi
26 fi
27 set -e
28
29 # Artifact URL
30 gs_url=artifacts.opnfv.org/nfvbench/images
31
32 # image version number
33 __version__=0.10
34 image_name=nfvbenchvm_centos-$__version__
35
36 # if image exists skip building
37 echo "Checking if image exists in google storage..."
38 if  command -v gsutil >/dev/null; then
39     if gsutil -q stat gs://$gs_url/$image_name.qcow2; then
40         echo "Image already exists at http://$gs_url/$image_name.qcow2"
41         echo "Build is skipped"
42         exit 0
43     fi
44     echo "Image does not exist in google storage, starting build..."
45     echo
46 else
47     echo "Cannot check image availability in OPNFV artifact repository (gsutil not available)"
48 fi
49
50 # check if image is already built locally
51 if [ -f $image_name.qcow2 ]; then
52     echo "Image $image_name.qcow2 already exists locally"
53 else
54
55     # install diskimage-builder
56     if [ -d dib-venv ]; then
57         . dib-venv/bin/activate
58     else
59         virtualenv dib-venv
60         . dib-venv/bin/activate
61         pip install diskimage-builder
62     fi
63
64     # Add nfvbenchvm_centos elements directory to the DIB elements path
65     export ELEMENTS_PATH=`pwd`/elements
66
67     # canned user/password for direct login
68     export DIB_DEV_USER_USERNAME=nfvbench
69     export DIB_DEV_USER_PASSWORD=nfvbench
70     export DIB_DEV_USER_PWDLESS_SUDO=Y
71
72     # Set the data sources to have ConfigDrive only
73     export DIB_CLOUD_INIT_DATASOURCES="ConfigDrive"
74
75     # Configure VPP REPO
76     export DIB_YUM_REPO_CONF=$ELEMENTS_PATH/nfvbenchvm/fdio-release.repo
77
78     # Use ELRepo to have latest kernel
79     export DIB_USE_ELREPO_KERNEL=True
80
81     echo "Building $image_name.qcow2..."
82     time disk-image-create -o $image_name centos7 nfvbenchvm
83 fi
84
85 ls -l $image_name.qcow2
86
87
88 if [ $verify_only -eq 1 ]; then
89     echo "Image verification SUCCESS"
90     echo "NO upload to google storage (-v)"
91 else
92     if command -v gsutil >/dev/null; then
93         echo "Uploading $image_name.qcow2..."
94         gsutil cp $image_name.qcow2 gs://$gs_url/$image_name.qcow2
95         echo "You can access to image at http://$gs_url/$image_name.qcow2"
96     else
97         echo "Cannot upload new image to the OPNFV artifact repository (gsutil not available)"
98         exit 1
99     fi
100 fi