Module: Beaker::DSL::EZBakeUtils

Included in:
Beaker::DSL
Defined in:
lib/beaker/dsl/ezbake_utils.rb

Overview

This module contains methods to assist in installing projects from source that use ezbake for packaging.

Private helpers collapse

LOCAL_COMMANDS_REQUIRED =
[
  ['leiningen', 'lein --version', nil],
  ['lein-pprint', 'lein with-profile ci pprint :version',
    'Must have lein-pprint installed under the :ci profile.'],
  ['java', 'java -version', nil],
  ['git', 'git --version', nil],
  ['rake', 'rake --version', nil],
]

Public DSL Methods collapse

Public DSL Methods collapse

Private helpers collapse

Class Attribute Details

.configObject



64
65
66
# File 'lib/beaker/dsl/ezbake_utils.rb', line 64

def config
  @config
end

Instance Method Details

#conditionally_clone(upstream_uri, local_path, branch = "origin/HEAD") ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Only clone from given git URI if there is no existing git clone at the given local_path location.

Parameters:

  • upstream_uri (String)

    git URI

  • local_path (String)

    path to conditionally install to

  • branch (String) (defaults to: "origin/HEAD")

    to checkout



245
246
247
248
249
250
251
252
253
254
255
# File 'lib/beaker/dsl/ezbake_utils.rb', line 245

def conditionally_clone upstream_uri, local_path, branch="origin/HEAD"
  if ezbake_local_cmd "git --work-tree=#{local_path} --git-dir=#{local_path}/.git status"
    ezbake_local_cmd "git --work-tree=#{local_path} --git-dir=#{local_path}/.git fetch origin"
    ezbake_local_cmd "git --work-tree=#{local_path} --git-dir=#{local_path}/.git checkout #{branch}"
  else
    parent_dir = File.dirname(local_path)
    FileUtils.mkdir_p(parent_dir)
    ezbake_local_cmd "git clone #{upstream_uri} #{local_path}"
    ezbake_local_cmd "git --work-tree=#{local_path} --git-dir=#{local_path}/.git checkout #{branch}"
  end
end

#ezbake_configHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return the ezbake config.

Returns:

  • (Hash)

    configuration for ezbake, usually from ezbake.rb



141
142
143
# File 'lib/beaker/dsl/ezbake_utils.rb', line 141

def ezbake_config
  EZBakeUtils.config
end

#ezbake_dev_build(url = "[email protected]:puppetlabs/ezbake.git", branch = "master") ⇒ Object

Install a development version of ezbake into the local m2 repository

This can be useful if you want to work on a development branch of ezbake that hasn’t been released yet. Ensure your project dependencies in your development branch include a reference to the -SNAPSHOT version of the project for it to successfully pickup a pre-shipped version of ezbake.

Parameters:

  • url (String) (defaults to: "[email protected]:puppetlabs/ezbake.git")

    git url

  • branch (String) (defaults to: "master")

    git branch



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/beaker/dsl/ezbake_utils.rb', line 49

def ezbake_dev_build url = "[email protected]:puppetlabs/ezbake.git",
                     branch = "master"
  ezbake_dir = 'tmp/ezbake'
  conditionally_clone url, ezbake_dir, branch
  lp = ezbake_lein_prefix

  Dir.chdir(ezbake_dir) do
    ezbake_local_cmd "#{lp} install",
                      :throw_on_failure => true
  end
end

#ezbake_install_dirString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the full path to the installed software on the remote host.

This only returns the path, it doesn’t work out if its installed or not.

Returns:

  • (String)

    path to the installation dir



224
225
226
# File 'lib/beaker/dsl/ezbake_utils.rb', line 224

def ezbake_install_dir
  "/root/#{ezbake_install_name}"
end

#ezbake_install_nameString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Retrieve the tarball installation name. This is the name of the tarball without the .tar.gz extension, and the name of the path where it will unpack to.

Returns:

  • (String)

    name of the tarball and directory



210
211
212
213
214
215
# File 'lib/beaker/dsl/ezbake_utils.rb', line 210

def ezbake_install_name
  ezbake = ezbake_config
  project_package_version = ezbake[:package_version]
  project_name = ezbake[:project]
  "%s-%s" % [ project_name, project_package_version ]
end

#ezbake_installsh(host, task = "") ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

A helper that wraps the execution of install.sh in the proper ezbake installation directory.

Parameters:

  • host (Host)

    Host to run install.sh on

  • task (String) (defaults to: "")

    Task to execute with install.sh



234
235
236
# File 'lib/beaker/dsl/ezbake_utils.rb', line 234

def ezbake_installsh host, task=""
  on host, "cd #{ezbake_install_dir}; bash install.sh #{task}"
end

#ezbake_lein_prefixString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a leiningen prefix with local m2 repo capability

Returns:

  • (String)

    lein prefix command that uses a local build m2 repository.



150
151
152
153
154
155
# File 'lib/beaker/dsl/ezbake_utils.rb', line 150

def ezbake_lein_prefix
  # Get the absolute path to the local repo
  m2_repo = File.join(Dir.pwd, 'tmp', 'm2-local')

  'lein update-in : assoc :local-repo "\"' + m2_repo + '\"" --'
end

#ezbake_local_cmd(cmd, opts = {}) ⇒ bool

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Executes a local command using system, logging the prepared command

Parameters:

  • cmd (String)

    command to execute

  • opts (Hash) (defaults to: {})

    options

Options Hash (opts):

  • :throw_on_failure (bool)

    If true, throws an exception if the exit code is non-zero. Defaults to false.

Returns:

  • (bool)

    true if exit == 0 false if otherwise

Raises:

  • (RuntimeError)

    if :throw_on_failure is true and command fails



191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/beaker/dsl/ezbake_utils.rb', line 191

def ezbake_local_cmd cmd, opts={}
  opts = {
    :throw_on_failure => false,
  }.merge(opts)

  logger.notify "localhost $ #{cmd}"
  result = system cmd
  if opts[:throw_on_failure] && result == false
    raise RuntimeError, "Command failure #{cmd}"
  end
  result
end

#ezbake_stageObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Prepares a staging directory for the specified project.



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/beaker/dsl/ezbake_utils.rb', line 160

def ezbake_stage
  # Install the PuppetDB jar into the local repository
  ezbake_local_cmd "#{ezbake_lein_prefix} install",
                   :throw_on_failure => true

  # Run ezbake stage
  ezbake_local_cmd "#{ezbake_lein_prefix} with-profile ezbake ezbake stage",
                   :throw_on_failure => true

  # Boostrap packaging, and grab configuration info from project
  staging_dir = File.join('target','staging')
  Dir.chdir(staging_dir) do
    ezbake_local_cmd 'rake package:bootstrap'

    load 'ezbake.rb'
    ezbake = EZBake::Config
    ezbake[:package_version] = `echo -n $(rake pl:print_build_param[ref] | tail -n 1)`
    EZBakeUtils.config = ezbake
  end
end

#ezbake_tools_available?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Checks given host for the tools necessary to perform install_from_ezbake.

Returns:

  • (Boolean)

Raises:

  • (RuntimeError)

    if tool is not found



125
126
127
128
129
130
131
132
133
134
135
# File 'lib/beaker/dsl/ezbake_utils.rb', line 125

def ezbake_tools_available?
  LOCAL_COMMANDS_REQUIRED.each do |software_name, command, additional_error_message|
    if not system command
      error_message = "Must have #{software_name} installed on development system.\n"
      if additional_error_message
        error_message += additional_error_message
      end
      raise RuntimeError, error_message
    end
  end
end

#ezbake_validate_support(host) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Test for support in one place

Parameters:

  • host (Host)

    host to check for support

Raises:

  • (RuntimeError)

    if OS is not supported



74
75
76
77
78
79
80
# File 'lib/beaker/dsl/ezbake_utils.rb', line 74

def ezbake_validate_support host
  variant, version, _, _ = host['platform'].to_array
  unless variant =~ /^(fedora|el|centos|debian|ubuntu)$/
    raise RuntimeError,
          "No support for #{variant} within ezbake_utils ..."
  end
end

#install_ezbake_tarball_on_host(host) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Build, copy & unpack tarball on remote host

Parameters:

  • host (Host)

    installation destination



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/beaker/dsl/ezbake_utils.rb', line 86

def install_ezbake_tarball_on_host host
  if not ezbake_config
    ezbake_stage
  end

  # Skip installation if the remote directory exists
  result = on host, "test -d #{ezbake_install_dir}", :acceptable_exit_codes => [0, 1]
  return if result.exit_code == 0

  ezbake_staging_dir = File.join('target', 'staging')
  Dir.chdir(ezbake_staging_dir) do
    ezbake_local_cmd 'rake package:tar'
  end

  local_tarball = ezbake_staging_dir + "/pkg/" + ezbake_install_name + ".tar.gz"
  remote_tarball = ezbake_install_dir + ".tar.gz"
  scp_to host, local_tarball, remote_tarball

  # untar tarball on host
  on host, "tar -xzf " + remote_tarball

  # Check to ensure directory exists
  on host, "test -d #{ezbake_install_dir}"
end

#install_from_ezbake(host) ⇒ Object

Installs leiningen project with given name and version on remote host.

Parameters:

  • host (Host)

    A single remote host on which to install the specified leiningen project.



19
20
21
22
23
24
# File 'lib/beaker/dsl/ezbake_utils.rb', line 19

def install_from_ezbake host
  ezbake_validate_support host
  ezbake_tools_available?
  install_ezbake_tarball_on_host host
  ezbake_installsh host, "service"
end

#install_termini_from_ezbake(host) ⇒ Object

Installs termini with given name and version on remote host.

Parameters:

  • host (Host)

    A single remote host on which to install the specified leiningen project.



31
32
33
34
35
36
# File 'lib/beaker/dsl/ezbake_utils.rb', line 31

def install_termini_from_ezbake host
  ezbake_validate_support host
  ezbake_tools_available?
  install_ezbake_tarball_on_host host
  ezbake_installsh host, "termini"
end