Class: ECSHelper::Command::BuildAndPush
- Defined in:
- lib/ecs_helper/command/build_and_push.rb
Instance Attribute Summary
Attributes inherited from Base
#client, #helper, #option_parser, #options, #type
Instance Method Summary collapse
- #auth_private ⇒ Object
- #build ⇒ Object
- #cmd_option_parser ⇒ Object
- #pull ⇒ Object
- #push ⇒ Object
- #required ⇒ Object
- #run ⇒ Object
- #should_cache? ⇒ Boolean
Methods inherited from Base
#check_bin, #initialize, #printable?, #validate
Methods included from Logging
Constructor Details
This class inherits a constructor from ECSHelper::Command::Base
Instance Method Details
#auth_private ⇒ Object
45 46 47 48 |
# File 'lib/ecs_helper/command/build_and_push.rb', line 45 def auth_private auth_cmd = helper.auth_private_cmd auth_cmd.run end |
#build ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/ecs_helper/command/build_and_push.rb', line 61 def build build_command = ["docker build #{directory}"] build_args = [:build_args].map { |a| "--build-arg=#{a}" } cache_command = should_cache? ? ["--cache-from #{latest_tag}"] : [] = ["--tag #{latest_tag} --tag #{version_tag}"] command = (build_command + build_args + cache_command + ).join(' ') build_cmd = Terrapin::CommandLine.new(command) console "Building with two tags: #{latest_tag} & #{version_tag}" build_cmd.run end |
#cmd_option_parser ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ecs_helper/command/build_and_push.rb', line 6 def cmd_option_parser = { build_args: [] } parser = ::OptionParser.new do |opts| opts. = 'Usage: ecs_helper build_and_push [options]' opts.on('-i VALUE', '--image VALUE', 'Set image name, will be used to detect ecr repo where to push image, for example web/nginx/toolbox (required)') do |c| [:image] = processEqual(c) end opts.on('-d VALUE', '--directory VALUE', "Set directory for dockerfile and context, default = './'") do |c| [:directory] = processEqual(c) end opts.on('-p VALUE', '--project VALUE', "Set project name, if not specified will look at ENV['PROJECT'], will be used to detect cluster") do |p| [:project] = processEqual(p) end opts.on('-a VALUE', '--application VALUE', "Set application name, if not specified will look at ENV['APPLICATION'], will be used to detect service and task definition") do |a| [:application] = processEqual(a) end opts.on('-c', '--cache', 'Cache image before build, default false') { [:cache] = true } opts.on('--build-arg=VALUE', 'Pass --build-arg to the build command') { |o| [:build_args] << o } end [parser, ] end |
#pull ⇒ Object
54 55 56 57 58 59 |
# File 'lib/ecs_helper/command/build_and_push.rb', line 54 def pull pull_cmd = Terrapin::CommandLine.new("docker pull #{latest_tag}") pull_cmd.run rescue Terrapin::ExitStatusError => e console e. end |
#push ⇒ Object
73 74 75 76 |
# File 'lib/ecs_helper/command/build_and_push.rb', line 73 def push pull_cmd = Terrapin::CommandLine.new("docker push #{latest_tag} && docker push #{version_tag}") pull_cmd.run end |
#required ⇒ Object
31 32 33 |
# File 'lib/ecs_helper/command/build_and_push.rb', line 31 def required [:image] end |
#run ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/ecs_helper/command/build_and_push.rb', line 35 def run log('Command', type) log('Options', ) log('Repository', repository) log('Auth Private', auth_private) should_cache? && log('Pull', pull) log('Build', build) log('Push', push) end |
#should_cache? ⇒ Boolean
50 51 52 |
# File 'lib/ecs_helper/command/build_and_push.rb', line 50 def should_cache? [:cache] end |