From 9ac4a77289bbfd8f4c5522376b59d07ee29a9ff2 Mon Sep 17 00:00:00 2001 From: Bassam Tabbara Date: Wed, 12 Oct 2016 21:03:22 -0700 Subject: [PATCH] add a vagrant demo file for CoreOS added a demo vagrant file that starts a bare CoreOS cluster and runs castle on it. --- .gitignore | 3 ++ build/makelib/release.mk | 8 ++-- build/release/aci.sh | 10 +++-- demo/vagrant/Vagrantfile | 25 ++++++++++++ demo/vagrant/cloud-config.yml.in | 66 ++++++++++++++++++++++++++++++++ demo/vagrant/util.rb | 56 +++++++++++++++++++++++++++ 6 files changed, 159 insertions(+), 9 deletions(-) create mode 100644 demo/vagrant/Vagrantfile create mode 100644 demo/vagrant/cloud-config.yml.in create mode 100644 demo/vagrant/util.rb diff --git a/.gitignore b/.gitignore index 6a588e21f..5da13fb3c 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,6 @@ vendor/ coverage.out coverage.html debug.test + +.vagrant/ +demo/vagrant/cloud-config.yml diff --git a/build/makelib/release.mk b/build/makelib/release.mk index 3348e740f..6eb4ff143 100644 --- a/build/makelib/release.mk +++ b/build/makelib/release.mk @@ -28,7 +28,7 @@ RELEASE_CLIENT_ONLY_PLATFORMS ?= RELEASE_HOST_PLATFORM ?= $(shell go env GOHOSTOS)_$(shell go env GOHOSTARCH) # Optional. the flavors to release -RELEASE_FLAVORS := binaries docker +RELEASE_FLAVORS := binaries docker aci # Optional. Github token repo and user GITHUB_TOKEN ?= @@ -56,11 +56,9 @@ release.build.parallel: $(foreach f,$(RELEASE_FLAVORS), release.build.$(f)) release.publish.parallel: $(foreach f,$(RELEASE_FLAVORS), release.publish.$(f)) -release.check: - @build/release/release.sh check - -release.build: release.check +release.build: @$(MAKE) release.build.parallel release.publish: release.build + @build/release/release.sh check @$(MAKE) release.publish.parallel diff --git a/build/release/aci.sh b/build/release/aci.sh index 8fe24a512..e489c6e26 100755 --- a/build/release/aci.sh +++ b/build/release/aci.sh @@ -3,7 +3,7 @@ scriptdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" source ${scriptdir}/common.sh -container=quantum.com/castle +container=quantum.com/castled build() { local type=$1 @@ -21,13 +21,15 @@ build() { mkdir -p ${RELEASE_DIR} local acb="acbuild --debug --work-path $tmpdir" - local acifile=${RELEASE_DIR}/castle-${version}-${os}-${arch}.aci + local acifile=${RELEASE_DIR}/castled-${version}-${os}-${arch}.aci echo creating aci file ${acifile} ${acb} begin ${acb} set-name ${container} - ${acb} copy-to-dir $tmpdir/root / + for f in $(find $tmpdir/root -maxdepth 1); do + ${acb} copy-to-dir ${f} / + done ${acb} label add version "$version" ${acb} set-exec -- /usr/bin/castled ${acb} write --overwrite ${acifile} @@ -44,7 +46,7 @@ publish() { [[ ${type} == "both" ]] || return 0 - local aci=${RELEASE_DIR}/castle-${version}-${os}-${arch}.aci + local aci=${RELEASE_DIR}/castled-${version}-${os}-${arch}.aci echo uploading aci file ${acifile} } diff --git a/demo/vagrant/Vagrantfile b/demo/vagrant/Vagrantfile new file mode 100644 index 000000000..3e363a8a2 --- /dev/null +++ b/demo/vagrant/Vagrantfile @@ -0,0 +1,25 @@ +VAGRANTFILE_API_VERSION = "2" + +$channel = "alpha" +$nodes = 3 +$new_discovery_url="https://discovery.etcd.io/new?size=1" + +require_relative 'util.rb' +require 'open-uri' + +Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| + set_coreos_box(config, $channel) + + (0..($nodes - 1)).each do |i| + config.vm.define name="castle%02d" % i, primary: (i == 0), autostart: (i == 0) do |node| + node.vm.hostname = name + node.vm.network "private_network", ip: "172.20.20.#{10+i}" + + # enable if you want to run for locally build ACI files + #node.vm.synced_folder "../../release", "/release", id: "release", :nfs => true, :mount_options => ['nolock,vers=3,tcp'] + + node.vm.provision :cloud_config, :template => "cloud-config.yml.in", + :subst => { "%%token%%" => open($new_discovery_url).read } + end + end +end diff --git a/demo/vagrant/cloud-config.yml.in b/demo/vagrant/cloud-config.yml.in new file mode 100644 index 000000000..dd607034f --- /dev/null +++ b/demo/vagrant/cloud-config.yml.in @@ -0,0 +1,66 @@ +#cloud-config + +coreos: + units: + - name: castled.service + enable: true + command: start +# enable if you want to run from locally built ACI files +# drop-ins: +# - name: 10-local-aci.conf +# content: | +# [Service] +# Environment=CASTLED_ACI=/release/castled-dev-linux-amd64.aci +# Environment=RKT_OPTIONS=--insecure-options=image + content: | + [Unit] + Description=Castle Daemon - software defined storage + Requires=network-online.target + After=network-online.target + + [Service] + Slice=machine.slice + Restart=always + KillMode=process + + Environment=CASTLED_ACI=quay.io/quantum/castled:latest + Environment=CASTLED_ID=%m + Environment=CASTLED_DISCOVERY_URL=%%token%% + Environment=CASTLED_PUBLIC_IPV4=$public_ipv4 + Environment=CASTLED_PRIVATE_IPV4=$private_ipv4 + Environment=CASTLED_DATA_DIRS=/var/lib/castled/data + + ExecStartPre=/usr/bin/mkdir -p ${CASTLED_DATA_DIRS} + + ExecStart=/usr/bin/rkt run \ + --trust-keys-from-https \ + --stage1-from-dir=stage1-fly.aci \ + --inherit-env \ + --volume dns,kind=host,source=/run/systemd/resolve/resolv.conf,readOnly=true \ + --mount volume=dns,target=/etc/resolv.conf \ + --volume var-lib-castled,kind=host,source=/var/lib/castled \ + --mount volume=var-lib-castled,target=/var/lib/castled \ + $RKT_OPTIONS \ + $CASTLED_ACI + + [Install] + WantedBy=multi-user.target + +# temporary until we make the repo public. +write_files: + - path: /etc/rkt/auth.d/quantum-demo-auth.json + owner: root:root + permissions: '0600' + content: | + { + "rktKind": "auth", + "rktVersion": "v1", + "domains": [ + "quay.io" + ], + "type": "basic", + "credentials": { + "user": "quantum+demo", + "password": "OD8HPMSRYOI5TU8ZWNXFHBXRM39HX4X7GB6MLW060SZ2W5DD04TEN5TCW3MHDNPO" + } + } diff --git a/demo/vagrant/util.rb b/demo/vagrant/util.rb new file mode 100644 index 000000000..99c9e9821 --- /dev/null +++ b/demo/vagrant/util.rb @@ -0,0 +1,56 @@ +def set_coreos_box(config, channel) + config.vm.box = "coreos-%s" % channel + config.vm.box_url = "http://%s.release.core-os.net/amd64-usr/current/coreos_production_vagrant.json" % $coreos_channel + + ["vmware_fusion", "vmware_workstation"].each do |vmware| + config.vm.provider vmware do |v, override| + override.vm.box_url = "http://%s.release.core-os.net/amd64-usr/current/coreos_production_vagrant_vmware_fusion.json" % $coreos_channel + end + end +end + +# a plugin to set the cloud-config file and substitute variables +class CloudConfigPlugin < Vagrant.plugin('2') + name 'cloud_config' + + config(:'cloud_config', :provisioner) do + class Config < Vagrant.plugin('2', :config) + attr_accessor :template + attr_accessor :subst + + def validate(machine) + errors = _detected_errors + if !template + errors << I18n.t("vagrant.provisioners.cloud_config.template") + end + { "Cloud Config provisioner" => errors } + end + end + Config + end + + provisioner :cloud_config do + class Provisioner < Vagrant.plugin('2', :provisioner) + def provision + @machine.ui.info("Creating cloud-config file") + + configfile = IO.readlines("#{config.template}")[0..-1].join + + config.subst.each do |key, value| + if ! configfile[key].nil? + configfile[key]=value + end + end + + File.open("cloud-config.yml", 'w') { |file| file.write(configfile) } + + @machine.communicate.tap do |comm| + comm.upload(File.expand_path("cloud-config.yml"), "/tmp/vagrantfile-user-data") + command = "mv /tmp/vagrantfile-user-data /var/lib/coreos-vagrant/" + comm.execute(command, sudo: config.privileged) + end + end + end + Provisioner + end +end