Class: Kitchen::Provisioner::Habitat

Inherits:
Base
  • Object
show all
Defined in:
lib/kitchen/provisioner/habitat.rb

Instance Method Summary collapse

Instance Method Details

#create_sandboxObject



99
100
101
102
103
104
# File 'lib/kitchen/provisioner/habitat.rb', line 99

def create_sandbox
  super
  copy_results_to_sandbox
  copy_user_toml_to_sandbox
  copy_package_config_from_override_to_sandbox
end

#finalize_config!(instance) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/kitchen/provisioner/habitat.rb', line 53

def finalize_config!(instance)
  # Check to see if a package ident was specified for package name and be helpful
  unless config[:package_name].nil? || (config[:package_name] =~ /\//).nil?
    config[:package_origin], config[:package_name], config[:package_version], config[:package_release] = config[:package_name].split("/")
  end

  unless config[:hab_sup_artifact_name].nil?
    ident = artifact_name_to_package_ident_regex.match(config[:hab_sup_artifact_name])
    config[:hab_sup_origin] = ident["origin"]
    config[:hab_sup_name] = ident["name"]
    config[:hab_sup_version] = ident["version"]
    config[:hab_sup_release] = ident["release"]
  end

  unless config[:artifact_name].nil?
    ident = artifact_name_to_package_ident_regex.match(config[:artifact_name])
    config[:package_origin] = ident["origin"]
    config[:package_name] = ident["name"]
    config[:package_version] = ident["version"]
    config[:package_release] = ident["release"]
  end
  super(instance)
end

#init_commandObject



90
91
92
93
94
95
96
97
# File 'lib/kitchen/provisioner/habitat.rb', line 90

def init_command
  wrap_shell_code <<-EOH
    id -u hab >/dev/null 2>&1 || sudo -E useradd hab >/dev/null 2>&1
    rm -rf /tmp/kitchen
    mkdir -p /tmp/kitchen/results
    #{'mkdir -p /tmp/kitchen/config' unless config[:override_package_config]}
  EOH
end

#install_commandObject



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/kitchen/provisioner/habitat.rb', line 77

def install_command
  raise "Need to fill in some implementation here." if instance.platform == "windows"
  wrap_shell_code <<-BASH
  #{export_hab_origin}
  if command -v hab >/dev/null 2>&1
  then
    echo "Habitat CLI already installed."
  else
    curl 'https://raw.githubusercontent.com/habitat-sh/habitat/master/components/hab/install.sh' | sudo -E bash
  fi
  BASH
end

#prepare_commandObject



106
107
108
109
110
111
112
113
114
115
# File 'lib/kitchen/provisioner/habitat.rb', line 106

def prepare_command
  wrap_shell_code <<-EOH
    #{export_hab_origin}
    #{install_supervisor_command}
    #{binlink_supervisor_command}
    #{install_service_package}
    #{remove_previous_user_toml}
    #{copy_user_toml_to_service_directory}
    EOH
end

#run_commandObject



117
118
119
120
121
122
123
124
125
126
127
# File 'lib/kitchen/provisioner/habitat.rb', line 117

def run_command
  run = <<-RUN
  #{export_hab_origin}
  #{clean_up_screen_sessions}
  #{clean_up_previous_supervisor}
  echo "Running #{package_ident}."
  #{run_package_in_background}
  RUN

  wrap_shell_code run
end