vagrant-symfony 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ pkg/
2
+ Gemfile.lock
3
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ # We depend on Vagrant for development, but we don't add it as a
7
+ # gem dependency because we expect to be installed within the
8
+ # Vagrant environment itself using `vagrant plugin`.
9
+ gem "vagrant", :git => "https://github.com/mitchellh/vagrant.git"
10
+ end
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ # Immediately sync all stdout so that tools like buildbot can
5
+ # immediately load in the output.
6
+ $stdout.sync = true
7
+ $stderr.sync = true
8
+
9
+ # Change to the directory of this file.
10
+ Dir.chdir(File.expand_path("../", __FILE__))
11
+
12
+ # This installs the tasks that help with gem creation and
13
+ # publishing.
14
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,10 @@
1
+ require "pathname"
2
+ require "vagrant-symfony/symfony"
3
+
4
+ module VagrantSymfony
5
+ # lib_path = Pathname.new(File.expand_path("../vagrant-symfony", __FILE__))
6
+
7
+ def self.source_root
8
+ @source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
9
+ end
10
+ end
@@ -0,0 +1,30 @@
1
+ require "log4r"
2
+
3
+ module VagrantSymfony
4
+ module Action
5
+ class Boot
6
+ def initialize(app, env)
7
+ @app = app
8
+ @logger = Log4r::Logger.new('vagranysymfony::action::boot')
9
+ end
10
+
11
+ def call(env)
12
+ @app.call(env)
13
+ vm = env[:machine]
14
+ if vm.config.symfony.updateNginx
15
+ folder = vm.config.symfony.webFolder
16
+ root = vm.config.symfony.rootFolder
17
+ if folder.start_with? './'
18
+ folder = root + folder[1..-1]
19
+ elsif !folder.start_with('/')
20
+ folder = root + '/' + folder
21
+ end
22
+ file = vm.config.symfony.nginxHostfile
23
+ vm.env.ui.info("Updating web directory and reloading config...")
24
+ vm.communicate.sudo("sed 's@root .*;@root #{folder};@g' #{file}")
25
+ vm.communicate.sudo("service nginx reload")
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,65 @@
1
+ require 'shellwords'
2
+ require_relative '../which'
3
+
4
+ module VagrantSymfony
5
+ module Command
6
+ class CommandInVm < Vagrant.plugin('2', :command)
7
+ def execute
8
+ with_target_vms do |vm|
9
+ if vm.state.id == :running
10
+ cmd = build_command(vm)
11
+ if interactive
12
+ run_interactive_command(vm, cmd)
13
+ else
14
+ run_command(vm, cmd)
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ def support_color
21
+ ENV.include?('TERM') && ENV['TERM'].include?('color')
22
+ end
23
+
24
+ def working_directory(vm)
25
+ vm.config.symfony.root
26
+ end
27
+
28
+ def run_interactive_command(vm, cmd)
29
+ ssh_bin = VagrantSymfony::Which.which('ssh')
30
+ if ssh_bin != nil
31
+ info = vm.ssh_info
32
+ args = [
33
+ info[:host],
34
+ '-t',
35
+ '-p', info[:port].to_s,
36
+ '-l', info[:username],
37
+ '-i', info[:private_key_path],
38
+ '-o', 'LogLevel=QUIET',
39
+ '--', cmd
40
+ ]
41
+ Vagrant::Util::SafeExec.exec('ssh', *args)
42
+ end
43
+ run_command(vm, cmd)
44
+ end
45
+
46
+ def run_command(vm, cmd)
47
+ communicator = vm.communicate
48
+ if communicator.ready?
49
+ exit_status = communicator.execute(cmd, :error_check => false) do |type, data|
50
+ channel = type == :stdout ? :out : :error
51
+ @env.ui.info(data.to_s, :prefix => false, :new_line => false, :channel => channel)
52
+ end
53
+ else
54
+ @env.ui.error("Could not execute command")
55
+ end
56
+ exit exit_status
57
+ end
58
+
59
+ def in_working_directory(vm, cmd)
60
+ wd = working_directory(vm)
61
+ "(cd #{wd}; #{cmd})"
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,17 @@
1
+ require_relative 'commandinvm'
2
+
3
+ module VagrantSymfony
4
+ module Command
5
+ class ComposerCommand < CommandInVm
6
+ def interactive
7
+ true
8
+ end
9
+
10
+ def build_command(vm)
11
+ command = Shellwords.join(@argv)
12
+ command = '--ansi ' + command if support_color
13
+ in_working_directory(vm, "composer.phar #{command}")
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ require_relative 'commandinvm'
2
+
3
+ module VagrantSymfony
4
+ module Command
5
+ class SymfonyCommand < CommandInVm
6
+ def interactive
7
+ true
8
+ end
9
+
10
+ def build_command(vm)
11
+ command = Shellwords.join(@argv)
12
+ command = '--ansi ' + command if support_color
13
+ name = vm.config.symfony.commandName
14
+ in_working_directory(vm, "#{name} #{command}")
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,42 @@
1
+ module VagrantSymfony
2
+ module Config
3
+ class Config < Vagrant.plugin('2', :config)
4
+ attr_accessor :web, :cmd, :update_nginx, :nginx_hostfile, :root
5
+
6
+ def initialize
7
+ @web = UNSET_VALUE
8
+ @cmd = UNSET_VALUE
9
+ @update_nginx = UNSET_VALUE
10
+ @nginx_hostfile = UNSET_VALUE
11
+ @root = UNSET_VALUE
12
+ end
13
+
14
+ def rootFolder
15
+ return "/vagrant" if @root == UNSET_VALUE
16
+ return @root[0..-2] if @root[-1] == '/'
17
+ return @root
18
+ end
19
+
20
+ def webFolder
21
+ return "./web" if @web == UNSET_VALUE
22
+ return @web[0..-2] if @web[-1] == '/'
23
+ return @web
24
+ end
25
+
26
+ def commandName
27
+ return "./app/console" if @cmd == UNSET_VALUE
28
+ return @cmd
29
+ end
30
+
31
+ def updateNginx
32
+ return false if @update_nginx == UNSET_VALUE
33
+ return @update_nginx
34
+ end
35
+
36
+ def nginxHostfile
37
+ return "/etc/nginx/sites-enabled/default" if @nginx_hostfile == UNSET_VALUE
38
+ return @nginx_hostfile
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,29 @@
1
+ module VagrantSymfony
2
+ class VagrantSymfonyPlugin < Vagrant.plugin('2')
3
+ name "VagrantSymfony"
4
+
5
+ config "symfony" do
6
+ require_relative "config/config"
7
+ Config::Config
8
+ end
9
+
10
+ ["sf", "symfony", "cmd", "console"].each do |cmd|
11
+ command cmd do
12
+ require_relative "command/symfony"
13
+ Command::SymfonyCommand
14
+ end
15
+ end
16
+
17
+ ["composer"].each do |cmd|
18
+ command cmd do
19
+ require_relative "command/composer"
20
+ Command::ComposerCommand
21
+ end
22
+ end
23
+
24
+ action_hook(ALL_ACTIONS) do |hook|
25
+ require_relative "action/boot"
26
+ hook.before(Vagrant::Action::Builtin::Provision, Action::Boot)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module VagrantSymfony
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantSymfony
2
+ require 'shellwords'
3
+
4
+ class Which
5
+ def self.which(cmd)
6
+ exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') + [''] : ['']
7
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
8
+ exts.each do |ext|
9
+ exe = File.join(path, "#{cmd}#{ext}")
10
+ return exe if File.executable? exe
11
+ end
12
+ end
13
+ return nil
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,53 @@
1
+ $:.unshift File.expand_path("../lib", __FILE__)
2
+ require "vagrant-symfony/version"
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "vagrant-symfony"
6
+ s.version = VagrantSymfony::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = "Ruben Nijveld"
9
+ s.email = "ruben@gewooniets.nl"
10
+ s.homepage = "http://github.com/rnijveld/vagrant-symfony"
11
+ s.summary = "Adds some useful functionality for working with vagrant and Symfony2."
12
+ s.description = "Adds some useful functionality for working with vagrant and Symfony2."
13
+
14
+ s.required_rubygems_version = ">= 1.3.6"
15
+ s.rubyforge_project = "vagrant-symfony"
16
+
17
+ s.add_development_dependency "rake"
18
+
19
+ # The following block of code determines the files that should be included
20
+ # in the gem. It does this by reading all the files in the directory where
21
+ # this gemspec is, and parsing out the ignored files from the gitignore.
22
+ # Note that the entire gitignore(5) syntax is not supported, specifically
23
+ # the "!" syntax, but it should mostly work correctly.
24
+ root_path = File.dirname(__FILE__)
25
+ all_files = Dir.chdir(root_path) { Dir.glob("**/{*,.*}") }
26
+ all_files.reject! { |file| [".", ".."].include?(File.basename(file)) }
27
+ gitignore_path = File.join(root_path, ".gitignore")
28
+ gitignore = File.readlines(gitignore_path)
29
+ gitignore.map! { |line| line.chomp.strip }
30
+ gitignore.reject! { |line| line.empty? || line =~ /^(#|!)/ }
31
+
32
+ unignored_files = all_files.reject do |file|
33
+ # Ignore any directories, the gemspec only cares about files
34
+ next true if File.directory?(file)
35
+
36
+ # Ignore any paths that match anything in the gitignore. We do
37
+ # two tests here:
38
+ #
39
+ # - First, test to see if the entire path matches the gitignore.
40
+ # - Second, match if the basename does, this makes it so that things
41
+ # like '.DS_Store' will match sub-directories too (same behavior
42
+ # as git).
43
+ #
44
+ gitignore.any? do |ignore|
45
+ File.fnmatch(ignore, file, File::FNM_PATHNAME) ||
46
+ File.fnmatch(ignore, File.basename(file), File::FNM_PATHNAME)
47
+ end
48
+ end
49
+
50
+ s.files = unignored_files
51
+ s.executables = unignored_files.map { |f| f[/^bin\/(.*)/, 1] }.compact
52
+ s.require_path = 'lib'
53
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-symfony
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ruben Nijveld
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Adds some useful functionality for working with vagrant and Symfony2.
31
+ email: ruben@gewooniets.nl
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - Gemfile
37
+ - lib/vagrant-symfony/action/boot.rb
38
+ - lib/vagrant-symfony/command/commandinvm.rb
39
+ - lib/vagrant-symfony/command/composer.rb
40
+ - lib/vagrant-symfony/command/symfony.rb
41
+ - lib/vagrant-symfony/config/config.rb
42
+ - lib/vagrant-symfony/symfony.rb
43
+ - lib/vagrant-symfony/version.rb
44
+ - lib/vagrant-symfony/which.rb
45
+ - lib/vagrant-symfony.rb
46
+ - pkg/vagrant-symfony-0.1.0.gem
47
+ - Rakefile
48
+ - vagrant-symfony.gemspec
49
+ - .gitignore
50
+ - pkg/.gitignore
51
+ homepage: http://github.com/rnijveld/vagrant-symfony
52
+ licenses: []
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ segments:
64
+ - 0
65
+ hash: 1596714359253639046
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: 1.3.6
72
+ requirements: []
73
+ rubyforge_project: vagrant-symfony
74
+ rubygems_version: 1.8.25
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: Adds some useful functionality for working with vagrant and Symfony2.
78
+ test_files: []