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



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

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



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

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



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

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



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/kitchen/provisioner/habitat.rb', line 80

def install_command
  raise "Need to fill in some implementation here." if instance.platform == "windows"

  version = " -v #{config[:hab_version]}" unless config[:hab_version].eql?("latest")

  wrap_shell_code <<-BASH
  #{export_hab_bldr_url}
  if command -v hab >/dev/null 2>&1
  then
    echo "Habitat CLI already installed."
  else
    curl -o /tmp/install.sh 'https://raw.githubusercontent.com/habitat-sh/habitat/master/components/hab/install.sh'
    sudo -E bash /tmp/install.sh#{version}
  fi
  BASH
end

#prepare_commandObject



113
114
115
116
117
118
119
120
121
122
# File 'lib/kitchen/provisioner/habitat.rb', line 113

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

#run_commandObject



124
125
126
127
128
129
130
131
132
133
134
# File 'lib/kitchen/provisioner/habitat.rb', line 124

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

  wrap_shell_code run
end