Sha256: 7a854e82d0039fdc0b67ac085a701826dc03d1f93dd9339ac4daee3e72af583a

Contents?: true

Size: 1.92 KB

Versions: 6

Compression:

Stored size: 1.92 KB

Contents

require 'fileutils'
require 'stringio'
require 'bib/opsworks/logging'

module Bib
  module Opsworks
    class Composer
      include Logging

      def copy_vendor(release_path, deploy_user)
        app_current = ::File.expand_path("#{release_path}/../../current")
        vendor_dir  = "#{app_current}/vendor"

        deploy_username  = deploy_user['user']
        deploy_group     = deploy_user['group']

        release_vendor = "#{release_path}/vendor"

        if ::File.exist?(release_vendor)
          log.info('Not copying vendor dir, there already is one in the target path')
          return
        end

        copy_vendordir(release_vendor, vendor_dir)
        chown_vendordir(release_vendor, deploy_username, deploy_group)
      end

      def copy_vendordir(release_vendor, vendor_dir)
        if ::File.exist?(vendor_dir)
          fileutils_output = StringIO.new
          ::FileUtils.fileutils_output = fileutils_output
          log.debug("Copy Vendor: Copying from #{vendor_dir} to #{release_vendor}")
          ::FileUtils.cp_r vendor_dir, release_vendor, verbose: true
          log.debug(fileutils_output.string)
        else
          log.info("Vendor dir #{vendor_dir} does not exist")
        end
      end

      def chown_vendordir(release_vendor, deploy_username, deploy_group)
        if ::File.exist?(release_vendor)
          fileutils_output = StringIO.new
          ::FileUtils.fileutils_output = fileutils_output
          log.debug("Chown Vendor #{release_vendor} to #{deploy_username}.#{deploy_group}")
          ::FileUtils.fileutils_output = fileutils_output
          result = ::FileUtils.chown_R deploy_username, deploy_group, release_vendor, verbose: true
          log.debug(fileutils_output.string)
        else
          log.info("Release vendor dir #{release_vendor} does not exist")
        end
        result
      end
    end
  end
end

module FileUtils
  class << self
    attr_writer :fileutils_output
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
BibOpsworks-0.2.0 lib/bib/opsworks/composer.rb
BibOpsworks-0.1.8 lib/bib/opsworks/composer.rb
BibOpsworks-0.1.7 lib/bib/opsworks/composer.rb
BibOpsworks-0.1.6 lib/bib/opsworks/composer.rb
BibOpsworks-0.1.5 lib/bib/opsworks/composer.rb
BibOpsworks-0.1.4 lib/bib/opsworks/composer.rb