summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuya Kusakabe <yuya.kusakabe@gmail.com>2016-03-04 14:33:32 +0900
committerYuya Kusakabe <yuya.kusakabe@gmail.com>2016-03-04 23:39:23 +0900
commit3e56d7456e55b46ceb1dbca6a8f5cbc5150e18f5 (patch)
tree5915979baf9ddc4f509c28f028b0befb0526cd5a
parenta05a3660eaf913689d89dd2187415d8b211aabb2 (diff)
downloadvyos-build-3e56d7456e55b46ceb1dbca6a8f5cbc5150e18f5.tar.gz
vyos-build-3e56d7456e55b46ceb1dbca6a8f5cbc5150e18f5.zip
Add qemu image build scripts
-rw-r--r--.gitignore2
-rw-r--r--Makefile7
-rwxr-xr-xscripts/build-qemu-image30
-rwxr-xr-xscripts/check-vm-build-env61
-rw-r--r--scripts/packer.json62
-rwxr-xr-xtools/run-qemu-image.sh16
6 files changed, 178 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index a0114d35..889ab43d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,4 @@
build/*
*.pyc
+packer_build/*
+packer_cache/*
diff --git a/Makefile b/Makefile
index 0a0cb2dd..86f0c27d 100644
--- a/Makefile
+++ b/Makefile
@@ -37,6 +37,13 @@ prepare-package-env:
@scripts/pbuilder-config
@scripts/pbuilder-setup
+.PHONY: qemu
+.ONESHELL:
+qemu:
+ @set -e
+ @scripts/check-vm-build-env
+ @scripts/build-qemu-image
+
.PHONY: clean
.ONESHELL:
clean:
diff --git a/scripts/build-qemu-image b/scripts/build-qemu-image
new file mode 100755
index 00000000..8643508a
--- /dev/null
+++ b/scripts/build-qemu-image
@@ -0,0 +1,30 @@
+#!/bin/sh
+#
+# Copyright (C) 2016 VyOS maintainers and contributors
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 or later as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# File: build-qemu-image
+# Purpose:
+# Build VyOS raw image for qemu.
+
+
+export ISO_IMAGE=./build/live-image-amd64.hybrid.iso
+export ISO_MD5_SUM=$(md5sum ${ISO_IMAGE} | awk '{print $1}')
+export PACKER_BUILD_DIR=packer_build
+export PACKER_LOG_PATH=${PACKER_BUILD_DIR}/build.log
+export PACKER_LOG=1
+
+mkdir -p ${PACKER_BUILD_DIR}
+
+packer build -only=qemu scripts/packer.json
diff --git a/scripts/check-vm-build-env b/scripts/check-vm-build-env
new file mode 100755
index 00000000..290b28c8
--- /dev/null
+++ b/scripts/check-vm-build-env
@@ -0,0 +1,61 @@
+#!/usr/bin/env python
+#
+# Copyright (C) 2016 VyOS maintainers and contributors
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 or later as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# File: check-vm-build-env
+# Purpose:
+# Checks if packages required for VM image build are installed.
+
+
+import os
+import sys
+from distutils.spawn import find_executable
+
+required_packages = [
+ 'make',
+ 'qemu-system-x86',
+ 'qemu-utils'
+]
+
+
+def is_installed(name):
+ result = os.system("dpkg-query -W --showformat='${{Status}}\n' {name} 2>&1 | grep 'install ok installed' >/dev/null".format(name=name))
+ return True if result == 0 else False
+
+
+missing_packages = []
+
+print("Checking if packages required for VyOS VM image build are installed")
+
+for p in required_packages:
+ if not is_installed(p):
+ missing_packages.append(p)
+
+if missing_packages:
+ print("Your system does not have some of the required packages installed.")
+ print("Please install the following packages:")
+ print(" ".join(missing_packages))
+ sys.exit(1)
+else:
+ print("All required packages are installed")
+
+if find_executable("packer"):
+ print("Your system has Packer.")
+else:
+ print("Your system does not have Packer.")
+ print("Please install Packer from https://www.packer.io/downloads.html.")
+ sys.exit(1)
+
+sys.exit(0)
diff --git a/scripts/packer.json b/scripts/packer.json
new file mode 100644
index 00000000..5d5f201e
--- /dev/null
+++ b/scripts/packer.json
@@ -0,0 +1,62 @@
+{
+ "variables": {
+ "iso_url": "{{env `ISO_IMAGE`}}",
+ "iso_checksum": "{{env `ISO_MD5_SUM`}}",
+ "output_directory": "{{env `PACKER_BUILD_DIR`}}"
+ },
+ "builders":
+ [
+ {
+ "type": "qemu",
+ "iso_url": "{{user `iso_url`}}",
+ "iso_checksum": "{{user `iso_checksum`}}",
+ "iso_checksum_type": "md5",
+ "output_directory": "{{user `output_directory`}}/qemu",
+ "shutdown_command": "sudo halt -p",
+ "disk_size": 4096,
+ "format": "raw",
+ "headless": true,
+ "accelerator": "kvm",
+ "ssh_host_port_min": 2222,
+ "ssh_host_port_max": 2229,
+ "ssh_username": "vyos",
+ "ssh_password": "vyos",
+ "ssh_port": 22,
+ "ssh_wait_timeout": "30s",
+ "vm_name": "vyos_qemu_image.img",
+ "net_device": "virtio-net",
+ "disk_interface": "virtio",
+ "boot_wait": "5s",
+ "boot_command":
+ [
+ "<enter><wait10><wait10>",
+ "vyos<enter><wait>",
+ "vyos<enter><wait>",
+ "install image<enter><wait>",
+ "<enter><wait>",
+ "<enter><wait>",
+ "<enter><wait>",
+ "Yes<enter><wait>",
+ "<enter><wait10>",
+ "<enter><wait>",
+ "<enter><wait>",
+ "vyos<enter><wait>",
+ "vyos<enter><wait>",
+ "<enter><wait10>",
+ "reboot<enter><wait>",
+ "Yes<enter><wait10><wait10><wait10>",
+ "vyos<enter><wait>",
+ "vyos<enter><wait>",
+ "configure<enter><wait>",
+ "delete system console<enter><wait>",
+ "set interface ethernet eth0 address dhcp<enter><wait>",
+ "set service ssh<enter><wait>",
+ "commit<enter><wait>",
+ "save<enter><wait>",
+ "exit<enter><wait>",
+ "reboot<enter><wait>",
+ "Yes<enter><wait10><wait10><wait10><wait10><wait10>"
+ ]
+ }
+ ]
+}
diff --git a/tools/run-qemu-image.sh b/tools/run-qemu-image.sh
new file mode 100755
index 00000000..b021ebd6
--- /dev/null
+++ b/tools/run-qemu-image.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+VM_NAME='vyos_qemu'
+VM_IMAGE='./packer_build/qemu/vyos_qemu_image.img'
+MEMORY_SIZE='1024'
+NCPUS=1
+SSH_PORT=2222
+
+qemu-system-x86_64 \
+ -name "${VM_NAME}" \
+ -m ${MEMORY_SIZE} \
+ -net nic,vlan=0,model=virtio \
+ -net user,vlan=0,hostfwd=tcp::"${SSH_PORT}"-:22,hostname="${VM_NAME}" \
+ -drive if=virtio,file=${VM_IMAGE} \
+ -machine accel=kvm \
+ -cpu host -smp ${NCPUS}