summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build-tools/macos-build/.gitignore4
-rw-r--r--build-tools/macos-build/Makefile31
-rw-r--r--build-tools/macos-build/README.md25
-rw-r--r--build-tools/macos-build/Vagrantfile39
-rwxr-xr-xbuild-tools/macos-build/check-macos-build-env84
5 files changed, 183 insertions, 0 deletions
diff --git a/build-tools/macos-build/.gitignore b/build-tools/macos-build/.gitignore
new file mode 100644
index 0000000..d9ac3f1
--- /dev/null
+++ b/build-tools/macos-build/.gitignore
@@ -0,0 +1,4 @@
+.vagrant/
+__pycache__
+build/
+.DS_Store
diff --git a/build-tools/macos-build/Makefile b/build-tools/macos-build/Makefile
new file mode 100644
index 0000000..5c1e74c
--- /dev/null
+++ b/build-tools/macos-build/Makefile
@@ -0,0 +1,31 @@
+build_dir ?= build
+branch ?= current
+os ?= buster64
+configureopt ?= --architecture amd64
+makeopt ?= iso
+buildsuffix ?= -amd64.iso
+
+.PHONY: init
+init:
+ mkdir $(build_dir) || true
+
+.PHONY: build
+.ONESHELL:
+build: init
+ @set -e
+ @echo "It's not like I'm building this specially for you or anything!"
+ @./check-macos-build-env
+ OS=$(os) BRANCH=$(branch) CONFIGUREOPT='$(configureopt)' MAKEOPT=$(makeopt) \
+ vagrant up
+ cd $(build_dir); \
+ rsync -Lam --include='*$(buildsuffix)' --exclude='*' vagrant@10.1.1.254:/opt/vyos-build/build/ .
+
+.PHONY: clean
+clean:
+ vagrant destroy -f
+
+.PHONY: purge
+purge: clean
+ rm -rf $(build_dir)
+
+
diff --git a/build-tools/macos-build/README.md b/build-tools/macos-build/README.md
new file mode 100644
index 0000000..a0cf468
--- /dev/null
+++ b/build-tools/macos-build/README.md
@@ -0,0 +1,25 @@
+## Build VyOS iso in MAC
+
+ `make build`
+
+### Create crux based iso
+
+ `os=jessie64 branch=crux make build`
+
+### Custom build options
+
+ `os=jessie64 branch=crux configureopt='--architecture amd64 --build-by richard@vyos.io' make build`
+
+### Clean up VM
+
+ `make clean`
+
+### Purge build and clean
+
+ `make purge`
+
+### Dependencies
+
+ - vagrant
+ - virtualbox
+ - rsync
diff --git a/build-tools/macos-build/Vagrantfile b/build-tools/macos-build/Vagrantfile
new file mode 100644
index 0000000..f1b86a4
--- /dev/null
+++ b/build-tools/macos-build/Vagrantfile
@@ -0,0 +1,39 @@
+PROVISION = <<-SCRIPT
+sudo apt-get update -y
+sudo apt-get install apt-transport-https \
+ ca-certificates \
+ curl \
+ gnupg2 \
+ git \
+ software-properties-common \
+ rsync -y
+curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
+sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
+sudo apt-get update -y
+sudo apt-get install -y docker-ce
+[ -d /home/vagrant/.ssh ] && echo '%{public_key}' >> /home/vagrant/.ssh/authorized_keys; true
+[ -d /home/vagrant/.ssh ] && chmod 600 /home/vagrant/.ssh/authorized_keys; true
+sudo usermod -aG docker vagrant
+git clone -b #{ENV['BRANCH']} --single-branch https://github.com/vyos/vyos-build /opt/vyos-build
+docker run --rm -t --privileged -v /opt/vyos-build:/vyos -w /vyos vyos/vyos-build:#{ENV['BRANCH']} \
+ /bin/bash -c './configure #{ENV['CONFIGUREOPT']} && make #{ENV['MAKEOPT']}'
+SCRIPT
+
+def define_vm(config, hostname, ip)
+ public_key_path = File.join(Dir.home, ".ssh", "id_rsa.pub")
+ public_key = IO.read(public_key_path)
+
+ config.vm.define hostname do |vm|
+ vm.vm.box = "debian/#{ENV['OS']}"
+ vm.vm.hostname = hostname
+ vm.vm.network 'private_network', ip: ip
+
+ vm.vm.provision :shell, inline: (PROVISION % { public_key: public_key })
+
+ end
+end
+
+Vagrant.configure("2") do |config|
+ define_vm(config, "vyos", "10.1.1.254")
+ config.vm.synced_folder ".", "/vagrant", disabled: true
+end
diff --git a/build-tools/macos-build/check-macos-build-env b/build-tools/macos-build/check-macos-build-env
new file mode 100755
index 0000000..3cf2d2b
--- /dev/null
+++ b/build-tools/macos-build/check-macos-build-env
@@ -0,0 +1,84 @@
+#!/usr/bin/env python3
+#
+# 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-macos-build-env
+# Purpose:
+# Checks if binaries for macOS image building are installed.
+
+
+import os
+import sys
+from distutils.spawn import find_executable
+
+import platform
+
+class DependencyChecker(object):
+ def __init__(self, spec):
+ missing_binaries = self._get_missing_binaries(spec['binaries'])
+ self.__missing = {'binaries': missing_binaries}
+
+ def _get_missing_binaries(self, binaries):
+ missing_binaries = []
+ for b in binaries:
+ if not find_executable(b):
+ missing_binaries.append(b)
+ return missing_binaries
+
+ def get_missing_dependencies(self):
+ if self.__missing['binaries']:
+ return self.__missing
+ return None
+
+ def print_missing_deps(self):
+ print("Missing binaries: " + " ".join(self.__missing['binaries']))
+
+platform = platform.system()
+if platform != 'Darwin':
+ print("Your system is not macOS.")
+ sys.exit(1)
+
+deps = {
+ 'binaries': [
+ 'vagrant',
+ 'virtualbox',
+ 'rsync'
+ ]
+}
+
+print("Checking if packages required for VyOS image build are installed")
+
+checker = DependencyChecker(deps)
+
+missing = checker.get_missing_dependencies()
+print(missing)
+if not missing:
+ print("All dependencies are installed")
+ sys.exit(0)
+else:
+ checker.print_missing_deps()
+ if 'vagrant' in missing['binaries']:
+ print("Your system does not have Vagrant.")
+ print("Please install Vagrant from https://www.vagrantup.com/downloads.")
+ sys.exit(1)
+ elif 'virtualbox' in missing['binaries']:
+ print("Your system does not have Virtualbox.")
+ print("Please install Virtualbox from https://www.virtualbox.org/wiki/Downloads.")
+ sys.exit(1)
+ elif 'rsync' in missing['binaries']:
+ print("Your system does not have Rsync.")
+ print("Please install Rsync from https://formulae.brew.sh/formula/rsync.")
+ sys.exit(1)
+sys.exit(0)