Class: Shipwright::Builder
- Inherits:
-
Object
- Object
- Shipwright::Builder
- Defined in:
- lib/shipwright/builder.rb
Constant Summary collapse
- BASE_VERSION =
'1.0.0'- VERSION_FILE =
'VERSION'- DOCKERRUN =
'Dockerrun.aws.json'- COMMIT_MESSAGE =
"new version %s built by Shipwright #{Shipwright::VERSION}\n [ci skip]"
Instance Attribute Summary collapse
-
#commit_message ⇒ Object
Returns the value of attribute commit_message.
-
#path ⇒ Object
Returns the value of attribute path.
-
#previous_version ⇒ Object
Returns the value of attribute previous_version.
-
#shipyard ⇒ Object
Returns the value of attribute shipyard.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
- .application ⇒ Object
- .build(path, shipyard = nil) ⇒ Object
- .bump ⇒ Object
- .init ⇒ Object
- .version ⇒ Object
Instance Method Summary collapse
- #application ⇒ Object
- #build ⇒ Object
- #build_image ⇒ Object
- #bump_version ⇒ Object
- #docker_tag ⇒ Object
- #generate_artifact ⇒ Object
- #git_commit ⇒ Object
- #git_push ⇒ Object
- #git_tag ⇒ Object
-
#initialize(path) ⇒ Builder
constructor
A new instance of Builder.
- #push_image ⇒ Object
- #run_cmd(cmd) ⇒ Object
- #update_dockerrun ⇒ Object
- #update_ebconfig ⇒ Object
Constructor Details
#initialize(path) ⇒ Builder
Returns a new instance of Builder.
36 37 38 |
# File 'lib/shipwright/builder.rb', line 36 def initialize(path) self.path = path end |
Instance Attribute Details
#commit_message ⇒ Object
Returns the value of attribute commit_message.
10 11 12 |
# File 'lib/shipwright/builder.rb', line 10 def @commit_message end |
#path ⇒ Object
Returns the value of attribute path.
10 11 12 |
# File 'lib/shipwright/builder.rb', line 10 def path @path end |
#previous_version ⇒ Object
Returns the value of attribute previous_version.
10 11 12 |
# File 'lib/shipwright/builder.rb', line 10 def previous_version @previous_version end |
#shipyard ⇒ Object
Returns the value of attribute shipyard.
10 11 12 |
# File 'lib/shipwright/builder.rb', line 10 def shipyard @shipyard end |
#version ⇒ Object
Returns the value of attribute version.
10 11 12 |
# File 'lib/shipwright/builder.rb', line 10 def version @version end |
Class Method Details
.application ⇒ Object
32 33 34 |
# File 'lib/shipwright/builder.rb', line 32 def self.application File.basename Dir.pwd end |
.build(path, shipyard = nil) ⇒ Object
12 13 14 |
# File 'lib/shipwright/builder.rb', line 12 def self.build(path, shipyard = nil) new(path).tap { |b| b.shipyard = shipyard }.build end |
.bump ⇒ Object
16 17 18 19 |
# File 'lib/shipwright/builder.rb', line 16 def self.bump Bump::Bump.run('patch', bundle: false, tag: false) Shipwright.info "Installed #{version} into #{VERSION_FILE}" end |
.init ⇒ Object
21 22 23 24 25 26 |
# File 'lib/shipwright/builder.rb', line 21 def self.init return if version Shipwright.info "Installing #{BASE_VERSION} into #{VERSION_FILE}" File.open(VERSION_FILE, 'wb') { |f| f.write BASE_VERSION } end |
.version ⇒ Object
28 29 30 |
# File 'lib/shipwright/builder.rb', line 28 def self.version Bump::Bump.version_from_version.tap { |v| return v.first if v } end |
Instance Method Details
#application ⇒ Object
131 132 133 |
# File 'lib/shipwright/builder.rb', line 131 def application @application ||= self.class.application end |
#build ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/shipwright/builder.rb', line 40 def build shipyard self.class.init Shipwright.info "Shipwright is building #{path} (at #{self.class.version})" bump_version build_image push_image update_dockerrun generate_artifact update_ebconfig git_commit git_push Shipwright.info "VERSION #{version} built" end |
#build_image ⇒ Object
64 65 66 67 68 |
# File 'lib/shipwright/builder.rb', line 64 def build_image Shipwright.info "Building image with tag #{docker_tag}" run_cmd "docker build -t #{docker_tag} #{path}" # self.image = Docker::Image.build_from_dir(path, 'tag' => docker_tag) end |
#bump_version ⇒ Object
60 61 62 |
# File 'lib/shipwright/builder.rb', line 60 def bump_version self.class.bump end |
#docker_tag ⇒ Object
117 118 119 |
# File 'lib/shipwright/builder.rb', line 117 def docker_tag "#{shipyard}/#{application}:#{version}" end |
#generate_artifact ⇒ Object
91 92 93 94 |
# File 'lib/shipwright/builder.rb', line 91 def generate_artifact Shipwright.info "Generating artifact" Shipwright::ElasticBeanstalk.generate_artifact end |
#git_commit ⇒ Object
101 102 103 104 105 106 |
# File 'lib/shipwright/builder.rb', line 101 def git_commit Shipwright.info "Commiting to git" git.add all: true git.commit COMMIT_MESSAGE % version git.add_tag git_tag end |
#git_push ⇒ Object
108 109 110 111 |
# File 'lib/shipwright/builder.rb', line 108 def git_push Shipwright.info "Pushing to git" git.push 'origin', git.current_branch, tags: true end |
#git_tag ⇒ Object
113 114 115 |
# File 'lib/shipwright/builder.rb', line 113 def git_tag "build-#{version}" end |
#push_image ⇒ Object
70 71 72 73 74 |
# File 'lib/shipwright/builder.rb', line 70 def push_image Shipwright.info "Pushing image to #{docker_tag}" run_cmd "docker push #{docker_tag}" # image.push end |
#run_cmd(cmd) ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/shipwright/builder.rb', line 76 def run_cmd(cmd) io = IO.popen(cmd) io.each { |line| Shipwright.info line.chomp } io.close unless $?.exitstatus.zero? puts "Command #{cmd} exitted with non zero status #{$?.exitstatus}" exit $?.exitstatus end end |
#update_dockerrun ⇒ Object
86 87 88 89 |
# File 'lib/shipwright/builder.rb', line 86 def update_dockerrun Shipwright.info "Updating Dockerrun.aws.json" Shipwright::ElasticBeanstalk.update_dockerrun end |
#update_ebconfig ⇒ Object
96 97 98 99 |
# File 'lib/shipwright/builder.rb', line 96 def update_ebconfig Shipwright.info "Updating .elasticbeanstalk/config.yml" Shipwright::ElasticBeanstalk.update_ebconfig end |