Class: Command::BuildImage

Inherits:
Base
  • Object
show all
Defined in:
lib/command/build_image.rb

Constant Summary collapse

NAME =
"build-image"
OPTIONS =
[
  app_option(required: true),
  commit_option
].freeze
DESCRIPTION =
"Builds and pushes the image to Control Plane"
LONG_DESCRIPTION =
"- Builds and pushes the image to Control Plane\n- Automatically assigns image numbers, e.g., `app:1`, `app:2`, etc.\n- Uses `.controlplane/Dockerfile` or a different Dockerfile specified through `dockerfile` in the `.controlplane/controlplane.yml` file\n- If a commit is provided through `--commit` or `-c`, it will be set as the runtime env var `GIT_COMMIT`\n"

Constants inherited from Base

Command::Base::DEFAULT_ARGS, Command::Base::EXAMPLES, Command::Base::HIDE, Command::Base::NO_IMAGE_AVAILABLE, Command::Base::REQUIRES_ARGS, Command::Base::USAGE

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods inherited from Base

all_commands, all_options, all_options_by_key_name, app_option, #args_join, commit_option, #cp, #ensure_workload_deleted, image_option, #initialize, #latest_image, #latest_image_from, #latest_image_next, org_option, #perform, #progress, skip_confirm_option, #step, #step_error, #step_finish, terminal_size_option, upstream_token_option, use_local_token_option, version_option, #wait_for_replica, #wait_for_workload, wait_option, workload_option

Constructor Details

This class inherits a constructor from Command::Base

Instance Method Details

#callObject

rubocop:disable Metrics/MethodLength



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/command/build_image.rb', line 18

def call # rubocop:disable Metrics/MethodLength
  ensure_docker_running!

  dockerfile = config.current[:dockerfile] || "Dockerfile"
  dockerfile = "#{config.app_cpln_dir}/#{dockerfile}"

  raise "Can't find Dockerfile at '#{dockerfile}'." unless File.exist?(dockerfile)

  progress.puts("Building image from Dockerfile '#{dockerfile}'...\n\n")

  image_name = latest_image_next
  image_url = "#{config.org}.registry.cpln.io/#{image_name}"

  commit = config.options[:commit]
  build_args = []
  build_args.push("GIT_COMMIT=#{commit}") if commit

  cp.image_build(image_url, dockerfile: dockerfile, build_args: build_args)

  progress.puts("\nPushed image to '/org/#{config.org}/image/#{image_name}'.")
end