diff options
author | Yuya Kusakabe <yuya.kusakabe@gmail.com> | 2017-07-29 15:30:57 +0900 |
---|---|---|
committer | Yuya Kusakabe <yuya.kusakabe@gmail.com> | 2017-07-29 15:30:57 +0900 |
commit | 822747f4de0274e366452c594c1a65562740a4f1 (patch) | |
tree | 9034efed4caaa4c56e07ba57c0f30b8e00fce8f5 | |
parent | 795546f923b900cb8dd6594972ab183e7447917b (diff) | |
download | vyos-build-822747f4de0274e366452c594c1a65562740a4f1.tar.gz vyos-build-822747f4de0274e366452c594c1a65562740a4f1.zip |
Add vagrant-libvirt make target
-rw-r--r-- | Makefile | 7 | ||||
-rwxr-xr-x | scripts/build-vagrant-libvirt-box | 69 | ||||
-rw-r--r-- | scripts/packer.json | 57 |
3 files changed, 77 insertions, 56 deletions
@@ -46,6 +46,13 @@ qemu: @scripts/check-vm-build-env @scripts/build-qemu-image +.PHONY: vagrant-libvirt +.ONESHELL: +vagrant-libvirt: + @set -e + @scripts/check-vm-build-env + @scripts/build-vagrant-libvirt-box + .PHONY: vmware .ONESHELL: vmware: diff --git a/scripts/build-vagrant-libvirt-box b/scripts/build-vagrant-libvirt-box new file mode 100755 index 00000000..5cb0b041 --- /dev/null +++ b/scripts/build-vagrant-libvirt-box @@ -0,0 +1,69 @@ +#!/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-vagrant-libvirt-box +# Purpose: +# Build VyOS Vagrant libvirt box. + +export PACKER_BUILD_DIR=packer_build + +DST_DIR=${PACKER_BUILD_DIR}/vagrant-libvirt +BOX_DIR=${DST_DIR}/box +mkdir -p ${BOX_DIR} + +# Copy qcow2 image +cp -p packer_build/qemu/vyos_qemu_image.img ${BOX_DIR}/box.img + +# Put metadata.json and Vagrantfile +echo '{"format":"qcow2","provider":"libvirt","virtual_size":4}' > ${BOX_DIR}/metadata.json +cat <<EOF > ${BOX_DIR}/Vagrantfile +Vagrant.configure("2") do |config| + config.vm.synced_folder './', '/vagrant', + type: "rsync", + owner: 'vyos', + group: 'users', + mount_options: ['dmode=775,fmode=775'] + config.ssh.username = "vyos" + config.ssh.password = "vyos" + config.vm.provider :libvirt do |libvirt| + libvirt.driver = "kvm" + end +end +EOF + +# Create box +box=${DST_DIR}/vyos_vagrant_libvirt.box +tar -C ${BOX_DIR} -czvf ${box} metadata.json Vagrantfile box.img +if [ "$?" = "0" ]; then + echo "Vagrant libvirt box successfully created to ./${box}" +fi + +PROVIDER=libvirt + +# Create version +curl -XPOST -d "version[version]=${VERSION}" \ + https://app.vagrantup.com/api/v1/box/${VAGRANT_BOX_NAME}/versions?access_token=${VAGRANT_CLOUD_ACCESS_TOKEN} +echo + +# Create provider +curl -XPOST -d "provider[name]=${PROVIDER}" -d "provider[url]=${VAGRANT_BOX_BASE_URL}" \ + https://app.vagrantup.com/api/v1/box/${VAGRANT_BOX_NAME}/version/${VERSION}/providers?access_token=${VAGRANT_CLOUD_ACCESS_TOKEN} +echo + +# Release version +curl -XPUT \ + https://app.vagrantup.com/api/v1/box/${VAGRANT_BOX_NAME}/version/${VERSION}/release?access_token=${VAGRANT_CLOUD_ACCESS_TOKEN} +echo diff --git a/scripts/packer.json b/scripts/packer.json index 30bd2fb7..218b2a85 100644 --- a/scripts/packer.json +++ b/scripts/packer.json @@ -2,11 +2,7 @@ "variables": { "iso_url": "{{env `ISO_IMAGE`}}", "iso_checksum": "{{env `ISO_MD5_SUM`}}", - "output_directory": "{{env `PACKER_BUILD_DIR`}}", - "box_tag": "{{env `VAGRANT_BOX_NAME`}}", - "cloud_token": "{{env `VAGRANT_CLOUD_ACCESS_TOKEN`}}", - "version": "{{env `VERSION`}}", - "box_base_url": "{{env `BOX_BASE_URL`}}" + "output_directory": "{{env `PACKER_BUILD_DIR`}}" }, "builders": [ @@ -61,57 +57,6 @@ "save<enter><wait5>", "exit<enter><wait5>" ] - }, - { - "name": "vmware-image", - "type": "qemu", - "iso_url": "{{user `output_directory`}}/qemu/vyos_qemu_image.img", - "iso_checksum_type": "none", - "output_directory": "{{user `output_directory`}}/vmware", - "shutdown_command": "sudo halt -p", - "disk_image": true, - "disk_size": 4096, - "format": "raw", - "headless": true, - "accelerator": "tcg", - "ssh_host_port_min": 2222, - "ssh_host_port_max": 2229, - "ssh_username": "vyos", - "ssh_password": "vyos", - "ssh_port": 22, - "ssh_wait_timeout": "300s", - "vm_name": "vyos_vmware_image.img", - "net_device": "virtio-net", - "disk_interface": "virtio", - "boot_wait": "5s" - } - ], - "provisioners": [ - { - "type": "shell", - "only": ["vmware-image"], - "scripts": [ - "scripts/packer-scripts/vmware.sh" - ] } - ], - "post-processors": [ - [ - { - "type": "vagrant", - "only": ["qemu-image"], - "vagrantfile_template": "scripts/Vagrantfile", - "output": "{{user `output_directory`}}/vagrant-libvirt/vyos_vagrant_libvirt.box", - "keep_input_artifact": true - }, - { - "type": "vagrant-cloud", - "only": ["qemu-image"], - "box_tag": "{{user `box_tag`}}", - "access_token": "{{user `cloud_token`}}", - "version": "{{user `version`}}", - "box_download_url": "{{user `box_base_url`}}/vyos-{{user `version`}}-vagrant-libvirt.box" - } - ] ] } |