From: Mike Marchetti Date: Wed, 13 Jun 2018 13:21:40 +0000 (-0400) Subject: Add packer scripts for vagrant image generation X-Git-Tag: BUILD_v4.0.1_1~13 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F67%2F6267%2F1;p=osm%2Fdevops.git Add packer scripts for vagrant image generation Change-Id: If163c456b756f6c7c8a7a197dabc8eb3b1fc7907 Signed-off-by: Mike Marchetti --- diff --git a/packer/.gitignore b/packer/.gitignore new file mode 100644 index 00000000..7979d3aa --- /dev/null +++ b/packer/.gitignore @@ -0,0 +1,3 @@ +output-virtualbox-iso/ +packer_cache/ +builds/ diff --git a/packer/http/preseed.cfg b/packer/http/preseed.cfg new file mode 100644 index 00000000..c2d3d41f --- /dev/null +++ b/packer/http/preseed.cfg @@ -0,0 +1,40 @@ +choose-mirror-bin mirror/http/proxy string +d-i base-installer/kernel/override-image string linux-server +d-i clock-setup/utc boolean true +d-i clock-setup/utc-auto boolean true +d-i finish-install/reboot_in_progress note +d-i grub-installer/only_debian boolean true +d-i grub-installer/with_other_os boolean true +d-i partman-auto/disk string /dev/sda +d-i partman-auto-lvm/guided_size string max +d-i partman-auto/choose_recipe select atomic +d-i partman-auto/method string lvm +d-i partman-lvm/confirm boolean true +d-i partman-lvm/confirm boolean true +d-i partman-lvm/confirm_nooverwrite boolean true +d-i partman-lvm/device_remove_lvm boolean true +d-i partman/choose_partition select finish +d-i partman/confirm boolean true +d-i partman/confirm_nooverwrite boolean true +d-i partman/confirm_write_new_label boolean true +d-i pkgsel/include string openssh-server cryptsetup build-essential libssl-dev libreadline-dev zlib1g-dev linux-source dkms nfs-common +d-i pkgsel/install-language-support boolean false +d-i pkgsel/update-policy select none +d-i pkgsel/upgrade select full-upgrade +d-i time/zone string UTC +tasksel tasksel/first multiselect standard, ubuntu-server + +d-i console-setup/ask_detect boolean false +d-i keyboard-configuration/layoutcode string us +d-i keyboard-configuration/modelcode string pc105 +d-i debian-installer/locale string en_US + +# Create vagrant user account. +d-i passwd/user-fullname string vagrant +d-i passwd/username string vagrant +d-i passwd/user-password password vagrant +d-i passwd/user-password-again password vagrant +d-i user-setup/allow-password-weak boolean true +d-i user-setup/encrypt-home boolean false +d-i passwd/user-default-groups vagrant sudo +d-i passwd/user-uid string 900 diff --git a/packer/scripts/cleanup.sh b/packer/scripts/cleanup.sh new file mode 100644 index 00000000..cc09a976 --- /dev/null +++ b/packer/scripts/cleanup.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +apt autoremove +apt update + +rm -f /home/vagrant/*.sh + +wget --no-check-certificate https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub -O /home/vagrant/.ssh/authorized_keys +chmod 0600 /home/vagrant/.ssh/authorized_keys +chown -R vagrant:vagrant /home/vagrant/.ssh + +dd if=/dev/zero of=/EMPTY bs=1M +rm -f /EMPTY +sync diff --git a/packer/scripts/get-install-osm.sh b/packer/scripts/get-install-osm.sh new file mode 100755 index 00000000..534799bb --- /dev/null +++ b/packer/scripts/get-install-osm.sh @@ -0,0 +1,8 @@ +#!/bin/bash +export PATH=$PATH:/snap/bin +echo "PATH=$PATH" +juju status + +wget "$1" +chmod +x install_osm.sh +./install_osm.sh --nolxd -y --vimemu diff --git a/packer/scripts/install_packages.sh b/packer/scripts/install_packages.sh new file mode 100644 index 00000000..e24c8261 --- /dev/null +++ b/packer/scripts/install_packages.sh @@ -0,0 +1,3 @@ +#!/bin/sh +sudo apt -y update && apt-get -y upgrade +sudo apt -y install git wget curl vim snapd docker.io zfs lxd software-properties-common diff --git a/packer/scripts/juju-setup.sh b/packer/scripts/juju-setup.sh new file mode 100755 index 00000000..55752e56 --- /dev/null +++ b/packer/scripts/juju-setup.sh @@ -0,0 +1,2 @@ +#!/bin/sh +sudo snap install juju --classic diff --git a/packer/scripts/lxd-bridge b/packer/scripts/lxd-bridge new file mode 100644 index 00000000..ff421502 --- /dev/null +++ b/packer/scripts/lxd-bridge @@ -0,0 +1,54 @@ +# WARNING: This file is generated by a debconf template! +# It is recommended to update it by using "dpkg-reconfigure -p medium lxd" + +# Whether to setup a new bridge or use an existing one +USE_LXD_BRIDGE="true" + +# Bridge name +# This is still used even if USE_LXD_BRIDGE is set to false +# set to an empty value to fully disable +LXD_BRIDGE="lxdbr0" + +# Update the "default" LXD profile +UPDATE_PROFILE="true" + +# Path to an extra dnsmasq configuration file +LXD_CONFILE="" + +# DNS domain for the bridge +LXD_DOMAIN="lxd" + +# IPv4 +## IPv4 address (e.g. 10.0.8.1) +LXD_IPV4_ADDR="10.49.16.1" + +## IPv4 netmask (e.g. 255.255.255.0) +LXD_IPV4_NETMASK="255.255.255.0" + +## IPv4 network (e.g. 10.0.8.0/24) +LXD_IPV4_NETWORK="10.49.16.1/24" + +## IPv4 DHCP range (e.g. 10.0.8.2,10.0.8.254) +LXD_IPV4_DHCP_RANGE="10.49.16.2,10.49.16.254" + +## IPv4 DHCP number of hosts (e.g. 250) +LXD_IPV4_DHCP_MAX="252" + +## NAT IPv4 traffic +LXD_IPV4_NAT="true" + +# IPv6 +## IPv6 address (e.g. 2001:470:b368:4242::1) +LXD_IPV6_ADDR="" + +## IPv6 CIDR mask (e.g. 64) +LXD_IPV6_MASK="" + +## IPv6 network (e.g. 2001:470:b368:4242::/64) +LXD_IPV6_NETWORK="" + +## NAT IPv6 traffic +LXD_IPV6_NAT="false" + +# Run a minimal HTTP PROXY server +LXD_IPV6_PROXY="false" diff --git a/packer/scripts/lxd-setup.sh b/packer/scripts/lxd-setup.sh new file mode 100644 index 00000000..a92dd170 --- /dev/null +++ b/packer/scripts/lxd-setup.sh @@ -0,0 +1,10 @@ +sudo lxd init --auto --storage-backend zfs --storage-pool lxdpool --storage-create-loop 20 + +sudo systemctl stop lxd-bridge +sudo systemctl --system daemon-reload + +sudo cp -f /tmp/lxd-bridge /etc/default/lxd-bridge +sudo systemctl enable lxd-bridge +sudo systemctl start lxd-bridge + +sudo usermod -a -G lxd $(whoami) diff --git a/packer/scripts/setup.sh b/packer/scripts/setup.sh new file mode 100644 index 00000000..de27aa72 --- /dev/null +++ b/packer/scripts/setup.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +echo "vagrant ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers +sed -i "s/^.*requiretty/#Defaults requiretty/" /etc/sudoers +echo 'APT::Periodic::Enable "0";' >> /etc/apt/apt.conf.d/10periodic diff --git a/packer/ubuntu1604-juju.json b/packer/ubuntu1604-juju.json new file mode 100644 index 00000000..79b49eda --- /dev/null +++ b/packer/ubuntu1604-juju.json @@ -0,0 +1,91 @@ +{ + "provisioners": [ + { + "type": "shell", + "execute_command": "echo 'vagrant' | {{.Vars}} sudo -S -E bash '{{.Path}}'", + "script": "scripts/install_packages.sh" + }, + { + "type": "shell", + "execute_command": "echo 'vagrant' | {{.Vars}} sudo -S -E bash '{{.Path}}'", + "script": "scripts/setup.sh" + }, + { + "type": "file", + "source": "scripts/lxd-bridge", + "destination": "/tmp/lxd-bridge" + }, + { + "type": "shell", + "script": "scripts/lxd-setup.sh" + }, + { + "type": "shell", + "script": "scripts/juju-setup.sh" + } + ], + "builders": [ + { + "type": "virtualbox-iso", + "boot_command": [ + "", + "", + "", + "", + "/install/vmlinuz", + " auto", + " console-setup/ask_detect=false", + " console-setup/layoutcode=us", + " console-setup/modelcode=pc105", + " debconf/frontend=noninteractive", + " debian-installer=en_US", + " fb=false", + " initrd=/install/initrd.gz", + " kbd-chooser/method=us", + " keyboard-configuration/layout=USA", + " keyboard-configuration/variant=USA", + " locale=en_US", + " netcfg/get_domain=vm", + " netcfg/get_hostname=vagrant", + " grub-installer/bootdev=/dev/sda", + " noapic", + " preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg", + " -- ", + "" + ], + "boot_wait": "10s", + "disk_size": 15360, + "guest_os_type": "Ubuntu_64", + "headless": true, + "http_directory": "http", + "iso_urls": [ + "iso/ubuntu-16.04.4-server-amd64.iso", + "http://releases.ubuntu.com/16.04/ubuntu-16.04.4-server-amd64.iso" + ], + "iso_checksum_type": "sha256", + "iso_checksum": "0a03608988cfd2e50567990dc8be96fb3c501e198e2e6efcb846d89efc7b89f2", + "ssh_username": "vagrant", + "ssh_password": "vagrant", + "ssh_port": 22, + "ssh_wait_timeout": "10000s", + "shutdown_command": "echo 'vagrant'|sudo -S shutdown -P now", + "guest_additions_path": "VBoxGuestAdditions_{{.Version}}.iso", + "virtualbox_version_file": ".vbox_version", + "vm_name": "packer-ubuntu-16.04-amd64-juju", + "vboxmanage": [ + [ + "modifyvm", + "{{.Name}}", + "--memory", + "4096" + ], + [ + "modifyvm", + "{{.Name}}", + "--cpus", + "2" + ] + ] + } + ] +} diff --git a/packer/ubuntu1604-ovf-osm.json b/packer/ubuntu1604-ovf-osm.json new file mode 100644 index 00000000..08221bd2 --- /dev/null +++ b/packer/ubuntu1604-ovf-osm.json @@ -0,0 +1,53 @@ +{ + "provisioners": [ + { + "type": "shell", + "script": "scripts/get-install-osm.sh", + "execute_command": "{{.Path}} {{user `osm_installer`}}" + }, + { + "type": "shell", + "execute_command": "echo 'vagrant' | {{.Vars}} sudo -S -E bash '{{.Path}}'", + "script": "scripts/cleanup.sh" + } + ], + "variables": { + "osm_installer": "https://osm-download.etsi.org/ftp/osm-4.0-four/install_osm.sh", + "input_ovf": "output-virtualbox-iso/packer-ubuntu-16.04-amd64-juju.ovf", + "vm_name": "packer-ubuntu-16.04-ovf-amd64" + }, + "builders": [ + { + "type": "virtualbox-ovf", + "source_path": "{{user `input_ovf`}}", + "headless": true, + "ssh_username": "vagrant", + "ssh_password": "vagrant", + "ssh_port": 22, + "ssh_wait_timeout": "10000s", + "shutdown_command": "echo 'vagrant'|sudo -S shutdown -P now", + "virtualbox_version_file": ".vbox_version", + "vm_name": "{{user `vm_name`}}", + "vboxmanage": [ + [ + "modifyvm", + "{{.Name}}", + "--memory", + "4096" + ], + [ + "modifyvm", + "{{.Name}}", + "--cpus", + "2" + ] + ] + } + ], + "post-processors": [ + { + "output": "builds/{{.Provider}}-osm.box", + "type": "vagrant" + } + ] +}