Class: Vanagon::Platform::Solaris11

Inherits:
Vanagon::Platform show all
Defined in:
lib/vanagon/platform/solaris_11.rb

Constant Summary

Constants inherited from Vanagon::Platform

PLATFORM_REGEX, VERSION_REGEX

Instance Attribute Summary

Attributes inherited from Vanagon::Platform

#abs_resource_name, #architecture, #aws_ami, #aws_instance_type, #aws_key, #aws_key_name, #aws_region, #aws_shutdown_behavior, #aws_subnet_id, #aws_user_data, #aws_vpc_id, #build_dependencies, #build_hosts, #cflags, #codename, #copy, #cross_compiled, #defaultdir, #dist, #docker_image, #docker_run_args, #environment, #find, #install, #ldflags, #make, #mktemp, #name, #num_cores, #os_name, #os_version, #output_dir, #package_type, #patch, #platform_triple, #provisioning, #rpmbuild, #sed, #servicedir, #servicetype, #servicetypes, #settings, #shasum, #shell, #sort, #source_output_dir, #ssh_port, #tar, #target_user, #use_docker_exec, #valid_operators, #vmpooler_template

Instance Method Summary collapse

Methods inherited from Vanagon::Platform

#[], #add_build_repository, #generate_compiled_archive, #get_service_dir, #get_service_types, #is_aix?, #is_cisco_wrlinux?, #is_cross_compiled?, #is_cross_compiled_linux?, #is_deb?, #is_debian?, #is_el8?, #is_el?, #is_eos?, #is_fedora?, #is_fips?, #is_huaweios?, #is_linux?, #is_macos?, #is_osx?, #is_rpm?, #is_sles?, #is_solaris?, #is_ubuntu?, #is_unix?, #is_windows?, load_platform, #package_override, #provision_with, #validate_operator, #version_munger

Methods included from HashableAttributes

#to_hash, #to_json

Methods included from Utilities

#erb_file, #erb_string, #ex, #find_program_on_path, #get_md5sum, #get_sum, #http_request, #http_request_code, #http_request_generic, #local_command, #remote_ssh_command, #retry_with_timeout, #rsync_from, #rsync_to, #ssh_command

Constructor Details

#initialize(name) ⇒ Vanagon::Platform::Solaris

Constructor. Sets up some defaults for the solaris 11 platform and calls the parent constructor

Parameters:

  • name (String)

    name of the platform



114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/vanagon/platform/solaris_11.rb', line 114

def initialize(name)
  @name = name
  @make = "/usr/bin/gmake"
  @tar = "/usr/bin/gtar"
  @patch = "/usr/bin/gpatch"
  @sed = "/usr/gnu/bin/sed"
  @num_cores = "/usr/bin/kstat cpu_info | /usr/bin/ggrep -E '[[:space:]]+core_id[[:space:]]' | wc -l"
  super(name)
  if @architecture == "sparc"
    @platform_triple = "sparc-sun-solaris2.#{@os_version}"
  elsif @architecture == "i386"
    @platform_triple = "i386-pc-solaris2.#{@os_version}"
  end
end

Instance Method Details

#add_group(user) ⇒ String

Generate the scripts required to add a group to the package generated. This will also update the group if it has changed.

Parameters:

Returns:

  • (String)

    the commands required to add a group to the system



55
56
57
# File 'lib/vanagon/platform/solaris_11.rb', line 55

def add_group(user)
  "group groupname=#{user.group}"
end

#add_repository(uri, origin) ⇒ String

Helper to setup an IPS build repo on a target system docs.oracle.com/cd/E36784_01/html/E36802/gkkek.html

Parameters:

  • uri (String)

    uri of the repository to add

  • origin (String)

    origin of the repository

Returns:

  • (String)

    the command required to add an ips build repository



65
66
67
# File 'lib/vanagon/platform/solaris_11.rb', line 65

def add_repository(uri, origin)
  "pkg set-publisher -G '*' -g #{uri} #{origin}"
end

#add_user(user) ⇒ String

Generate the scripts required to add a user to the package generated. This will also update the user if it has changed.

Parameters:

Returns:

  • (String)

    the commands required to add a user to the system



74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/vanagon/platform/solaris_11.rb', line 74

def add_user(user)
  command = "user username=#{user.name}"
  command << " group=#{user.group}" if user.group
  command << " home-dir=#{user.homedir}" if user.homedir
  if user.shell
    command << " login-shell=#{user.shell}"
  elsif user.is_system
    command << " login-shell=/usr/bin/false"
  end

  command
end

#generate_package(project) ⇒ Array

The specific bits used to generate a solaris package for a given project

Parameters:

Returns:

  • (Array)

    list of commands required to build a solaris package for the given project from a tarball



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/vanagon/platform/solaris_11.rb', line 8

def generate_package(project) # rubocop:disable Metrics/AbcSize
  target_dir = project.repo ? output_dir(project.repo) : output_dir
  name_and_version = "#{project.name}-#{project.version}"
  pkg_name = package_name(project)

  [
    # Set up our needed directories
    "mkdir -p $(tempdir)/#{name_and_version}",
    "mkdir -p $(tempdir)/pkg",
    "mkdir -p output/#{target_dir}",

    # Unpack the project and stage the packaging artifacts
    "gunzip -c #{name_and_version}.tar.gz | '#{@tar}' -C '$(tempdir)' -xf -",
    "cp -r packaging $(tempdir)/",
    "pkgrepo create $(tempdir)/repo",
    "pkgrepo set -s $(tempdir)/repo publisher/prefix=#{project.identifier}",

    "(cd $(tempdir); pkgsend generate #{name_and_version} | pkgfmt >> packaging/#{project.name}.p5m.1)",

    # Actually build the package
    "(cd $(tempdir)/packaging; pkgmogrify -DARCH=`uname -p` #{project.name}.p5m.1 #{project.name}.p5m | pkgfmt > #{project.name}.p5m.2)",
    "pkglint $(tempdir)/packaging/#{project.name}.p5m.2",
    "pkgsend -s 'file://$(tempdir)/repo' publish -d '$(tempdir)/#{name_and_version}' --fmri-in-manifest '$(tempdir)/packaging/#{project.name}.p5m.2'",
    "pkgrecv -s 'file://$(tempdir)/repo' -a -d 'output/#{target_dir}/#{pkg_name}' '#{project.name}@#{ips_version(project.version, project.release)}'",

    # Now make sure the package we built isn't totally broken (but not when cross-compiling)
    %(if [ "#{@architecture}" = `uname -p` ]; then pkg install -nv -g 'output/#{target_dir}/#{pkg_name}' '#{project.name}@#{ips_version(project.version, project.release)}'; fi),
  ]
end

#generate_packaging_artifacts(workdir, name, binding, project) ⇒ Object

Method to generate the files required to build a solaris package for the project

Parameters:

  • workdir (String)

    working directory to stage the evaluated templates in

  • name (String)

    name of the project

  • binding (Binding)

    binding to use in evaluating the packaging templates

  • project (Vanagon::Project)

    Vanagon::Project we are building for



44
45
46
47
48
# File 'lib/vanagon/platform/solaris_11.rb', line 44

def generate_packaging_artifacts(workdir, name, binding, project)
  target_dir = File.join(workdir, 'packaging')
  FileUtils.mkdir_p(target_dir)
  erb_file(File.join(VANAGON_ROOT, "resources/solaris/11/p5m.erb"), File.join(target_dir, "#{name}.p5m"), false, { :binding => binding })
end

#ips_version(version, release) ⇒ String

Method to transform a standard version into the format expected by IPS packages

Parameters:

  • version (String)

    Standard package version

  • release (String)

    Standard package release

Returns:

  • (String)

    version in IPS format



101
102
103
104
105
106
107
108
# File 'lib/vanagon/platform/solaris_11.rb', line 101

def ips_version(version, release)
  version = version.gsub(/[a-zA-Z]/, '')
  version = version.gsub(/(^-)|(-$)/, '')

  # Here we strip leading 0 from version components but leave singular 0 on their own.
  version = version.split('.').map(&:to_i).join('.')
  "#{version},5.11-#{release}"
end

#package_name(project) ⇒ String

Method to derive the package name for the project

Parameters:

Returns:

  • (String)

    name of the solaris package for this project



91
92
93
# File 'lib/vanagon/platform/solaris_11.rb', line 91

def package_name(project)
  "#{project.name}@#{ips_version(project.version, project.release)}.#{@architecture}.p5p"
end