mirror of
https://github.com/vyos/vyos-build.git
synced 2025-10-01 20:28:40 +02:00
Merge pull request #2 from higebu/qemu-image
Add qemu image build scripts
This commit is contained in:
commit
c6bca34587
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,2 +1,4 @@
|
|||||||
build/*
|
build/*
|
||||||
*.pyc
|
*.pyc
|
||||||
|
packer_build/*
|
||||||
|
packer_cache/*
|
||||||
|
|||||||
7
Makefile
7
Makefile
@ -37,6 +37,13 @@ prepare-package-env:
|
|||||||
@scripts/pbuilder-config
|
@scripts/pbuilder-config
|
||||||
@scripts/pbuilder-setup
|
@scripts/pbuilder-setup
|
||||||
|
|
||||||
|
.PHONY: qemu
|
||||||
|
.ONESHELL:
|
||||||
|
qemu:
|
||||||
|
@set -e
|
||||||
|
@scripts/check-vm-build-env
|
||||||
|
@scripts/build-qemu-image
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
.ONESHELL:
|
.ONESHELL:
|
||||||
clean:
|
clean:
|
||||||
|
|||||||
30
scripts/build-qemu-image
Executable file
30
scripts/build-qemu-image
Executable file
@ -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
|
||||||
61
scripts/check-vm-build-env
Executable file
61
scripts/check-vm-build-env
Executable file
@ -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)
|
||||||
62
scripts/packer.json
Normal file
62
scripts/packer.json
Normal file
@ -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>"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
16
tools/run-qemu-image.sh
Executable file
16
tools/run-qemu-image.sh
Executable file
@ -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}
|
||||||
Loading…
x
Reference in New Issue
Block a user