Class: AppBuilder::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/app_builder/config.rb

Constant Summary collapse

VALID_OPTIONS =
[
  :build_id,
  :project_name,
  :remote_repository,
  :branch,
  :revision,
  :src_base_url,
  :manifest_base_url,
  :remote_src_path,
  :remote_manifest_path,
  :manifest_template_path,
  :resource_host,
  :ssh_user,
  :identity_file,
  :logger,
].freeze
PARAMETERS =
[
  :working_path,
  :repo_path,
  :archive_path,
  :build_path,
  :builded_src_path,
  :builded_manifest_path,
  :revision_path,
  :src_url,
  :manifest_url,
  :remote_app_home,
].concat(VALID_OPTIONS).freeze

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Config

Returns a new instance of Config.



35
36
37
38
# File 'lib/app_builder/config.rb', line 35

def initialize(options = {})
  reset
  merge(options)
end

Instance Method Details

#archive_pathObject



63
64
65
# File 'lib/app_builder/config.rb', line 63

def archive_path
  File.join(working_path, "archive", build_id)
end

#build_nameObject



47
48
49
# File 'lib/app_builder/config.rb', line 47

def build_name
  "#{build_id}.tar.gz"
end

#build_pathObject



67
68
69
# File 'lib/app_builder/config.rb', line 67

def build_path
  File.join(working_path, "build", build_id)
end

#builded_manifest_pathObject



75
76
77
# File 'lib/app_builder/config.rb', line 75

def builded_manifest_path
  File.join(build_path, manifest_name)
end

#builded_src_pathObject



71
72
73
# File 'lib/app_builder/config.rb', line 71

def builded_src_path
  File.join(build_path, build_name)
end

#manifest_nameObject



51
52
53
# File 'lib/app_builder/config.rb', line 51

def manifest_name
  "#{build_id}.yml"
end

#manifest_urlObject



87
88
89
# File 'lib/app_builder/config.rb', line 87

def manifest_url
  File.join(manifest_base_url, manifest_name)
end

#merge(params) ⇒ Object



40
41
42
43
44
45
# File 'lib/app_builder/config.rb', line 40

def merge(params)
  params.each do |key, value|
    self.send("#{key}=", value)
  end
  self
end

#remote_app_homeObject



91
92
93
# File 'lib/app_builder/config.rb', line 91

def remote_app_home
  File.join("/var/www", project_name)
end

#repo_pathObject



59
60
61
# File 'lib/app_builder/config.rb', line 59

def repo_path
  File.join(working_path, "repo")
end

#resetObject



95
96
97
98
99
100
101
102
103
104
105
# File 'lib/app_builder/config.rb', line 95

def reset
  @build_id               = Time.now.strftime("%Y%m%d%H%M%S")
  @project_name           = File.basename(`git rev-parse --show-toplevel`.chomp)
  @remote_repository      = `git remote get-url origin`.chomp
  @branch                 = ENV.fetch("TARGET_BRANCH", "master")
  @revision               = `git rev-parse #{branch}`.chomp
  @manifest_template_path = File.expand_path("template/manifest.yml.erb", __dir__)
  @ssh_user               = ENV.fetch("USER", nil)
  @identity_file          = "~/.ssh/id_rsa"
  @logger                 = Logger.new(STDOUT)
end

#revision_pathObject



79
80
81
# File 'lib/app_builder/config.rb', line 79

def revision_path
  File.join(archive_path, "revision.yml")
end

#src_urlObject



83
84
85
# File 'lib/app_builder/config.rb', line 83

def src_url
  File.join(src_base_url, build_name)
end

#working_pathObject



55
56
57
# File 'lib/app_builder/config.rb', line 55

def working_path
  File.join("/var/tmp", project_name)
end