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
48 49 50 51 |
# File 'lib/ecs_helper/command/build_and_push.rb', line 48 def auth_private auth_cmd = helper.auth_private_cmd auth_cmd.run end |
#build ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ecs_helper/command/build_and_push.rb', line 64 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}"] file_command = ["--file #{file}"] command = (build_command + file_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 30 31 32 |
# 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 build context, default = './'") do |c| [:directory] = processEqual(c) end opts.on('-f VALUE', '--file VALUE', "Set path for Dockerfile, default = './Dockerfile'") do |c| [:file] = 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
57 58 59 60 61 62 |
# File 'lib/ecs_helper/command/build_and_push.rb', line 57 def pull pull_cmd = Terrapin::CommandLine.new("docker pull #{latest_tag}") pull_cmd.run rescue Terrapin::ExitStatusError => e console e. end |
#push ⇒ Object
77 78 79 80 |
# File 'lib/ecs_helper/command/build_and_push.rb', line 77 def push pull_cmd = Terrapin::CommandLine.new("docker push #{latest_tag} && docker push #{version_tag}") pull_cmd.run end |
#required ⇒ Object
34 35 36 |
# File 'lib/ecs_helper/command/build_and_push.rb', line 34 def required [:image] end |
#run ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/ecs_helper/command/build_and_push.rb', line 38 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
53 54 55 |
# File 'lib/ecs_helper/command/build_and_push.rb', line 53 def should_cache? [:cache] end |