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.

Constant Summary collapse

REMOTE_PACKAGES_REQUIRED =
['make']
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],
]

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.configObject



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

def config
  @config
end

Instance Method Details

#ezbake_configObject

Return the ezbake config.



27
28
29
# File 'lib/beaker/dsl/ezbake_utils.rb', line 27

def ezbake_config
  EZBakeUtils.config
end

#ezbake_stage(project_name, project_param_string, ezbake_dir = "tmp/ezbake") ⇒ Object

Prepares a staging directory for the specified project.

Parameters:

  • project_name (String)

    The name of the ezbake project being worked on.

  • project_param_string (String)

    Parameters to be passed to ezbake on the command line.

  • ezbake_dir (String) (defaults to: "tmp/ezbake")

    The local directory where the ezbake project resides or should reside if it doesn’t exist already.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/beaker/dsl/ezbake_utils.rb', line 66

def ezbake_stage project_name, project_param_string, ezbake_dir="tmp/ezbake"
  ezbake_tools_available?
  conditionally_clone "[email protected]:puppetlabs-ezbake.git", ezbake_dir

  package_version = ''
  Dir.chdir(ezbake_dir) do
    `lein run -- stage #{project_name} #{project_param_string}`
  end

  staging_dir = File.join(ezbake_dir, 'target/staging')
  Dir.chdir(staging_dir) do
    output = `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?(host = nil) ⇒ Boolean

Checks given host for the tools necessary to perform install_from_ezbake. If no host is given then check the local machine for necessary available tools. If a tool is not found, then raise RuntimeError.

Returns:

  • (Boolean)


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/beaker/dsl/ezbake_utils.rb', line 36

def ezbake_tools_available? host = nil
  if host
    REMOTE_PACKAGES_REQUIRED.each do |package_name|
      if not check_for_package host, package_name
        raise "Required package, #{package_name}, not installed on #{host}" 
      end
    end
  else
    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 error_message
      end
    end
  end
end

#install_ezbake_deps(host) ⇒ Object

Installs ezbake dependencies on given host.

packaging dependencies of the ezbake project configuration currently in Beaker::DSL::EZBakeUtils.config

Parameters:

  • host (Host)

    A single remote host on which to install the



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/beaker/dsl/ezbake_utils.rb', line 91

def install_ezbake_deps host
  ezbake_tools_available? host

  if not ezbake_config
    ezbake_stage project_name, project_param_string
  end

  variant, version, arch, codename = host['platform'].to_array
  ezbake = ezbake_config

  case variant
  when /^(fedora|el|centos)$/
    dependency_list = ezbake[:redhat][:additional_dependencies]
    dependency_list.each do |dependency|
      package_name, _, package_version = dependency.split
      install_package host, package_name, package_version
    end

  when /^(debian|ubuntu|cumulus)$/
    dependency_list = ezbake[:debian][:additional_dependencies]
    dependency_list.each do |dependency|
      package_name, _, package_version = dependency.split
      if package_version
        package_version = package_version.chop
      end
      install_package host, package_name, package_version
    end

  else
    raise "No repository installation step for #{variant} yet..."
  end

end

#install_from_ezbake(host, project_name, project_param_string, env_args = {}, ezbake_dir = 'tmp/ezbake') ⇒ Object

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

specified leiningen project. this is the name of both a subdirectory of the ezbake_dir/configs dir and the name of the .clj file in that directory which contains the project map used by ezbake to create the staging directory. project_name which is to be built and installed on the remote host. cloned; alternatively, if ezbake is already at that directory, it will be updated from its github master before any ezbake operations are performed.

Parameters:

  • host (Host)

    A single remote host on which to install the

  • project_name (String)

    The name of the project. In ezbake context

  • project_param_string (String)

    The version of the project specified by

  • ezbake_dir (String) (defaults to: 'tmp/ezbake')

    The directory to which ezbake should be



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/beaker/dsl/ezbake_utils.rb', line 140

def install_from_ezbake host, project_name, project_param_string, env_args={}, ezbake_dir='tmp/ezbake'
  ezbake_tools_available? host

  if not ezbake_config
    ezbake_stage project_name, project_param_string
  end

  variant, _, _, _ = host['platform'].to_array

  case variant
  when /^(osx|windows|solaris|aix)$/
    raise "Beaker::DSL::EZBakeUtils unsupported platform: #{variant}"
  end

  ezbake = ezbake_config
  project_package_version = ezbake[:package_version]
  project_name = ezbake[:project]

  ezbake_staging_dir = File.join(ezbake_dir, "target/staging")

  remote_tarball = ""
  local_tarball = ""
  dir_name = ""

  Dir.chdir(ezbake_staging_dir) do
    output = `rake package:tar`

    pattern = "%s-%s"
    dir_name = pattern % [
      project_name,
      project_package_version
    ]
    local_tarball = "./pkg/" + dir_name + ".tar.gz"
    remote_tarball = "/root/" +  dir_name + ".tar.gz"

    scp_to host, local_tarball, remote_tarball
  end

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

  # "make" on target
  cd_to_package_dir = "cd /root/" + dir_name + "; "
  env = ""
  if not env_args.empty?
    env = "env " + env_args.map {|k, v| "#{k}=#{v} "}.join(' ')
  end
  on host, cd_to_package_dir + env + "make -e install-" + project_name

  # install init scripts and default settings, perform additional preinst
  # TODO: figure out a better way to install init scripts and defaults
  case variant
    when /^(fedora|el|centos)$/
      env += "defaultsdir=/etc/sysconfig "
      on host, cd_to_package_dir + env + "make -e install-rpm-sysv-init"
    when /^(debian|ubuntu|cumulus)$/
      env += "defaultsdir=/etc/default "
      on host, cd_to_package_dir + env + "make -e install-deb-sysv-init"
    else
      raise "No ezbake installation step for #{variant} yet..."
  end
end