vagrant-layout 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7df38e9feb8a4e818a87ad7924a1452bcbf50d02
4
- data.tar.gz: 25df792cda72734a15feafabf5e8b118f2024468
3
+ metadata.gz: fa4d543c7752fe9ae1cde442aaa9edd83deffe82
4
+ data.tar.gz: 7e30892ce995cf83eb7e1ea931f84f8eb0ab6f81
5
5
  SHA512:
6
- metadata.gz: b231cae5fa8d2ee031deb77c5ddf3b86b48080d5e04043b1cddc6d88a6a4d8b60060affde27fa253c1c212cb660b7488ed3fe8c6951fab177fdec9bece1fdd7a
7
- data.tar.gz: f10b53efc735c7988b05aed1e562e180416458367c9210fdd6e14fdad1fcb53e625184d9ec46bbd53d4876d063740eea8660f6c3a47dc3bdaf0f57600956eb59
6
+ metadata.gz: b179aed280d0edc79234813af903c08ed662e3fddaa0f58fc5fb2923bba2d3d54bc8f414ca631c621344806abf020b159b7b410ec097d1ef0df73f05defe5286
7
+ data.tar.gz: a288b0fd74ada757c60b6e2b2ae6eb6f3c5d689923b21ad148762df2c2aa65737ae6ff19cccb30b0e7dc789e5634d27d1e955f36127925e1492e98a29b17c597
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile CHANGED
@@ -3,6 +3,7 @@ source 'https://rubygems.org'
3
3
  group :development do
4
4
  # https://github.com/mitchellh/vagrant/pull/4869
5
5
  gem 'vagrant', :git => 'https://github.com/mitchellh/vagrant.git', :ref => 'v1.6.5'
6
+ gem 'rspec'
6
7
  end
7
8
 
8
9
  group :plugins do
data/README.md CHANGED
@@ -1,24 +1,118 @@
1
- # Vagrant::Layout
1
+ # vagrant-layout plugin
2
+
3
+ vagrant-layout plugin do:
4
+
5
+ 1. Download files from GitHub repository
6
+ 2. Patch or overwrite the files using Gist
2
7
 
3
- TODO: Write a gem description
4
8
 
5
9
  ## Installation
6
10
 
7
- Add this line to your application's Gemfile:
11
+ ```
12
+ $ vagrant plugin install vagrant-layout
13
+ $ vagrant layout --help
14
+ ```
15
+
16
+ ## Plugin Usage
17
+
18
+ ```
19
+ $ vagrant layout init [target]
20
+ ```
21
+
22
+ The targets can be one of the:
23
+
24
+ * GitHub branch name (`ruby`)
25
+ * GitHub user name and branch name (`koseki/ruby`)
26
+ * GitHub user name, repository name and branch name (`koseki/vagrant-layout/ruby`)
27
+ * GitHub commit URL (`https://github.com/koseki/vagrant-layout/commit/e09768d`)
28
+ * GitHub tree URL (`https://github.com/koseki/vagrant-layout/tree/e09768d`)
29
+ * Gist URL (`https://gist.github.com/koseki/37f61d9a02b9a48e6651`)
30
+ * Blank. The default target is `koseki/vagrant-layout/master`
31
+
32
+ ### Examples
33
+
34
+ At first, create project directory.
35
+
36
+ ```
37
+ $ mkdir your_project_name
38
+ $ cd your_project_name
39
+ ```
40
+
41
+ Download from [master branch](https://github.com/koseki/vagrant-layout/tree/master). This is default layout sample. Install Nginx to CentOS.
42
+
43
+ ```
44
+ $ vagrant layout init
45
+ ```
46
+
47
+ Download from [php branch](https://github.com/koseki/vagrant-layout/tree/php). Install Nginx, MySQL, PHP, php-fpm and Composer.
48
+
49
+ ```
50
+ $ vagrant layout init php
51
+ ```
52
+
53
+ Download from [ruby branch](https://github.com/koseki/vagrant-layout/tree/ruby). Install Nginx, MySQL, Ruby and Bundler.
54
+
55
+ ```
56
+ $ vagrant layout init ruby
57
+ ```
58
+
59
+ Download from specific commit and apply patch using [gist](https://gist.github.com/koseki/efbd631472c932ff2153). Install Laravel.
60
+
61
+ ```
62
+ $ vagrant layout init https://gist.github.com/koseki/efbd631472c932ff2153
63
+ ```
64
+
65
+ Download from specific commit and apply patch using [gist](https://gist.github.com/koseki/37f61d9a02b9a48e6651). Install Rails.
66
+
67
+ ```
68
+ $ vagrant layout init https://gist.github.com/koseki/37f61d9a02b9a48e6651
69
+ ```
70
+
71
+ Fork this repository and create your own layout.
72
+
73
+ ```
74
+ ## default repository is vagrant-layout.
75
+ $ vagrant layout init ${github_username}/${branch_name}
76
+ $ vagrant layout init ${github_username}/${repository}/${branch_name}
77
+ ```
78
+
79
+ Download from specific commit.
80
+
81
+ ```
82
+ $ vagrant layout init https://github.com/koseki/vagrant-layout/commit/e73c4b21
83
+ ```
84
+
85
+ ## Start VM
86
+
87
+ Doble click `sandbox/osx/start.command` or `sandbox/win/start.command`.
88
+
89
+ * You need VirtualBox and Vagrant.
90
+
91
+ On Windows:
92
+
93
+ * ssh command required for `vagrant ssh`. Git includes `ssh.exe`
94
+ * use `LF` to execute shellscript. check `convert-eol.bat`
95
+ * do not include white space and non-ASCII character in your project directory path
96
+ * do not include white space and non-ASCII character in VAGRANT_HOME
97
+
98
+ If you want to use proxy:
99
+
100
+ * execute `sandbox/osx/use-proxy.command` or `use-proxy.bat` and edit generated config file
8
101
 
9
- gem 'vagrant-layout'
102
+ ## Stop VM
10
103
 
11
- And then execute:
104
+ Dobule click `sandbox/osx/stop.command` or `stop.bat`.
12
105
 
13
- $ bundle
106
+ ## Update team member's VM
14
107
 
15
- Or install it yourself as:
108
+ 1. Update `sandbox/bin/provision.sh` and commit, push
109
+ 2. Ask all team members to pull and execute `sandbox/osx/manage/provision.command` or `provision.bat`
16
110
 
17
- $ gem install vagrant-layout
111
+ You can't change old provisioning commands. Add new command blocks to `provisioning.sh`.
18
112
 
19
- ## Usage
113
+ ## Uninstall VM
20
114
 
21
- TODO: Write usage instructions here
115
+ Double click `sandbox/osx/manage/uninstall.command` or `uninstall.bat`.
22
116
 
23
117
  ## Contributing
24
118
 
data/Rakefile CHANGED
@@ -1,2 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
-
2
+ begin
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ rescue LoadError
6
+ end
@@ -9,13 +9,13 @@ module VagrantPlugins
9
9
  #
10
10
  class Command < Vagrant.plugin(2, :command)
11
11
  def self.synopsis
12
- 'TODO: synopsis'
12
+ 'create Vagrant layout files'
13
13
  end
14
14
 
15
15
  def execute
16
16
  opts = { force: false }
17
17
  oparser = OptionParser.new do |o|
18
- o.banner = 'Usage: vagrant layout init [gist-url]'
18
+ o.banner = 'Usage: vagrant layout init [branch|url]'
19
19
  o.on('-f', '--force', 'Overwrite existing files') do |f|
20
20
  opts[:force] = f
21
21
  end
@@ -23,7 +23,10 @@ module VagrantPlugins
23
23
  end
24
24
 
25
25
  opts[:argv] = parse_options(oparser)
26
- if opts[:argv].empty?
26
+
27
+ if opts[:argv].nil? # --help
28
+ return -1
29
+ elsif opts[:argv].to_a.empty?
27
30
  puts oparser.help
28
31
  return -1
29
32
  end
@@ -2,6 +2,7 @@ require 'yaml'
2
2
  require 'fileutils'
3
3
  require 'tmpdir'
4
4
  require 'open-uri'
5
+ require_relative 'target'
5
6
  require_relative 'tar_gz'
6
7
 
7
8
  module VagrantPlugins
@@ -10,15 +11,16 @@ module VagrantPlugins
10
11
  # init command
11
12
  #
12
13
  class CommandInit
13
- DEFAULT_REPOSITORY = %w{koseki vagrant-layout master}
14
-
15
14
  def initialize(opts)
16
15
  @opts = opts
17
16
  end
18
17
 
19
18
  def execute
20
- target = parse_target(@opts[:argv].shift)
21
- return -1 unless target
19
+ begin
20
+ target = Target.new(@opts[:argv].shift)
21
+ rescue InvalidArgumentException
22
+ return -1
23
+ end
22
24
 
23
25
  Dir.mktmpdir do |root|
24
26
  dir = download_layout(root, target)
@@ -28,61 +30,28 @@ module VagrantPlugins
28
30
  0
29
31
  end
30
32
 
31
- def parse_target(target)
32
- return github_target(DEFAULT_REPOSITORY) unless target
33
-
34
- if target =~ %r{\A(https://gist\.github\.com/[^/]+/[0-9a-f]+)(/(download)?)?}
35
- url = Regexp.last_match[1]
36
- path = Regexp.last_match[2]
37
- if path == '/'
38
- url += 'download'
39
- elsif path.to_s == ''
40
- url += '/download'
41
- else
42
- url += path
43
- end
44
- return [:gist, url]
45
- end
46
-
47
- target = target.split('/')
48
- if target.length == 1
49
- target = [DEFAULT_REPOSITORY[0], DEFAULT_REPOSITORY[1], target[0]]
50
- elsif target.length == 2
51
- target = [target[0], DEFAULT_REPOSITORY[1], target[1]]
52
- elsif target.length >= 4
53
- target = target[0..3]
54
- end
55
-
56
- github_target(target)
57
- end
58
-
59
- def github_target(target)
60
- url = "https://github.com/#{ target[0] }/#{ target[1] }/archive/#{ target[2] }.tar.gz"
61
- [:github, url]
62
- end
63
-
64
33
  def download_layout(root, target)
65
- if target[0] == :github
34
+ if target.type == :github
66
35
  return download_github(root, target)
67
- elsif target[0] == :gist
36
+ elsif target.type == :gist
68
37
  dir = download_gist(root, target)
69
38
  return merge_gist_to_github(root, dir)
70
39
  end
71
40
  end
72
41
 
73
42
  def download_github(root, target)
74
- puts "Downloading: #{ target[1] }"
43
+ puts "Downloading: #{ target.url }"
75
44
  targz = File.join(root, 'base.tar.gz')
76
45
  dest = File.join(root, 'github')
77
- extract_tgz(target[1], targz, dest)
46
+ extract_tgz(target.url, targz, dest)
78
47
  first_dir(dest)
79
48
  end
80
49
 
81
50
  def download_gist(root, target)
82
- puts "Downloading: #{ target[1] }"
51
+ puts "Downloading: #{ target.url }"
83
52
  targz = File.join(root, 'gist.tar.gz')
84
53
  dest = File.join(root, 'gist')
85
- extract_tgz(target[1], targz, dest)
54
+ extract_tgz(target.url, targz, dest)
86
55
  first_dir(dest)
87
56
  end
88
57
 
@@ -106,15 +75,21 @@ module VagrantPlugins
106
75
  def merge_gist_to_github(root, gist_dir)
107
76
  dotfile = File.join(gist_dir, '.vagrant-layout')
108
77
  github_dir = nil
78
+
109
79
  if File.file?(dotfile)
110
80
  dot = YAML.load(File.read(dotfile))
111
81
  if dot['base']
112
- if dot['base'] =~ %r{https://github.com/([-\w]+)/([-\w]+)/tree/([0-9a-f]{40})}
113
- github_dir = download_github(root, github_target(Regexp.last_match[1..3]))
82
+ begin
83
+ target = Target.new(dot['base'])
84
+ rescue ArgumentError
85
+ end
86
+
87
+ if target && target.type == :github
88
+ github_dir = download_github(root, target)
114
89
  else
115
- msg = 'Illegal base url. Base URL must be like '
116
- msg += 'https://github.com/{user}/{repos}/tree/[0-9a-f]{40}'
117
- fail msg
90
+ err = 'Illegal base url. Base URL must be like '
91
+ err += 'https://github.com/{user}/{repos}/(tree|commit)/[0-9a-f]+'
92
+ fail err
118
93
  end
119
94
  end
120
95
  end
@@ -150,9 +125,7 @@ module VagrantPlugins
150
125
 
151
126
  overwrite = []
152
127
  sources.each do |src|
153
- if File.exist?(src) && ! File.directory?(src)
154
- overwrite << src
155
- end
128
+ overwrite << src if File.exist?(src) && !File.directory?(src)
156
129
  end
157
130
 
158
131
  unless overwrite.empty?
@@ -0,0 +1,70 @@
1
+ module VagrantPlugins
2
+ module Layout
3
+ #
4
+ # Command Target
5
+ #
6
+ class Target
7
+ DEFAULT_REPOSITORY = %w{koseki vagrant-layout master}
8
+
9
+ attr_reader :type, :url
10
+
11
+ def initialize(target_str, default_repository = nil)
12
+ @default_repository = default_repository || DEFAULT_REPOSITORY
13
+ if target_str.to_s.strip.empty?
14
+ github_target(@default_repository)
15
+ elsif target_str =~ %r{https://}
16
+ parse_url(target_str)
17
+ else
18
+ parse_repository_name(target_str)
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ #
25
+ # * GitHub Tree URL
26
+ # https://github.com/koseki/vagrant-layout/tree/php
27
+ # https://github.com/koseki/vagrant-layout/tree/e09768d91387ea4465abb8755a3cd2eb011bee9a
28
+ # * GitHub Commit URL
29
+ # https://github.com/koseki/vagrant-layout/commit/e09768d91387ea4465abb8755a3cd2eb011bee9a
30
+ # * Gist URL
31
+ # https://gist.github.com/koseki/37f61d9a02b9a48e6651
32
+ #
33
+ def parse_url(url)
34
+ if url =~ %r{\A(https://gist\.github\.com/[^/]+/[0-9a-f]+)/?\z}
35
+ gist_target(Regexp.last_match[1])
36
+ elsif url =~ %r{\Ahttps://github.com/([^/]+)/([^/]+)/(?:tree|commit)/([^/]+)/?\z}
37
+ github_target(Regexp.last_match[1..3])
38
+ else
39
+ msg = 'Invalid target URL. URL must be Gist URL or GitHub tree URL'
40
+ fail ArgumentError, msg
41
+ end
42
+ end
43
+
44
+ def parse_repository_name(name)
45
+ target = name.split('/')
46
+ fail ArgumentError, 'Invalid target' if target.any? { |t| t.strip.empty? }
47
+
48
+ if target.length == 1
49
+ target = [@default_repository[0], @default_repository[1], target[0]]
50
+ elsif target.length == 2
51
+ target = [target[0], @default_repository[1], target[1]]
52
+ elsif target.length >= 4
53
+ target = target[0..3]
54
+ end
55
+ github_target(target)
56
+ end
57
+
58
+ def github_target(target)
59
+ url = "https://github.com/#{ target[0] }/#{ target[1] }/archive/#{ target[2] }.tar.gz"
60
+ @type = :github
61
+ @url = url
62
+ end
63
+
64
+ def gist_target(url)
65
+ @type = :gist
66
+ @url = url + '/download'
67
+ end
68
+ end
69
+ end
70
+ end
@@ -3,6 +3,6 @@ module VagrantPlugins
3
3
  # Vagrant Layout Plugin
4
4
  #
5
5
  module Layout
6
- VERSION = '0.0.8'
6
+ VERSION = '0.0.9'
7
7
  end
8
8
  end
@@ -0,0 +1,7 @@
1
+ require 'rspec'
2
+
3
+ RSpec.configure do |config|
4
+ config.filter_run focus: true
5
+ config.run_all_when_everything_filtered = true
6
+ config.order = :random
7
+ end
@@ -0,0 +1,67 @@
1
+ require 'vagrant-layout/target'
2
+
3
+ describe VagrantPlugins::Layout::Target do
4
+ let(:default_target) { %w{user repo tree} }
5
+ subject { VagrantPlugins::Layout::Target.new(target, default_target) }
6
+
7
+ context 'with nil target' do
8
+ subject { VagrantPlugins::Layout::Target.new(nil) }
9
+
10
+ its(:type) { should eq :github }
11
+ its(:url) { should eq 'https://github.com/koseki/vagrant-layout/archive/master.tar.gz' }
12
+ end
13
+
14
+ context 'with default_target argument' do
15
+ let(:target) { nil }
16
+ its(:type) { should eq :github }
17
+ its(:url) { should eq 'https://github.com/user/repo/archive/tree.tar.gz' }
18
+ end
19
+
20
+ context 'with tree target' do
21
+ let(:target) { 'php' }
22
+ its(:type) { should eq :github }
23
+ its(:url) { should eq 'https://github.com/user/repo/archive/php.tar.gz' }
24
+ end
25
+
26
+ context 'with user/tree target' do
27
+ let(:target) { 'someone/php' }
28
+ its(:type) { should eq :github }
29
+ its(:url) { should eq 'https://github.com/someone/repo/archive/php.tar.gz' }
30
+ end
31
+
32
+ context 'with user/repo/tree target' do
33
+ let(:target) { 'someone/layout/php' }
34
+ its(:type) { should eq :github }
35
+ its(:url) { should eq 'https://github.com/someone/layout/archive/php.tar.gz' }
36
+ end
37
+
38
+ context 'with user/repo/tree target' do
39
+ let(:target) { 'someone/layout/php' }
40
+ its(:type) { should eq :github }
41
+ its(:url) { should eq 'https://github.com/someone/layout/archive/php.tar.gz' }
42
+ end
43
+
44
+ context 'with Gist URL' do
45
+ let(:target) { 'https://gist.github.com/koseki/37f61d9a02b9a48e6651' }
46
+ its(:type) { should eq :gist }
47
+ its(:url) { should eq target + '/download' }
48
+ end
49
+
50
+ context 'with branch name tree URL' do
51
+ let(:target) { 'https://github.com/koseki/vagrant-layout/tree/php' }
52
+ its(:type) { should eq :github }
53
+ its(:url) { should eq 'https://github.com/koseki/vagrant-layout/archive/php.tar.gz' }
54
+ end
55
+
56
+ context 'with hash tree URL' do
57
+ let(:target) { 'https://github.com/koseki/vagrant-layout/tree/e09768d9' }
58
+ its(:type) { should eq :github }
59
+ its(:url) { should eq 'https://github.com/koseki/vagrant-layout/archive/e09768d9.tar.gz' }
60
+ end
61
+
62
+ context 'with commit URL' do
63
+ let(:target) { 'https://github.com/koseki/vagrant-layout/commit/e09768d9' }
64
+ its(:type) { should eq :github }
65
+ its(:url) { should eq 'https://github.com/koseki/vagrant-layout/archive/e09768d9.tar.gz' }
66
+ end
67
+ end
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-layout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - KOSEKI Kengo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-21 00:00:00.000000000 Z
11
+ date: 2015-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.6'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  description: vagrant layout plugin
@@ -45,8 +45,9 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
- - .gitignore
49
- - .rubocop.yml
48
+ - ".gitignore"
49
+ - ".rspec"
50
+ - ".rubocop.yml"
50
51
  - Gemfile
51
52
  - LICENSE.txt
52
53
  - README.md
@@ -56,7 +57,10 @@ files:
56
57
  - lib/vagrant-layout/command_init.rb
57
58
  - lib/vagrant-layout/plugin.rb
58
59
  - lib/vagrant-layout/tar_gz.rb
60
+ - lib/vagrant-layout/target.rb
59
61
  - lib/vagrant-layout/version.rb
62
+ - spec/spec_helper.rb
63
+ - spec/target_spec.rb
60
64
  - vagrant-layout.gemspec
61
65
  homepage: ''
62
66
  licenses:
@@ -68,12 +72,12 @@ require_paths:
68
72
  - lib
69
73
  required_ruby_version: !ruby/object:Gem::Requirement
70
74
  requirements:
71
- - - '>='
75
+ - - ">="
72
76
  - !ruby/object:Gem::Version
73
77
  version: '0'
74
78
  required_rubygems_version: !ruby/object:Gem::Requirement
75
79
  requirements:
76
- - - '>='
80
+ - - ">="
77
81
  - !ruby/object:Gem::Version
78
82
  version: '0'
79
83
  requirements: []
@@ -82,4 +86,6 @@ rubygems_version: 2.0.14
82
86
  signing_key:
83
87
  specification_version: 4
84
88
  summary: vagrant layout plugin
85
- test_files: []
89
+ test_files:
90
+ - spec/spec_helper.rb
91
+ - spec/target_spec.rb