Class: Konstant::Builder
- Inherits:
-
Object
- Object
- Konstant::Builder
- Defined in:
- lib/konstant/builder.rb
Instance Attribute Summary collapse
-
#new_build ⇒ Object
readonly
Returns the value of attribute new_build.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Instance Method Summary collapse
- #build ⇒ Object
- #build_status ⇒ Object
- #build_stderr ⇒ Object
- #build_stdout ⇒ Object
- #cleanup ⇒ Object
- #cleanup_old_builds ⇒ Object
- #deploy ⇒ Object
-
#initialize(project) ⇒ Builder
constructor
A new instance of Builder.
- #notify(message) ⇒ Object
- #previous_build_failed? ⇒ Boolean
- #run ⇒ Object
- #symlink ⇒ Object
Constructor Details
#initialize(project) ⇒ Builder
Returns a new instance of Builder.
3 4 5 6 7 |
# File 'lib/konstant/builder.rb', line 3 def initialize(project) @project = project = Time.now.strftime("%Y%m%d%H%M%S") @new_build = Konstant::Build.new project, end |
Instance Attribute Details
#new_build ⇒ Object (readonly)
Returns the value of attribute new_build.
9 10 11 |
# File 'lib/konstant/builder.rb', line 9 def new_build @new_build end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
9 10 11 |
# File 'lib/konstant/builder.rb', line 9 def project @project end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
9 10 11 |
# File 'lib/konstant/builder.rb', line 9 def end |
Instance Method Details
#build ⇒ Object
44 45 46 |
# File 'lib/konstant/builder.rb', line 44 def build Konstant::Runner.new(new_build, "build").run end |
#build_status ⇒ Object
92 93 94 |
# File 'lib/konstant/builder.rb', line 92 def build_status new_build.status end |
#build_stderr ⇒ Object
100 101 102 |
# File 'lib/konstant/builder.rb', line 100 def build_stderr new_build.stderr end |
#build_stdout ⇒ Object
96 97 98 |
# File 'lib/konstant/builder.rb', line 96 def build_stdout new_build.stdout end |
#cleanup ⇒ Object
52 53 54 |
# File 'lib/konstant/builder.rb', line 52 def cleanup Konstant::Runner.new(new_build, "cleanup").run end |
#cleanup_old_builds ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/konstant/builder.rb', line 56 def cleanup_old_builds builds = project.builds limit = Konstant.config["builds_to_keep"] if builds.size > limit Konstant.logger.info "removing #{builds.size - limit} build(s) from project '#{project.id}'" builds[limit..-1].each do |build| build.destroy end end end |
#deploy ⇒ Object
48 49 50 |
# File 'lib/konstant/builder.rb', line 48 def deploy Konstant::Runner.new(new_build, "deploy").run end |
#notify(message) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/konstant/builder.rb', line 72 def notify() unless Konstant.config["notify"].empty? Mail.deliver do from Konstant.config["mail_sender"] to Konstant.config["notify"] case when :failure subject "Konstant: Project failed: #{project.id}" when :recovery subject "Konstant: Project recovered: #{project.id}" when :cleanup_failed subject "Konstant: Project could not be cleaned up: #{project.id}" when :deploy_failed subject "Konstant: Project could not be deployed: #{project.id}" end end end end |
#previous_build_failed? ⇒ Boolean
104 105 106 |
# File 'lib/konstant/builder.rb', line 104 def previous_build_failed? new_build.previous ? new_build.previous.failure? : false end |
#run ⇒ Object
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 |
# File 'lib/konstant/builder.rb', line 11 def run Konstant.logger.info "building project '#{project.id}'" if build if previous_build_failed? Konstant.logger.info "project '#{project.id}' recovered" notify :recovery else Konstant.logger.info "project '#{project.id}' built successfully" end Konstant.logger.info "deploying project '#{project.id}'" unless deploy notify :deploy_failed end Konstant.logger.info "project '#{project.id}' deployed" else Konstant.logger.info "project '#{project.id}' failed to build" notify :failure end Konstant.logger.info "cleaning up project '#{project.id}'" unless cleanup notify :cleanup_failed end Konstant.logger.info "project '#{project.id}' cleaned up" symlink Konstant.logger.info "finished building project '#{project.id}'" cleanup_old_builds end |
#symlink ⇒ Object
68 69 70 |
# File 'lib/konstant/builder.rb', line 68 def symlink system "ln -sfn #{new_build.path} #{project.path}/current" end |