Module: Capistrano::Isitdeployed

Defined in:
lib/capistrano/isitdeployed.rb,
lib/capistrano/isitdeployed/debug.rb,
lib/capistrano/isitdeployed/config.rb,
lib/capistrano/isitdeployed/version.rb

Defined Under Namespace

Modules: Debug

Constant Summary collapse

ENDPOINT =
'http://www.isitdeployed.com'
VERSION =
"0.1.3"

Class Method Summary collapse

Class Method Details

.load_into(configuration) ⇒ Object



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
# File 'lib/capistrano/isitdeployed.rb', line 19

def self.load_into(configuration)
  configuration.load do

    # task hooks
    before 'deploy',               'isit:deploy'
    after  'deploy',               'isit:status:success'
    after  'deploy:rollback',      'isit:status:rollback'
    after  'isit:status:success',  'isit:update'
    after  'isit:status:rollback', 'isit:update'

    # task definitions
    namespace :isit do

      desc "Creates a new deploy using the API"
      task :deploy do
        started = Capistrano::Isitdeployed.timestamp
        set(:stage, "my platform") unless exists?(:stage)
        RestClient.post(ENDPOINT + "/p/#{isitdeployed_project_id}/d", JSON.generate({ :status => 1, :platform => "#{stage}", :release => "#{release_name}", :started => started, :token => isitdeployed_api_secret, :version => VERSION }), :content_type => :json, :accept => :json, :timeout => 5, :open_timeout => 5){ |response, request, result| response
          case response.code
          when 201
            logger.trace "IsItDeployed > New deploy created for #{application} to #{stage} with version: #{release_name}"
            logger.trace "IsItDeployed > URL is #{ENDPOINT}/p/#{isitdeployed_project_id}"
            json = JSON.parse(response)
            if json['latest_version'] > VERSION
              logger.trace "IsItDeployed > WARNING: Your 'capistrano-isitdeployed' gem is outdated. Consider upgrade to #{json['latest_version']}"                  
            end
            set(:isitdeployed_did,     json['deploy_id'])
            set(:isitdeployed_started, started)
            set(:isitdeployed_created, 1)
          when 401
            logger.trace "IsItDeployed > ERROR: Invalid 'isitdeployed_api_secret'. Check your 'deploy.rb' file"                
            set(:isitdeployed_created, 0)
          when 404
            logger.trace "IsItDeployed > ERROR: Invalid 'isitdeployed_project_id'. Check your 'deploy.rb' file"                
            set(:isitdeployed_created, 0)
          else
            logger.trace "IsItDeployed > ERROR: Can't create deploy, server returned code #{response.code}"
            set(:isitdeployed_created, 0)
          end
        }
      end

      namespace :status do
        desc "Set the deploy status to success locally"
        task :success do
          set(:isitdeployed_status, 2)
        end

        desc "Set the deploy status to rollback locally"
        task :rollback do
          set(:isitdeployed_status, 3)
        end
      end

      desc "Updates deploy status using the API (success or rollback)"
        task :update do
        if isitdeployed_created === 1
          stopped   = Capistrano::Isitdeployed.timestamp
          duration  = stopped.to_i - isitdeployed_started.to_i
          RestClient.put(ENDPOINT + "/p/#{isitdeployed_project_id}/d/#{isitdeployed_did}", JSON.generate({ :status => isitdeployed_status, :stopped => stopped, :duration => duration, :token => isitdeployed_api_secret }), :content_type => :json, :accept => :json, :timeout => 5, :open_timeout => 5){ |response, request, result| response
            case response.code
            when 204
              logger.trace "IsItDeployed > Deploy ##{isitdeployed_did} has been updated for #{application} to #{stage}."
            when 401
              logger.trace "IsItDeployed > ERROR: Invalid 'isitdeployed_api_secret'. Check your 'deploy.rb' file"                
            when 404
              logger.trace "IsItDeployed > ERROR: Invalid 'isitdeployed_project_id'. Check your 'deploy.rb' file"                
            else
              logger.trace "IsItDeployed > ERROR: Can't create deploy, server returned #{response.code}"
            end
          }                      
        end
      end
    end
  end
end

.load_user_configObject



15
16
17
# File 'lib/capistrano/isitdeployed.rb', line 15

def self.load_user_config
  return YAML.load_file(CONFIG_DEST)      
end

.timestampObject



11
12
13
# File 'lib/capistrano/isitdeployed.rb', line 11

def self.timestamp
  return Time.now.utc.strftime("%Y%m%d%H%M%S")        
end