Class: AvstCloud::CapistranoDeploymentTask

Inherits:
Task
  • Object
show all
Includes:
Logging
Defined in:
lib/avst-cloud/task.rb

Instance Method Summary collapse

Methods included from Logging

included, #logger, #logger=

Constructor Details

#initialize(git, branch, server_tmp_folder = "/tmp/avst_cloud_tmp_#{Time.now.to_i}", reference = nil, custom_provisioning_commands = [], puppet_runner = nil, puppet_runner_prepare = nil, destination_folder = '/var/opt/puppet') ⇒ CapistranoDeploymentTask

Returns a new instance of CapistranoDeploymentTask.



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/avst-cloud/task.rb', line 167

def initialize(git, branch, server_tmp_folder = "/tmp/avst_cloud_tmp_#{Time.now.to_i}", reference = nil, custom_provisioning_commands = [], puppet_runner = nil, puppet_runner_prepare = nil, destination_folder = '/var/opt/puppet')
    unless git and (branch or reference)
        logger.debug "You have to provide git repo url #{git} and git branch #{branch} or git tag reference #{reference}".red
        raise "You have to provide git repo url #{git} and git branch #{branch} or git tag reference #{reference}"
    end

    @git = git
    @branch = branch
    @server_tmp_folder = server_tmp_folder
    @reference = reference
    @custom_provisioning_commands = custom_provisioning_commands || []
    @puppet_runner = puppet_runner
    @puppet_runner_prepare = puppet_runner_prepare
    @destination_folder = destination_folder || '/var/opt/puppet'
end

Instance Method Details

#execute(server) ⇒ Object



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/avst-cloud/task.rb', line 183

def execute(server)
    unless server.ip_address
        logger.error 'Can not find host'.red
        raise 'Can not find ip address, access_user or access_password'
    end

    unless server.access_user
        logger.error 'Access user not found. Please provide username for this server.'.red
        raise 'Access user not found. Please provide username for this server.'
    end

    unless server.access_password
        logger.error 'Password not found. Please provide password or pem key for this server.'.red
        raise 'Password not found. Please provide root_password in config. for this server.'
    end

    logger.debug "Using #{server.access_user}@#{server.ip_address} with #{server.access_password}"


    # Initiate capistrano deploy script to download the laters code and provision the server
    require 'capistrano/all'
    require 'capistrano/setup'
    require 'capistrano/deploy'
    Dir.glob("#{File.dirname __dir__}/capistrano/tasks/*.rake").each { |r| load r }
    # cap production deploy
    ENV['cap_git_repo_url'] = @git
    ENV['cap_branch_name'] = @branch
    ENV['cap_reference_name'] = @reference
    ENV['cap_ip_address'] = server.ip_address
    ENV['cap_access_password'] = server.access_password
    ENV['cap_access_user'] = server.access_user
    ENV['server_name'] = server.server_name
    ENV['puppet_runner'] = @puppet_runner
    ENV['puppet_runner_prepare'] = @puppet_runner_prepare
    ENV['avst_cloud_tmp_folder'] = @server_tmp_folder
    ENV['custom_provisioning_commands'] = @custom_provisioning_commands.to_json
    ENV['destination_folder'] = @destination_folder
    logger.debug "Using git #{@git} branch #{@branch} to provision #{server.ip_address}"

    Capistrano::Application.invoke('production')
    Capistrano::Application.invoke('deploy')
    logger.debug "You can connect to server on #{server.ip_address}"
end