From e90664189d9b161dfc2553632194efbca35b48fe Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Sat, 26 Apr 2014 22:22:31 -0400 Subject: [PATCH 01/11] cleanup(coreos-base/oem-vagrant): Move ssh key into cloud config. The old behavior of loading authorized_keys from /usr/share/oem is deprecated, so lets switch vagrant to the new config driven world. :) --- .../coreos-base/oem-vagrant/files/authorized_keys | 1 - .../coreos-base/oem-vagrant/files/cloud-config.yml | 3 +++ .../coreos-base/oem-vagrant/oem-vagrant-0.0.1.ebuild | 1 - 3 files changed, 3 insertions(+), 2 deletions(-) delete mode 100644 sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/authorized_keys diff --git a/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/authorized_keys b/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/authorized_keys deleted file mode 100644 index 18a9c00fd5..0000000000 --- a/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/authorized_keys +++ /dev/null @@ -1 +0,0 @@ -ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key diff --git a/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/cloud-config.yml b/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/cloud-config.yml index 4cf0581490..08c80deab7 100644 --- a/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/cloud-config.yml +++ b/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/cloud-config.yml @@ -13,3 +13,6 @@ coreos: name: Vagrant home-url: http://www.vagrantup.com/ bug-report-url: https://github.com/coreos/coreos-overlay + +ssh_authorized_keys: + - ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key diff --git a/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/oem-vagrant-0.0.1.ebuild b/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/oem-vagrant-0.0.1.ebuild index fc732939c0..76fbe52dd6 100644 --- a/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/oem-vagrant-0.0.1.ebuild +++ b/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/oem-vagrant-0.0.1.ebuild @@ -17,7 +17,6 @@ S="${WORKDIR}" src_install() { insinto "/usr/share/oem" - doins "${FILESDIR}/authorized_keys" doins "${FILESDIR}/cloud-config.yml" into "/usr/share/oem" From 500e9c26931681125b0aee88f82bdbde4cb8a052 Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Sat, 26 Apr 2014 23:05:22 -0400 Subject: [PATCH 02/11] add(coreos-base/coreos-vagrant): Import Vagrantfile template This is the static piece of the Vagrantfile previously defined in scripts/build_library/virtualbox_ovf.sh. Moving it here so we can start maintaining the major Vagrant OEM pieces together. --- .../coreos-base/oem-vagrant/files/box/Vagrantfile | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/Vagrantfile diff --git a/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/Vagrantfile b/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/Vagrantfile new file mode 100644 index 0000000000..50fe4487d9 --- /dev/null +++ b/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/Vagrantfile @@ -0,0 +1,11 @@ +if Vagrant::VERSION < "1.2.3" + raise "Need at least vagrant version 1.2.3, please update" +end + +Vagrant.configure("2") do |config| + # SSH in as the default 'core' user, it has the vagrant ssh key. + config.ssh.username = "core" + + # Disable the base shared folder, guest additions are unavailable. + config.vm.synced_folder ".", "/vagrant", disabled: true +end From e6244ef10cd1f568946bba98ff27280bad14bd87 Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Sat, 26 Apr 2014 23:23:46 -0400 Subject: [PATCH 03/11] add(coreos-base/oem-vagrant): Import code from coreos-vagrant Import override-plugin.rb and some VirtualBox fixups from our published Vagrantfile repo. The current Vagrant OEM depends on this code, making it impossible to boot without using our special Vagrantfile. Using the box as a stand-alone entity worked up until recently and is something users expect to work. Also bump the minimum Vagrant version to 1.5, matching our current documentation. Fixes https://github.com/coreos/bugs/issues/5 --- .../oem-vagrant/files/box/Vagrantfile | 18 ++- .../oem-vagrant/files/box/override-plugin.rb | 117 ++++++++++++++++++ 2 files changed, 133 insertions(+), 2 deletions(-) create mode 100644 sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/override-plugin.rb diff --git a/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/Vagrantfile b/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/Vagrantfile index 50fe4487d9..055355aefa 100644 --- a/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/Vagrantfile +++ b/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/Vagrantfile @@ -1,11 +1,25 @@ -if Vagrant::VERSION < "1.2.3" - raise "Need at least vagrant version 1.2.3, please update" +# -*- mode: ruby -*- +# # vi: set ft=ruby : + +if Vagrant::VERSION < "1.5.0" + raise "Need at least vagrant version 1.5.0, please update" end +require_relative 'override-plugin.rb' + Vagrant.configure("2") do |config| # SSH in as the default 'core' user, it has the vagrant ssh key. config.ssh.username = "core" # Disable the base shared folder, guest additions are unavailable. config.vm.synced_folder ".", "/vagrant", disabled: true + + config.vm.provider :virtualbox do |vb| + # Guest Additions are unavailable. + vb.check_guest_additions = false + + # Fix docker not being able to resolve private registry in VirtualBox + vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"] + vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"] + end end diff --git a/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/override-plugin.rb b/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/override-plugin.rb new file mode 100644 index 0000000000..eb0bc99589 --- /dev/null +++ b/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/override-plugin.rb @@ -0,0 +1,117 @@ +# -*- mode: ruby -*- +# # vi: set ft=ruby : + +# NOTE: This monkey-patching of the coreos guest plugin is a terrible +# hack that needs to be removed once the upstream plugin works with +# alpha CoreOS images. + +require 'tempfile' +require 'ipaddr' +require Vagrant.source_root.join("plugins/guests/coreos/cap/configure_networks.rb") + +BASE_CLOUD_CONFIG = < Date: Sat, 26 Apr 2014 23:37:37 -0400 Subject: [PATCH 04/11] fix(coreos-base/oem-vagrant): Move user config handling out of ruby code There's no reason for handling vagrantfile-user-data in the Vagrant plugin, move it to the OEM cloud-config.yml along side the user-data handler. Use the generic user-config@ unit as well. --- .../oem-vagrant/files/box/override-plugin.rb | 17 ----------------- .../oem-vagrant/files/cloud-config.yml | 7 +++++++ 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/override-plugin.rb b/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/override-plugin.rb index eb0bc99589..0d19773887 100644 --- a/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/override-plugin.rb +++ b/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/override-plugin.rb @@ -14,23 +14,6 @@ BASE_CLOUD_CONFIG = < Date: Sun, 27 Apr 2014 17:52:47 -0400 Subject: [PATCH 05/11] fix(coreos-base/oem-vagrant): Split up plugin, use change_host_name hook. The old override-plugin.rb didn't actually properly monkey patch the change host name function because it was missing a requires line pointing to the file it is defined in upstream. To clarify things split the code into two files that match the upstream names. Additionally using this hook as it is intended means it works if a host name is defined but additional networks are not. As part of the split switch to starting the units directly. The indirection through a path unit just adds complexity. --- .../oem-vagrant/files/box/Vagrantfile | 3 +- .../oem-vagrant/files/box/change_host_name.rb | 37 +++++++++++++++++++ ...erride-plugin.rb => configure_networks.rb} | 28 ++------------ .../oem-vagrant/files/cloud-config.yml | 7 ---- 4 files changed, 43 insertions(+), 32 deletions(-) create mode 100644 sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/change_host_name.rb rename sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/{override-plugin.rb => configure_networks.rb} (77%) diff --git a/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/Vagrantfile b/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/Vagrantfile index 055355aefa..db24837d3f 100644 --- a/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/Vagrantfile +++ b/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/Vagrantfile @@ -5,7 +5,8 @@ if Vagrant::VERSION < "1.5.0" raise "Need at least vagrant version 1.5.0, please update" end -require_relative 'override-plugin.rb' +require_relative 'change_host_name.rb' +require_relative 'configure_networks.rb' Vagrant.configure("2") do |config| # SSH in as the default 'core' user, it has the vagrant ssh key. diff --git a/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/change_host_name.rb b/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/change_host_name.rb new file mode 100644 index 0000000000..dfab7916be --- /dev/null +++ b/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/change_host_name.rb @@ -0,0 +1,37 @@ +# -*- mode: ruby -*- +# # vi: set ft=ruby : + +# NOTE: This monkey-patching of the coreos guest plugin is a terrible +# hack that needs to be removed once the upstream plugin works with +# alpha CoreOS images. + +require 'tempfile' +require Vagrant.source_root.join("plugins/guests/coreos/cap/change_host_name.rb") + +CLOUD_CONFIG = < Date: Sun, 27 Apr 2014 19:37:11 -0400 Subject: [PATCH 06/11] fix(coreos-base/oem-vagrant): Rework network configuration code. - Only write configs for static networks, DHCP will work by default. - Match interfaces by MAC address if possible. - Use the configured netmask instead of always using a /24 - Define default addresses in /etc/environment based on the type of network. Now using both a private and a public network works! --- .../files/box/configure_networks.rb | 109 ++++++++++++++---- 1 file changed, 86 insertions(+), 23 deletions(-) diff --git a/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/configure_networks.rb b/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/configure_networks.rb index 674e475eab..392fd50ba0 100644 --- a/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/configure_networks.rb +++ b/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/configure_networks.rb @@ -7,11 +7,17 @@ require 'tempfile' require 'ipaddr' +require 'log4r' require Vagrant.source_root.join("plugins/guests/coreos/cap/configure_networks.rb") BASE_CLOUD_CONFIG = < Date: Mon, 28 Apr 2014 16:44:09 -0400 Subject: [PATCH 07/11] fix(coreos-base/oem-vagrant): Add timeout for /etc/environment The environment file will not be written if there are no public or private networks defined since the configure_networks hook is never run. Report an error after one minute to make this situation less confusing. --- .../oem-vagrant/files/coreos-setup-environment | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/coreos-setup-environment b/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/coreos-setup-environment index 22b53abc37..616d3d1c96 100755 --- a/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/coreos-setup-environment +++ b/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/coreos-setup-environment @@ -7,7 +7,17 @@ if [ -z "$ENV" ]; then exit 1 fi +now=$(date +%s) +timeout=$(( now + 60 )) + # just block until cloudinit updates environment while ! grep -qs ^COREOS_PUBLIC_IPV4 "$ENV"; do + if [[ $timeout -lt $(date +%s) ]]; then + echo "No network configuration provided by Vagrant!" >&2 + echo "Using localhost, for default public and private IPs" >&2 + echo "COREOS_PUBLIC_IPV4=127.0.0.1" >> "$ENV" + echo "COREOS_PRIVATE_IPV4=127.0.0.1" >> "$ENV" + exit + fi sleep 0.1 done From 8ac5099b3a807ef69e2c702b15e36e5da3a2d72e Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Mon, 28 Apr 2014 18:47:53 -0400 Subject: [PATCH 08/11] fix(coreos-base/oem-vagrant): Add hook to make it easy to set base_mac The file `base_mac.rb` will be re-written when packing this into a box. --- .../coreos-base/oem-vagrant/files/box/Vagrantfile | 1 + .../coreos-base/oem-vagrant/files/box/base_mac.rb | 4 ++++ 2 files changed, 5 insertions(+) create mode 100644 sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/base_mac.rb diff --git a/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/Vagrantfile b/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/Vagrantfile index db24837d3f..b43a347cd7 100644 --- a/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/Vagrantfile +++ b/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/Vagrantfile @@ -7,6 +7,7 @@ end require_relative 'change_host_name.rb' require_relative 'configure_networks.rb' +require_relative 'base_mac.rb' Vagrant.configure("2") do |config| # SSH in as the default 'core' user, it has the vagrant ssh key. diff --git a/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/base_mac.rb b/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/base_mac.rb new file mode 100644 index 0000000000..1f26796e07 --- /dev/null +++ b/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/base_mac.rb @@ -0,0 +1,4 @@ +# This file must be rewritten with a real value for VirtualBox +Vagrant.configure("2") do |config| + config.vm.base_mac = "080027000000" +end From d7cfb39436ee1105de3c46e11ecca905c152cb8a Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Mon, 28 Apr 2014 16:53:23 -0400 Subject: [PATCH 09/11] bump(coreos-base/oem-vagrant): Update revision, include box configs. --- .../{oem-vagrant-0.0.1-r8.ebuild => oem-vagrant-0.0.1-r9.ebuild} | 0 .../coreos-base/oem-vagrant/oem-vagrant-0.0.1.ebuild | 1 + 2 files changed, 1 insertion(+) rename sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/{oem-vagrant-0.0.1-r8.ebuild => oem-vagrant-0.0.1-r9.ebuild} (100%) diff --git a/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/oem-vagrant-0.0.1-r8.ebuild b/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/oem-vagrant-0.0.1-r9.ebuild similarity index 100% rename from sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/oem-vagrant-0.0.1-r8.ebuild rename to sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/oem-vagrant-0.0.1-r9.ebuild diff --git a/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/oem-vagrant-0.0.1.ebuild b/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/oem-vagrant-0.0.1.ebuild index 76fbe52dd6..4c076dcc14 100644 --- a/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/oem-vagrant-0.0.1.ebuild +++ b/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/oem-vagrant-0.0.1.ebuild @@ -18,6 +18,7 @@ S="${WORKDIR}" src_install() { insinto "/usr/share/oem" doins "${FILESDIR}/cloud-config.yml" + doins -r "${FILESDIR}/box" into "/usr/share/oem" dobin ${FILESDIR}/coreos-setup-environment From def1901f7e8a6f20e43b2a6848924a8824301149 Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Tue, 29 Apr 2014 02:10:10 -0400 Subject: [PATCH 10/11] fix(coreos-base/oem-vagrant): Create directory for vagrant user-data. This fixes compatibility with the existing Vagrantfile in coreos-vagrant which expected the plugin code to create this directory. Also, the units can be runtime since they are always written at boot. --- .../coreos-base/oem-vagrant/files/cloud-config.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/cloud-config.yml b/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/cloud-config.yml index a40a1b65f0..f6512e7b48 100644 --- a/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/cloud-config.yml +++ b/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/cloud-config.yml @@ -1,9 +1,16 @@ #cloud-config coreos: units: + - name: coreos-cloudinit-vagrant-mkdir.service + command: start + runtime: yes + content: | + [Service] + Type=oneshot + ExecStart=/bin/mkdir -p /var/lib/coreos-vagrant - name: coreos-cloudinit-vagrant-user.path command: start - runtime: no + runtime: yes content: | [Path] PathExists=/var/lib/coreos-vagrant/vagrantfile-user-data From c0b34b285c6f9ca46162daa2185f4866bef1167e Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Tue, 29 Apr 2014 03:26:54 -0400 Subject: [PATCH 11/11] fix(coreos-base/oem-vagrant): Fix up comments Fix some comments that were written for a previous iteration of code. --- .../oem-vagrant/files/box/configure_networks.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/configure_networks.rb b/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/configure_networks.rb index 392fd50ba0..e2a4c65d68 100644 --- a/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/configure_networks.rb +++ b/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-vagrant/files/box/configure_networks.rb @@ -93,9 +93,8 @@ module VagrantPlugins end end - # Find IP addresses to export in /etc/environment. This step - # must be performed here because that file must be written even - # if there are no additional networks configured. + # Find IP addresses to export in /etc/environment. This only works + # for static addresses defined in the user's Vagrantfile. def self.get_environment_ips(machine, default) public_ipv4 = nil private_ipv4 = nil @@ -109,7 +108,7 @@ module VagrantPlugins end end - # Fall back to localhost if no networks are configured. + # Fall back to localhost if no static networks are configured. private_ipv4 ||= default public_ipv4 ||= private_ipv4 return [public_ipv4, private_ipv4]