Class: Moku::DeployConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/moku/deploy_config.rb

Overview

The deploy configuration used in the deployment of the instance. I.e. how the instance gets deployed.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(deploy_dir:, env:, systemd_services:, sites:) ⇒ DeployConfig

Returns a new instance of DeployConfig.

Parameters:

  • deploy_dir (Pathname)
  • env (Hash<Symbol, String>)
  • systemd_services (Array<String>)
  • sites (Sites)

45
46
47
48
49
50
# File 'lib/moku/deploy_config.rb', line 45

def initialize(deploy_dir:, env:, systemd_services:, sites:)
  @deploy_dir = Pathname.new(deploy_dir)
  @env = env
  @systemd_services = systemd_services
  @sites = sites
end

Instance Attribute Details

#deploy_dirObject (readonly)

Returns the value of attribute deploy_dir


52
53
54
# File 'lib/moku/deploy_config.rb', line 52

def deploy_dir
  @deploy_dir
end

#sitesObject (readonly)

Returns the value of attribute sites


52
53
54
# File 'lib/moku/deploy_config.rb', line 52

def sites
  @sites
end

#systemd_servicesObject (readonly)

Returns the value of attribute systemd_services


52
53
54
# File 'lib/moku/deploy_config.rb', line 52

def systemd_services
  @systemd_services
end

Class Method Details

.from_dir(dir, filename: Moku.deploy_config_filename) ⇒ Object

Parameters:

  • dir (Pathname)

31
32
33
# File 'lib/moku/deploy_config.rb', line 31

def self.from_dir(dir, filename: Moku.deploy_config_filename)
  from_hash(YAML.load(File.read((dir/filename).to_s))) # rubocop:disable Security/YAMLLoad
end

.from_hash(hash) ⇒ Object

Parameters:

  • hash (Hash)

16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/moku/deploy_config.rb', line 16

def self.from_hash(hash)
  tmp = hash.symbolize_keys
  tmp.default_proc = proc {|h, key| h[key] = {} }
  rack_env = tmp[:env][:rack_env] || tmp[:rack_env] || tmp[:rails_env]
  env = tmp[:env].merge(rack_env: rack_env)

  new(
    deploy_dir: tmp[:deploy_dir],
    env: env,
    systemd_services: tmp[:systemd_services] || [],
    sites: Sites.for(tmp[:sites])
  )
end

.from_ref(ref, ref_repo) ⇒ Object

Parameters:


37
38
39
# File 'lib/moku/deploy_config.rb', line 37

def self.from_ref(ref, ref_repo)
  from_dir(ref_repo.resolve(ref))
end

Instance Method Details

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)

60
61
62
63
64
65
# File 'lib/moku/deploy_config.rb', line 60

def eql?(other)
  deploy_dir == other.deploy_dir &&
    systemd_services == other.systemd_services &&
    sites.hosts == other.sites.hosts &&
    shell_env == other.shell_env
end

#shell_envObject


54
55
56
57
58
# File 'lib/moku/deploy_config.rb', line 54

def shell_env
  @shell_env ||= env.keep_if {|_key, value| value }
    .map {|key, value| "#{key.to_s.upcase}=#{Shellwords.escape(value)}" }
    .join(" ")
end