Class: Kdep::Commands::Build
- Inherits:
-
Object
- Object
- Kdep::Commands::Build
- Defined in:
- lib/kdep/commands/build.rb
Class Method Summary collapse
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(global_options:, command_options:, args:) ⇒ Build
constructor
A new instance of Build.
Constructor Details
#initialize(global_options:, command_options:, args:) ⇒ Build
Returns a new instance of Build.
16 17 18 19 20 21 |
# File 'lib/kdep/commands/build.rb', line 16 def initialize(global_options:, command_options:, args:) @global_options = @command_options = @args = args @ui = Kdep::UI.new(color: false) end |
Class Method Details
.option_parser ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/kdep/commands/build.rb', line 6 def self.option_parser OptionParser.new do |opts| opts. = "Usage: kdep build [deploy] [env]" opts.separator "" opts.separator "Builds a Docker image using the deploy configuration." opts.separator "" opts.on("--platform=PLATFORM", "Target platform (e.g., linux/amd64)") end end |
Instance Method Details
#execute ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/kdep/commands/build.rb', line 23 def execute deploy_name = @args[0] env = @args[1] # Discover kdep/ directory discovery = Kdep::Discovery.new kdep_dir = discovery.find_kdep_dir unless kdep_dir @ui.error("No kdep/ directory found") exit 1 end # Resolve deploy directory deploy_dir = resolve_deploy_dir(kdep_dir, deploy_name, discovery) unless deploy_dir exit 1 end # Load config config = Kdep::Config.new(deploy_dir, env).load # Construct full image tag image = config["image"] || config["name"] tag = config["tag"] || "latest" registry = config["registry"] if registry && !registry.to_s.empty? full_tag = "#{registry}/#{image}:#{tag}" else full_tag = "#{image}:#{tag}" end # Build context_dir = File.dirname(kdep_dir) begin Kdep::Docker.build( tag: full_tag, context_dir: context_dir, dockerfile: config["dockerfile"], target: config["target"], platform: @command_options[:platform] || config["platform"] ) @ui.info("Built: #{full_tag}") rescue Kdep::Docker::Error => e @ui.error(e.) exit 1 end end |