Class: SimpleDeploy::CLI::Deploy

Inherits:
Object
  • Object
show all
Includes:
Shared
Defined in:
lib/simple_deploy/cli/deploy.rb

Instance Method Summary collapse

Methods included from Shared

#command_name, #parse_attributes, #rescue_exceptions_and_exit, #valid_options?

Instance Method Details

#command_summaryObject



105
106
107
# File 'lib/simple_deploy/cli/deploy.rb', line 105

def command_summary
  'Execute deployment on given stack(s)'
end

#deployObject



9
10
11
12
13
14
15
16
17
18
19
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/simple_deploy/cli/deploy.rb', line 9

def deploy
  @opts = Trollop::options do
    version SimpleDeploy::VERSION
    banner <<-EOS

Execute deployment on given stack(s).

simple_deploy deploy -n STACK_NAME -n STACK_NAME -e ENVIRONMENT

Using SSH:

Simple deploy defaults your user and key for SSH to your username and your id_rsa key.

If you need to override these because you want to use a different username or you have a different key file,
you can set simple deploy specific environment variables to do the override.

Example 1: Overriding when the command is run.
SIMPLE_DEPLOY_SSH_USER=fred SIMPLE_DEPLOY_SSH_KEY=$HOME/.ssh/id_dsa simple_deploy deploy -n STACK_NAME -n STACK_NAME -e ENVIRONMENT

Example 2: Overriding them in your shell environment (bash shell used in the example).
export SIMPLE_DEPLOY_SSH_USER=fred
export SIMPLE_DEPLOY_SSH_KEY=$HOME/.ssh/id_dsa
simple_deploy deploy -n STACK_NAME -n STACK_NAME -e ENVIRONMENT

Using Internal / External IP for SSH:

simple_deploy defaults to using the public IP when ssh'ng to stacks in classic, or the private IP when in a VPC.

The internal or external flag forces simple_deploy to use the given IP address.

simple_deploy deploy -n STACK_NAME -n STACK_NAME -e ENVIRONMENT -i

EOS
    opt :help, "Display Help"
    opt :attributes, "= seperated attribute and it's value", :type  => :string,
                                                             :multi => true
    opt :environment, "Set the target environment", :type => :string
    opt :force, "Force a deployment to proceed"
    opt :log_level, "Log level:  debug, info, warn, error", :type    => :string,
                                                            :default => 'info'
    opt :name, "Stack name(s) of stack to deploy", :type => :string,
                                                   :multi => true
    opt :quiet, "Quiet, do not send notifications"
    opt :read_from_env, "Read credentials and region from environment variables"
    opt :external, "Use external IP for ssh commands"
    opt :internal, "Use internal IP for ssh commands"
  end

  valid_options? :provided => @opts,
                 :required => [:environment, :name, :read_from_env]

  config_arg = @opts[:read_from_env] ? :read_from_env : @opts[:environment]
  SimpleDeploy.create_config config_arg
  logger = SimpleDeploy.logger @opts[:log_level]

  new_attributes = parse_attributes :attributes => @opts[:attributes]

  @opts[:name].each do |name|
    notifier = Notifier.new :stack_name  => name,
                            :environment => @opts[:environment]

   stack = Stack.new :name        => name,
                     :environment => @opts[:environment],
                     :external    => @opts[:external],
                     :internal    => @opts[:internal]

    proceed = true

    if new_attributes.any?
      rescue_exceptions_and_exit do
        proceed = stack.update :force      => @opts[:force], 
                               :attributes => new_attributes
      end
    end

    stack.wait_for_stable

    if proceed
      notifier.send_deployment_start_message unless @opts[:quiet]

      result = stack.deploy @opts[:force]

      if result
        notifier.send_deployment_complete_message unless @opts[:quiet]
      else
        logger.error "Deployment to #{name} did not complete successfully."
        exit 1
      end
    else
      logger.error "Update of #{name} did not complete successfully."
      exit 1
    end

  end
end