Merge pull request #77 from bassamtabbara/add-vagrant-demo

add a vagrant demo file for CoreOS
This commit is contained in:
Bassam Tabbara authored and GitHub committed 2016-10-13 17:57:43 -07:00
commit f87b5faa06
6 files changed
+159 -9

No files matched your search

+3
View File
@@ -10,3 +10,6 @@ vendor/
coverage.out
coverage.html
debug.test
.vagrant/
demo/vagrant/cloud-config.yml
+3 -5
View File
@@ -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
+6 -4
View File
@@ -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}
}
+25
View File
@@ -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
+66
View File
@@ -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"
}
}
+56
View File
@@ -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