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.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
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
- #shipyard ⇒ Object
- #update_dockerrun ⇒ Object
- #update_ebconfig ⇒ Object
Constructor Details
#initialize(path) ⇒ Builder
Returns a new instance of Builder.
32 33 34 35 |
# File 'lib/shipwright/builder.rb', line 32 def initialize(path) self.path = path shipyard 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 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 |
#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
.build(path) ⇒ Object
12 13 14 |
# File 'lib/shipwright/builder.rb', line 12 def self.build(path) new(path).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
119 120 121 |
# File 'lib/shipwright/builder.rb', line 119 def application File.basename Dir.pwd end |
#build ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/shipwright/builder.rb', line 37 def build 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
60 61 62 63 64 |
# File 'lib/shipwright/builder.rb', line 60 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
56 57 58 |
# File 'lib/shipwright/builder.rb', line 56 def bump_version self.class.bump end |
#docker_tag ⇒ Object
107 108 109 |
# File 'lib/shipwright/builder.rb', line 107 def docker_tag "#{shipyard}/#{application}:#{version}" end |
#generate_artifact ⇒ Object
81 82 83 84 |
# File 'lib/shipwright/builder.rb', line 81 def generate_artifact Shipwright.info "Generating artifact" Shipwright::ElasticBeanstalk.generate_artifact end |
#git_commit ⇒ Object
91 92 93 94 95 96 |
# File 'lib/shipwright/builder.rb', line 91 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
98 99 100 101 |
# File 'lib/shipwright/builder.rb', line 98 def git_push Shipwright.info "Pushing to git" git.push 'origin', git.current_branch, tags: true end |
#git_tag ⇒ Object
103 104 105 |
# File 'lib/shipwright/builder.rb', line 103 def git_tag "build-#{version}" end |
#push_image ⇒ Object
66 67 68 69 70 |
# File 'lib/shipwright/builder.rb', line 66 def push_image Shipwright.info "Pushing image to #{docker_tag}" run_cmd "docker push #{docker_tag}" # image.push end |
#run_cmd(cmd) ⇒ Object
72 73 74 |
# File 'lib/shipwright/builder.rb', line 72 def run_cmd(cmd) IO.popen(cmd).each { |line| Shipwright.info line.chomp } end |
#shipyard ⇒ Object
115 116 117 |
# File 'lib/shipwright/builder.rb', line 115 def shipyard ENV.fetch('SHIPYARD') { raise "set SHIPYARD= to your docker host/scope" } end |
#update_dockerrun ⇒ Object
76 77 78 79 |
# File 'lib/shipwright/builder.rb', line 76 def update_dockerrun Shipwright.info "Updating Dockerrun.aws.json" Shipwright::ElasticBeanstalk.update_dockerrun end |
#update_ebconfig ⇒ Object
86 87 88 89 |
# File 'lib/shipwright/builder.rb', line 86 def update_ebconfig Shipwright.info "Updating .elasticbeanstalk/config.yml" Shipwright::ElasticBeanstalk.update_ebconfig end |