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



89
90
91
92
93
# File 'lib/kitchen/provisioner/habitat.rb', line 89

def create_sandbox
  super
  copy_results_to_sandbox
  copy_user_toml_to_sandbox
end

#finalize_config!(instance) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/kitchen/provisioner/habitat.rb', line 50

def finalize_config!(instance)
  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_timestamp] = ident["timestamp"]
  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_timestamp] = ident["timestamp"]
  end
  super(instance)
end

#init_commandObject



85
86
87
# File 'lib/kitchen/provisioner/habitat.rb', line 85

def init_command
  wrap_shell_code "id -u hab >/dev/null 2>&1 || sudo useradd hab >/dev/null 2>&1"
end

#install_commandObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/kitchen/provisioner/habitat.rb', line 69

def install_command
  if instance.platform == "windows"
    raise "Need to fill in some implementation here."
  else
    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 bash
    fi
    BASH
  end
end

#prepare_commandObject



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

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



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

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

  #{run_package_in_background}
  sleep 5
  RUN

  wrap_shell_code run
end