module Arfor::ControlRepo

Constants

CLEANUP_FILES
CLEAN_RUBY
UPSTREAM_EXAMPLE
VENDORED_FILES
WORKING_DIR

Public Class Methods

create() click to toggle source

create a new contorl repository in a directory ./puppet-control

# File lib/arfor/control_repo.rb, line 35
def self.create()
  if File.exists?(WORKING_DIR)
    abort("Puppet control repository already exists at #{WORKING_DIR}")
  else
    # Step 1 - git clone of upstream puppet control repository
    system("git clone #{UPSTREAM_EXAMPLE} #{WORKING_DIR}")

    # Step 2 - crud cleanup
    CLEANUP_FILES.each { |f|
      # swallow errors relating to files that are no longer in upstream
      begin
        File.delete(f)
      rescue
      end
    }
    # ...And remove upstream git repo - not needed
    FileUtils.rm_rf(File.join(WORKING_DIR, '.git'))

    # Step 3 - Copy in files
    dir = File.join(File.dirname(File.expand_path(__FILE__)), VENDORED_FILES)
    FileUtils.cp_r(dir, WORKING_DIR)

    # Step 4 - Install onceover
    Dir.chdir(WORKING_DIR) {
      system("#{CLEAN_RUBY} bundle install")
      system("#{CLEAN_RUBY} bundle exec onceover init")

      # Step 5 - setup git
      system("git init")
      system("git checkout -b production")

      # Step 6 - initial git commit
      system("git add -A")
      system("git commit -m 'initial' ")
    }
  end
end