Method: RHC::Commands::App#create

Defined in:
lib/rhc/commands/app.rb

#create(name, cartridges) ⇒ Object

Raises:

  • (ArgumentError)


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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/rhc/commands/app.rb', line 64

def create(name, cartridges)
  check_config!

  check_name!(name)

  arg_envs, cartridges = cartridges.partition{|item| item.match(env_var_regex_pattern)}

  cartridges = check_cartridges(cartridges, &require_one_web_cart)

  options.default \
    :dns => true,
    :git => true

  raise ArgumentError, "You have named both your main application and your Jenkins application '#{name}'. In order to continue you'll need to specify a different name with --enable-jenkins or choose a different application name." if jenkins_app_name == name && enable_jenkins?

  rest_domain = check_domain!
  rest_app = nil
  repo_dir = nil

  cart_names = cartridges.collect do |c|
    c.usage_rate? ? "#{c.short_name} (addtl. costs may apply)" : c.short_name
  end.join(', ')

  env = collect_env_vars(arg_envs.concat(Array(options.env)))
  if env.present? && !rest_domain.supports_add_application_with_env_vars?
    env = []
    warn "Server does not support environment variables."
  end

  paragraph do
    header "Application Options"
    table([["Domain:", options.namespace],
           ["Cartridges:", cart_names],
          (["Source Code:", options.from_code] if options.from_code),
           ["Gear Size:", options.gear_size || "default"],
           ["Scaling:", options.scaling ? "yes" : "no"],
          (["Environment Variables:", env.map{|item| "#{item.name}=#{item.value}"}.join(', ')] if env.present?),
          ].compact
         ).each { |s| say "  #{s}" }
  end

  paragraph do
    say "Creating application '#{name}' ... "

    # create the main app
    rest_app = create_app(name, cartridges, rest_domain, options.gear_size, options.scaling, options.from_code, env, options.auto_deploy, options.keep_deployments, options.deployment_branch)
    success "done"

    paragraph{ indent{ success rest_app.messages.map(&:strip) } }
  end

  build_app_exists = rest_app.building_app

  if enable_jenkins?

    unless build_app_exists
      paragraph do
        say "Setting up a Jenkins application ... "

        begin
          build_app_exists = add_jenkins_app(rest_domain)

          success "done"
          paragraph{ indent{ success build_app_exists.messages.map(&:strip) } }

        rescue Exception => e
          warn "not complete"
          add_issue("Jenkins failed to install - #{e}",
                    "Installing jenkins and jenkins-client",
                    "pbox create-app jenkins",
                    "pbox add-cartridge jenkins-client -a #{rest_app.name}")
        end
      end
    end

    paragraph do
      messages = []
      add_jenkins_client_to(rest_app, messages)
      paragraph{ indent{ success messages.map(&:strip) } }
    end if build_app_exists
  end

  debug "Checking SSH keys through the wizard"
  check_sshkeys! unless options.no_keys

  if options.dns
    paragraph do
      say "Waiting for your DNS name to be available ... "
      if dns_propagated? rest_app.host
        success "done"
      else
        warn "failure"
        add_issue("We were unable to lookup your hostname (#{rest_app.host}) in a reasonable amount of time and can not clone your application.",
                  "Clone your git repo",
                  "pbox git-clone #{rest_app.name}")

        output_issues(rest_app)
        return 0
      end
    end

    if options.git
      section(:now => true, :top => 1, :bottom => 1) do
        begin
          repo_dir = git_clone_application(rest_app)
        rescue RHC::GitException => e
          warn "#{e}"
          unless RHC::Helpers.windows? and windows_nslookup_bug?(rest_app)
            add_issue("We were unable to clone your application's git repo - #{e}",
                      "Clone your git repo",
                      "pbox git-clone #{rest_app.name}")
          end
        end
      end
    end
  end

  output_issues(rest_app) if issues?

  paragraph do
    say "Your application '#{rest_app.name}' is now available."
    paragraph do
      indent do
        say table [
            ['URL:', rest_app.app_url],
            ['SSH to:', rest_app.ssh_string],
            ['Git remote:', rest_app.git_url],
            (['Cloned to:', repo_dir] if repo_dir)
          ].compact
      end
    end
  end
  paragraph{ say "Run 'pbox show-app #{name}' for more details about your app." }

  0
end