require "rake" require "dtc_rake/config" require "dtc_rake/ui" require "json" require "uu/os/uesuri" module DtcRake class Product include Singleton include DtcRake::UI # Appbox version specified in deployment descriptor. attr_reader :version # UESURI of the appbox artifact. attr_reader :appbox_uri attr_reader :gem_project, :cmd_project, :vuc_project, :dockerfiles_project attr_reader :has_gem, :has_cmd, :has_vuc, :has_dockerfiles attr_reader :gem_file_name, :cmd_file_name, :vuc_file_name, :yardoc_file_name, :dockerfiles_file_name attr_reader :gem_attachment_code, :cmd_attachment_code, :vuc_attachment_code, :yardoc_attachment_code, :dockerfiles_attachment_code def initialize config = Config.instance root_dir = config.root_dir sibling_dir_path = File.expand_path(File.join(root_dir, "../#{config.vendor}_#{config.app}")) @gem_project = sibling_dir_path @has_gem = File.directory?(@gem_project) @cmd_project = "#{sibling_dir_path}-cmd" @has_cmd = File.directory?(@cmd_project) @vuc_project = "#{sibling_dir_path}-vuc" @has_vuc = File.directory?(@vuc_project) @dockerfiles_project = File.expand_path(File.join(root_dir, "../docker")) @has_dockerfiles = File.directory?(@dockerfiles_project) end def uucloud_descriptor return @uucloud_descriptor if @uucloud_descriptor # TODO: Use app.json instead of uucloud_descriptor.json for appbox metadata File.open(Config.instance.uucloud_descriptor_path, "r") do |f| @uucloud_descriptor = JSON.parse(f.read, symbolize_names: true) end end def version config = Config.instance config.appbox_version end def appbox_uri return @appbox_uri if @appbox_uri config = Config.instance appbox_uri = UU::OS::UESURI.create(territory_code: config.appbox_territory_code, artifact_code: config.appbox_artifact_code) @appbox_uri = appbox_uri end def gem_file_name return @gem_file_name if defined? @gem_file_name config = Config.instance # the actual gem version differs - e.g. uu_operation_registry-1.3.0.pre.BETA.1.gem (NOT uu_operation_registry-1.3.0-BETA.1.gem) gem_version = version.sub(/-(dev|ALPHA|BETA|RC)/) { |_| ".pre.#{$1}" } @gem_file_name = "#{config.vendor}_#{config.app}-#{gem_version}.gem" end def cmd_file_name return @cmd_file_name if defined? @cmd_file_name config = Config.instance @cmd_file_name = "#{config.vendor}_#{config.app}-cmd-#{version}.war" end def vuc_file_name return @vuc_file_name if defined? @vuc_file_name config = Config.instance @vuc_file_name = "#{config.vendor}_#{config.app}-vuc-#{version}.war" end def dockerfiles_file_name return @dockerfiles_file_name if defined? @dockerfiles_file_name config = Config.instance @dockerfiles_file_name = "#{config.vendor}_#{config.app}-dockerfiles-#{version}.zip" end def yardoc_file_name return @yardoc_file_name if defined? @yardoc_file_name config = Config.instance @yardoc_file_name = "#{config.vendor}_#{config.app}-yardoc-#{version}.zip" end def gem_attachment_code return @gem_attachment_code if defined? @gem_attachment_code config = Config.instance @gem_attachment_code = "#{config.vendor.upcase}.#{config.app.upcase}/GEM-PACK" end def cmd_attachment_code return @cmd_attachment_code if defined? @cmd_attachment_code config = Config.instance @cmd_attachment_code = "#{config.vendor.upcase}.#{config.app.upcase}/CMD-PACK" end def vuc_attachment_code return @vuc_attachment_code if defined? @vuc_attachment_code config = Config.instance @vuc_attachment_code = "#{config.vendor.upcase}.#{config.app.upcase}/VUC-PACK" end def dockerfiles_attachment_code return @dockerfiles_attachment_code if defined? @dockerfiles_attachment_code config = Config.instance @dockerfiles_attachment_code = "#{config.vendor.upcase}.#{config.app.upcase}/DOCKERFILES-PACK" end def yardoc_attachment_code return @yardoc_attachment_code if defined? @yardoc_attachment_code config = Config.instance @yardoc_attachment_code = "#{config.vendor.upcase}.#{config.app.upcase}/YARDOC-PACK" end def uucloud_descriptor_attachment_code return @uucloud_descriptor_attachment_code if defined? @uucloud_descriptor_attachment_code config = Config.instance @uucloud_descriptor_attachment_code = "#{config.vendor.upcase}.#{config.app.upcase}/UUAPP-DEPLOY" end def readme_attachment_code return @readme_attachment_code if defined? @readme_attachment_code config = Config.instance @readme_attachment_code = "#{config.vendor.upcase}.#{config.app.upcase}/README" end end end