]> gitweb.fluxo.info Git - leap/leap_cli.git/commitdiff
added support for custom-puppet
authorelijah <elijah@riseup.net>
Tue, 21 Oct 2014 09:18:23 +0000 (02:18 -0700)
committerelijah <elijah@riseup.net>
Tue, 21 Oct 2014 09:18:23 +0000 (02:18 -0700)
lib/leap_cli/commands/deploy.rb
lib/leap_cli/constants.rb
lib/leap_cli/version.rb

index 54c2bdb9bb36731520884edb6cfb9827a55abab4..75ac9778dd843197b05ecb0f5066de9c1a1ace0a 100644 (file)
@@ -171,7 +171,13 @@ module LeapCli
       end
     end
 
+    #
+    # sync various support files.
+    # TODO: move everything into /srv/leap instead of /etc/leap
+    #
     def sync_support_files(ssh)
+      # sync files to /etc/leap
+      # TODO: remove this
       dest_dir = provider.hiera_sync_destination
       ssh.rsync.update do |server|
         node = manager.node(server.host)
@@ -190,6 +196,37 @@ module LeapCli
           nil
         end
       end
+
+      # sync files to /srv/leap/files
+      dest_dir = File.join(LeapCli::PUPPET_DESTINATION, "files")
+      source_files = []
+      if file_exists?(:custom_puppet_dir)
+        source_files += [:custom_puppet_dir, :custom_puppet_modules_dir, :custom_puppet_manifests_dir].collect{|path|
+          Path.relative_path(path, Path.provider) + '/' # rsync needs trailing slash
+        }
+        if !file_exists?(:custom_puppet_site)
+          write_file!(:custom_puppet_site, "# custom puppet configuration" + "\n" + "tag 'leap_base'" + "\n")
+        end
+        ensure_dir :custom_puppet_modules_dir
+      end
+      ssh.rsync.update do |server|
+        node = manager.node(server.host)
+        files_to_sync = node.file_paths.collect {|path| Path.relative_path(path, Path.provider) }
+        files_to_sync += source_files
+        if files_to_sync.any?
+          ssh.leap.log(files_to_sync.join(', ') + ' -> ' + node.name + ':' + dest_dir)
+          {
+            :chdir => Path.named_path(:files_dir),
+            :source => ".",
+            :dest => dest_dir,
+            :excludes => "*",
+            :includes => calculate_includes_from_files(files_to_sync, '/files'),
+            :flags => "-rltp --chmod=u+rX,go-rwx --relative --delete --delete-excluded --copy-links"
+          }
+        else
+          nil
+        end
+      end
     end
 
     def sync_puppet_files(ssh)
@@ -204,21 +241,6 @@ module LeapCli
           :flags => "-rlt --relative --delete --copy-links"
         }
       end
-      ssh.rsync.update do |server|
-        custom_site = Path.provider + LeapCli::CUSTOM_PUPPET_SITE
-        custom_modules = Path.provider + LeapCli::CUSTOM_PUPPET_MODULES
-        if !file_exists?(custom_site)
-          write_file!(custom_site, "# custom puppet configuration" + "\n" + "tag 'leap_base'" + "\n")
-        end
-        ensure_dir custom_modules
-        ssh.leap.log(Path.provider + LeapCli::CUSTOM_PUPPET_SOURCE + ' -> ' + server.host + ':' + LeapCli::CUSTOM_PUPPET_DESTINATION)
-        {
-          :dest => LeapCli::CUSTOM_PUPPET_DESTINATION,
-          :source => Path.provider + LeapCli::CUSTOM_PUPPET_SOURCE,
-          :chdir => Path.platform,
-          :flags => "-rlt --delete --copy-links"
-        }
-      end
     end
 
     #
@@ -240,11 +262,17 @@ module LeapCli
       end
     end
 
-    def calculate_includes_from_files(files)
+    #
+    # converts an array of file paths into an array
+    # suitable for --include of rsync
+    #
+    # if set, `prefix` is stripped off.
+    #
+    def calculate_includes_from_files(files, prefix=nil)
       return nil unless files and files.any?
 
       # prepend '/' (kind of like ^ for rsync)
-      includes = files.collect {|file| '/' + file}
+      includes = files.collect {|file| file =~ /^\// ? file : '/' + file }
 
       # include all sub files of specified directories
       includes.size.times do |i|
@@ -262,6 +290,10 @@ module LeapCli
         end
       end
 
+      if prefix
+        includes.map! {|path| path.sub(/^#{Regexp.escape(prefix)}/, '')}
+      end
+
       return includes
     end
 
index dcb66bea46bf66b3883959d6b31cc64cbc5b22cd..5abe6302ef5b70f32f4a0b1347d3aa5784f77492 100644 (file)
@@ -2,9 +2,6 @@ module LeapCli
 
   PUPPET_DESTINATION = '/srv/leap'
   CUSTOM_PUPPET_DESTINATION = '/srv/leap/custom-puppet'
-  CUSTOM_PUPPET_SOURCE = '/files/custom-puppet/'
-  CUSTOM_PUPPET_SITE = "#{CUSTOM_PUPPET_SOURCE}/manifests/site.pp"
-  CUSTOM_PUPPET_MODULES = "#{CUSTOM_PUPPET_SOURCE}/modules"
   INITIALIZED_FILE = "#{PUPPET_DESTINATION}/initialized"
   DEFAULT_TAGS = ['leap_base','leap_service']
 
index 019e267eaee7b97969d482ff9ffd1ea6c5145aa7..62819dee83a85aa9424a37efe64a0bbeca610216 100644 (file)
@@ -1,7 +1,7 @@
 module LeapCli
   unless defined?(LeapCli::VERSION)
     VERSION = '1.5.9'
-    COMPATIBLE_PLATFORM_VERSION = '0.5.3'..'1.99'
+    COMPATIBLE_PLATFORM_VERSION = '0.5.5'..'1.99'
     SUMMARY = 'Command line interface to the LEAP platform'
     DESCRIPTION = 'The command "leap" can be used to manage a bevy of servers running the LEAP platform from the comfort of your own home.'
     LOAD_PATHS = ['lib', 'vendor/certificate_authority/lib', 'vendor/rsync_command/lib']