]> gitweb.fluxo.info Git - leap/leap_cli.git/commitdiff
added @allow_production_deploy and @platform_branch to Leapfile
authorelijah <elijah@riseup.net>
Fri, 1 Mar 2013 06:41:25 +0000 (22:41 -0800)
committerelijah <elijah@riseup.net>
Fri, 1 Mar 2013 06:41:25 +0000 (22:41 -0800)
lib/leap_cli/commands/deploy.rb
lib/leap_cli/commands/pre.rb
lib/leap_cli/commands/vagrant.rb
lib/leap_cli/config/manager.rb
lib/leap_cli/leapfile.rb
lib/leap_cli/util.rb

index 4cfefd7b4c461562d790636527586017ea82f3cb..065a1119d0776ab04379ad64295498f7fb8d9839 100644 (file)
@@ -20,7 +20,7 @@ module LeapCli
       c.action do |global,options,args|
         init_submodules
 
-        nodes = manager.filter!(args)
+        nodes = filter_deploy_nodes(args)
         if nodes.size > 1
           say "Deploying to these nodes: #{nodes.keys.join(', ')}"
           if !global[:yes] && !agree("Continue? ")
@@ -141,5 +141,17 @@ module LeapCli
       return includes
     end
 
+    #
+    # for safety, we allow production deploys to be turned off in the Leapfile.
+    #
+    def filter_deploy_nodes(filter)
+      nodes = manager.filter!(filter)
+      if !leapfile.allow_production_deploy
+        nodes = nodes[:production => false]
+        assert! nodes.any?, "Skipping deploy because @allow_production_deploy is disabled."
+      end
+      nodes
+    end
+
   end
 end
index 03355bb11a05c28ce3817f3790466261823aad30..cb92fe2ac6b7f24f856aee4bc9eef8a5af3b443c 100644 (file)
@@ -47,6 +47,13 @@ module LeapCli
         bail! { log :missing, "platform directory '#{Path.platform}'" }
       end
 
+      if LeapCli.leapfile.platform_branch && LeapCli::Util.is_git_directory?(Path.platform)
+        branch = LeapCli::Util.current_git_branch(Path.platform)
+        if branch != LeapCli.leapfile.platform_branch
+          bail! "Wrong branch for #{Path.platform}. Was '#{branch}', should be '#{LeapCli.leapfile.platform_branch}'. Edit Leapfile to disable this check."
+        end
+      end
+
       #
       # set log file
       #
index 56e887aed69bba3c222bc11b6ff7d1b220706aa8..3526d2373542e8173dc5a82c323da601f6f2f82f 100644 (file)
@@ -105,7 +105,7 @@ module LeapCli; module Commands
 
   def vagrant_setup
     assert_bin! 'vagrant', 'Vagrant is required for running local virtual machines. Run "sudo apt-get install vagrant".'
-    unless `vagrant gem which sahara`.chars.any?
+    unless assert_run!('vagrant gem which sahara').chars.any?
       log :installing, "vagrant plugin 'sahara'"
       assert_run! 'vagrant gem install sahara'
     end
index b5ce092ac66cc93b235d6d01977b96fc39ceda9f..cf4d127fa59e1f70e2e87dc61c98fd74bc43f7b6 100644 (file)
@@ -140,7 +140,7 @@ module LeapCli
       #
       def filter!(filters)
         node_list = filter(filters)
-        Util::assert! node_list.any?, "Could not match any nodes from '#{filters}'"
+        Util::assert! node_list.any?, "Could not match any nodes from '#{filters.join ' '}'"
         return node_list
       end
 
index c24f939e721b9973714372d6d70b4fadeb32580b..06db3b48348dcdca48864aa47ed622c79b00c873 100644 (file)
@@ -16,6 +16,8 @@ module LeapCli
     attr_accessor :leap_version
     attr_accessor :log
     attr_accessor :vagrant_network
+    attr_accessor :platform_branch
+    attr_accessor :allow_production_deploy
 
     def initialize
       @vagrant_network = '10.5.5.0/24'
@@ -26,10 +28,15 @@ module LeapCli
       if directory == '/'
         return nil
       else
-        self.provider_directory_path = directory
+        @provider_directory_path = directory
         read_settings(directory + '/Leapfile')
         read_settings(ENV['HOME'] + '/.leaprc')
-        self.platform_directory_path = File.expand_path(self.platform_directory_path || '../leap_platform', self.provider_directory_path)
+        @platform_directory_path = File.expand_path(@platform_directory_path || '../leap_platform', @provider_directory_path)
+        if @allow_production_deploy.nil?
+          # by default, only allow production deploys from 'master' or if not a git repo
+          @allow_production_deploy = !LeapCli::Util.is_git_directory?(@provider_directory_path) ||
+            LeapCli::Util.current_git_branch(@provider_directory_path) == 'master'
+        end
         return true
       end
     end
index 5bab424bed1f6b8602e0e91554b8a309ae1cde47..155796f03fe6a5def4c5987fd09cd99cb28aa70e 100644 (file)
@@ -74,7 +74,7 @@ module LeapCli
     #
     def assert_run!(cmd, message=nil)
       cmd = cmd + " 2>&1"
-      output = `#{cmd}`
+      output = `#{cmd}`.strip
       unless $?.success?
         exit_status($?.exitstatus)
         bail! do
@@ -363,6 +363,28 @@ module LeapCli
       ERB.new(string, nil, '%<>-').result(binding)
     end
 
+    ##
+    ## GIT
+    ##
+
+    def is_git_directory?(dir)
+      Dir.chdir(dir) do
+        `which git && git rev-parse 2>/dev/null`
+        return $? == 0
+      end
+    end
+
+    def current_git_branch(dir)
+      Dir.chdir(dir) do
+        branch = `git symbolic-ref HEAD 2>/dev/null`.strip
+        if branch.chars.any?
+          branch.sub /^refs\/heads\//, ''
+        else
+          nil
+        end
+      end
+    end
+
   end
 end