Permalink
Browse files

Add a mainstream mode to make packaged/installed omv easier

The entire inspiration and critical idea for this mode came from
rbarlow. I had some time to hack on it, and fought with the
implementation since he was busy hacking on other things.
  • Loading branch information...
1 parent 8530734 commit aa764ae79d69475b87f293c43af4f20fd7d1d000 @purpleidea committed Jul 2, 2015
Showing with 110 additions and 23 deletions.
  1. +18 −0 DOCUMENTATION.md
  2. +50 −0 bin/omv.sh
  3. +42 −23 vagrant/Vagrantfile
View
@@ -31,6 +31,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2. [Project description - What the project does](#project-description)
3. [Setup - Getting started with Oh-My-Vagrant](#setup)
* [What can Oh-My-Vagrant do?](#what-can-oh-my-vagrant-do)
+ * [Mainstream usage](#mainstream-usage)
* [Simple usage](#simple-usage)
* [Complex usage](#complex-usage)
* [Example modules](#example-modules)
@@ -88,6 +89,23 @@ Oh-My-Vagrant is designed to be able to deal with:
* Automatic Kubernetes setup
* And much more...
+###Mainstream usage
+Oh-My-Vagrant now supports a "mainstream" mode. This is the most common way to
+use OMV when it is installed via your package manager. You interact with it
+entirely with the `omv` binary. The `omv` binary works exactly like the
+`vagrant` command that you're used to, except that it works directly on the
+`omv.yaml` file, and hides the Vagrantfile complexity inside a system folder.
+
+To initialize a new OMV environment, you can run:
+
+```bash
+$ omv init
+```
+
+to automatically create an `omv.yaml` file. If you supply a path as an argument
+to the init verb, then all OMV project specific files will be stored in this
+sub directory, to avoid cluttering up your project root directory.
+
###Simple usage
For most use cases, the simple usage of Oh-My-Vagrant should fulfill all your
View
@@ -0,0 +1,50 @@
+#!/usr/bin/bash
+
+# This is: Oh My Vagrant!
+# Copyright (C) 2012-2015+ James Shubin
+# Written by James Shubin <james@shubin.ca>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# 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 Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+vagrantdir="$HOME/code/oh-my-vagrant/vagrant/" # this should be set at install
+projectdir="`pwd`" # default to where we are
+args=$@
+
+if [ "$1" = '' ]; then
+ echo -e "Usage: ./"`basename $0`" --help | init [dir] | <vagrant cmd>"
+fi
+
+# initialize a new omv project (if called with $2 it puts mess in that folder!)
+if [ "$1" = 'init' ]; then
+ args='status'
+ if [ "$2" != '' ]; then
+ mkdir -p "$projectdir/$2"
+ ln -s "$2/omv.yaml" 'omv.yaml' # relative, not absolute symlink!
+ args="--omv-folder=$2 $args"
+ fi
+fi
+
+omvsearch=$projectdir
+# search upwards for omv.yaml
+while [ "$omvsearch" != "/" ]; do
+ if [ -e "$omvsearch/omv.yaml" ]; then
+ projectdir="$omvsearch" # found one!
+ break
+ fi
+ omvsearch=`dirname "$omvsearch"`
+done
+
+# this is where the magic happens...
+VAGRANT_CWD="$vagrantdir" VAGRANT_DOTFILE_PATH="$projectdir/.vagrant/" vagrant $args
+
View
@@ -111,6 +111,7 @@ end
# 42
#EOT
+vagrantfiledir = File.expand_path File.dirname(__FILE__) # Vagrantfile dir
projectdir = File.expand_path File.dirname(__FILE__) # vagrant project dir!!
#
@@ -119,7 +120,7 @@ projectdir = File.expand_path File.dirname(__FILE__) # vagrant project dir!!
# Vagrant is using it's own gem path. Using local xdg gem
# Another option could be adding xdg gem directly to vagrant
begin
- gemlibdir = File.join(projectdir, 'gems/xdg/lib')
+ gemlibdir = File.join(vagrantfiledir, 'gems/xdg/lib')
$:.unshift(gemlibdir) # add local path for gems
require 'xdg'
auth_config = File.join("#{XDG['CONFIG']}/oh-my-vagrant/", 'auth.yaml')
@@ -139,6 +140,22 @@ if File.exist?(auth_config)
end
#
+# mainstream mode
+#
+if "#{ENV['VAGRANT_CWD']}" != '' # if called by omv.sh, this is set...
+ projectdir = "#{Dir.pwd}" # and we're calling from the new root
+ omvsearch = projectdir
+ while omvsearch != '/' # search upwards for omv.yaml
+ if File.exist?(File.join(omvsearch, 'omv.yaml'))
+ projectdir = omvsearch # found one!
+ break
+ end
+ omvsearch = File.expand_path('..', omvsearch)
+ end
+end
+#ENV['VAGRANT_DOTFILE_PATH'] = File.join(projectdir, '.vagrant/')
+
+#
# ARGV parsing
#
f = g = File.join(projectdir, 'omv.yaml')
@@ -555,30 +572,32 @@ end
# this extern code should be one of the *last* things before the big configure!
folder = (folder + '/') if not(folder.end_with?('/')) # ensure trailing slash
folder = '' if folder.start_with?('/') # only relative paths are allowed...
-
-if load_folder
- puppet_basedir = File.join(projectdir, folder, 'puppet/', 'modules/')
- # NOTE: i called the ansible child dir 'modules' because i didn't know
- # what to call it. Suggestions welcome! It's not really 'playbooks' or
- # 'roles' really, so it's 'modules' until something better comes along
- ansible_basedir = File.join(projectdir, folder, 'ansible/', 'modules/')
- docker_basedir = File.join(projectdir, folder, 'docker/')
- kubernetes_basedir = File.join(projectdir, folder, 'kubernetes/', 'applications/')
- ktemplates_basedir = File.join(projectdir, folder, 'kubernetes/', 'templates/')
-else
- puppet_basedir = File.join(projectdir, 'puppet/', 'modules/')
- ansible_basedir = File.join(projectdir, 'ansible/', 'modules/')
- docker_basedir = File.join(projectdir, 'docker/')
- kubernetes_basedir = File.join(projectdir, 'kubernetes/', 'applications/')
- ktemplates_basedir = File.join(projectdir, 'kubernetes/', 'templates/')
-end
+#puts "folder is: #{folder}" # debug
+
+puppet_basedir = File.join(projectdir, folder, 'puppet/', 'modules/')
+# NOTE: i called the ansible child dir 'modules' because i didn't know
+# what to call it. Suggestions welcome! It's not really 'playbooks' or
+# 'roles' really, so it's 'modules' until something better comes along
+ansible_basedir = File.join(projectdir, folder, 'ansible/', 'modules/')
+docker_basedir = File.join(projectdir, folder, 'docker/')
+kubernetes_basedir = File.join(projectdir, folder, 'kubernetes/', 'applications/')
+ktemplates_basedir = File.join(projectdir, folder, 'kubernetes/', 'templates/')
+
+# mkdir in case these folders are missing
+mkdirp = 'mkdir -p'
+mkdirp += " #{puppet_basedir}"
+mkdirp += " #{ansible_basedir}"
+mkdirp += " #{docker_basedir}"
+mkdirp += " #{kubernetes_basedir}"
+mkdirp += " #{ktemplates_basedir}"
+`#{mkdirp}`
native = [] # native files
-native += `cd "#{puppet_basedir}" && git ls-files`.strip.split("\n")
-native += `cd "#{ansible_basedir}" && git ls-files`.strip.split("\n")
-native += `cd "#{docker_basedir}" && git ls-files`.strip.split("\n")
-native += `cd "#{kubernetes_basedir}" && git ls-files`.strip.split("\n")
-native += `cd "#{ktemplates_basedir}" && git ls-files`.strip.split("\n")
+native += `cd "#{puppet_basedir}" && (git status &> /dev/null) && git ls-files`.strip.split("\n")
+native += `cd "#{ansible_basedir}" && (git status &> /dev/null) && git ls-files`.strip.split("\n")
+native += `cd "#{docker_basedir}" && (git status &> /dev/null) && git ls-files`.strip.split("\n")
+native += `cd "#{kubernetes_basedir}" && (git status &> /dev/null) && git ls-files`.strip.split("\n")
+native += `cd "#{ktemplates_basedir}" && (git status &> /dev/null) && git ls-files`.strip.split("\n")
if extern.length > 0
extern.each do |i|

0 comments on commit aa764ae

Please sign in to comment.