Class: AmoebaDeployTools::Amoeba

Inherits:
Command
  • Object
show all
Defined in:
lib/amoeba_deploy_tools/commands/amoeba.rb

Instance Method Summary collapse

Methods included from Concerns::Hooks

included, #invoke_command

Constructor Details

#initialize(args = [], options = {}, config = {}) ⇒ Amoeba

Any “global” setup can be done here, as the “amoeba” command will always be initialized



8
9
10
11
12
13
14
15
16
# File 'lib/amoeba_deploy_tools/commands/amoeba.rb', line 8

def initialize(args=[], options={}, config={})
  super
  setup_logger
  setup_cocaine

  # Fix JSON so it doesn't try to dereference json_class in JSON responses
  # See http://blog.defunct.ca/2013/02/01/query-chef-server-api-from-ruby-script/
  JSON.create_id = ''
end

Instance Method Details

#init(url = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/amoeba_deploy_tools/commands/amoeba.rb', line 20

def init(url=nil)
  # Store the user-specified URL if it exists
  user_url = url if url

  # Check if we're in a git repo
  if system('git rev-parse > /dev/null 2>&1')
    project_dir = %x{git rev-parse --show-toplevel}

    default_kitchen_dir = File.expand_path("#{File.basename(project_dir).chop}-kitchen",
                                   File.expand_path('..', project_dir))
  else
    default_kitchen_dir = File.expand_path('.', 'kitchen')
  end

  kitchen_dir = ask "Where should the new kitchen be located? (default: #{default_kitchen_dir})"
  kitchen_dir = default_kitchen_dir if kitchen_dir.empty?

  if File.exist?(kitchen_dir)
    say 'Existing kitchen found! Will not overwrite.', :yellow
  else
    # Copy (not clone) the repo if the URL isn't specified. If it is, obey the --skeleton param
    copy = url ? options[:skeleton] : true

    # If there was no specified URL, use default one
    url ||= DEFAULT_SKELETON_REPO

    git_opts = copy ?  '--depth 1' : ''
    if system("git clone #{git_opts} #{url} #{kitchen_dir}")
      if copy
        git_dir = File.expand_path('.git', kitchen_dir)
        if File.directory?(git_dir)
          FileUtils.rm_rf(git_dir)
        end
        say_bold "New kitchen created at: #{kitchen_dir}. Please add it to version control"
      else
        say_bold "Kitchen from #{url} has been 'git clone'-ed into your kitchen directory"
      end
    else
      say_fatal "ERROR: Kitchen directory cannot be cloned from URL #{url}"
    end
  end

  # Okay, the kitchen exists (one way or another)

  config.kitchen!.url  = user_url if user_url && !options[:skeleton]
  config.kitchen!.path = kitchen_dir.to_s
  config.save

  say_bold 'Saving ./amoeba.yml config file. We suggest you `git ignore` this (contains local settings).'
end

#syncObject



72
73
# File 'lib/amoeba_deploy_tools/commands/amoeba.rb', line 72

def sync
end

#updateObject



76
77
# File 'lib/amoeba_deploy_tools/commands/amoeba.rb', line 76

def update
end