Class: Vanagon::Platform::OSX

Inherits:
Vanagon::Platform show all
Defined in:
lib/vanagon/platform/osx.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, #add_group, #add_user, #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::OSX

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

Parameters:

  • name (String)

    name of the platform



127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/vanagon/platform/osx.rb', line 127

def initialize(name)
  @name = name
  @make = "/usr/bin/make"
  @tar = "tar"
  @shasum = "/usr/bin/shasum"
  @pkgbuild = "/usr/bin/pkgbuild"
  @productbuild = "/usr/bin/productbuild"
  @hdiutil = "/usr/bin/hdiutil"
  @patch = "/usr/bin/patch"
  @num_cores = "/usr/sbin/sysctl -n hw.physicalcpu"
  @mktemp = "mktemp -d -t 'tmp'"
  super(name)
end

Instance Method Details

#generate_package(project) ⇒ Array

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

Parameters:

Returns:

  • (Array)

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



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/vanagon/platform/osx.rb', line 21

def generate_package(project) # rubocop:disable Metrics/AbcSize
  target_dir = project.repo ? output_dir(project.repo) : output_dir

  # Here we maintain backward compatibility with older vanagon versions
  # that did this by default.  This shim should get removed at some point
  # in favor of just letting the makefile deliver the bill-of-materials
  # to the correct directory. This shouldn't be required at all then.
  if project.bill_of_materials.nil?
    bom_install = [
      # Move bill-of-materials into a docdir
      "mkdir -p $(tempdir)/osx/build/root/#{project.name}-#{project.version}/usr/local/share/doc/#{project.name}",
      "mv $(tempdir)/osx/build/root/#{project.name}-#{project.version}/bill-of-materials $(tempdir)/osx/build/root/#{project.name}-#{project.version}/usr/local/share/doc/#{project.name}/bill-of-materials",
    ]
  else
    bom_install = []
  end

  if project.extra_files_to_sign.any?
    sign_commands = Vanagon::Utilities::ExtraFilesSigner.commands(project, @mktemp, "/osx/build/root/#{project.name}-#{project.version}")
  else
    sign_commands = []
  end

   # Setup build directories
  ["bash -c 'mkdir -p $(tempdir)/osx/build/{dmg,pkg,scripts,resources,root,payload,plugins}'",
   "mkdir -p $(tempdir)/osx/build/root/#{project.name}-#{project.version}",
   "mkdir -p $(tempdir)/osx/build/pkg",
   # Grab distribution xml, scripts and other external resources
   "cp #{project.name}-installer.xml $(tempdir)/osx/build/",
   #copy the uninstaller to the pkg dir, where eventually the installer will go too
   "cp #{project.name}-uninstaller.tool $(tempdir)/osx/build/pkg/",
   "cp scripts/* $(tempdir)/osx/build/scripts/",
   "if [ -d resources/osx/productbuild ] ; then cp -r resources/osx/productbuild/* $(tempdir)/osx/build/; fi",
   # Unpack the project
   "gunzip -c #{project.name}-#{project.version}.tar.gz | '#{@tar}' -C '$(tempdir)/osx/build/root/#{project.name}-#{project.version}' --strip-components 1 -xf -",

   bom_install,

   # Sign extra files
   sign_commands,

   # Package the project
   "(cd $(tempdir)/osx/build/; #{@pkgbuild} --root root/#{project.name}-#{project.version} \
    --scripts $(tempdir)/osx/build/scripts \
    --identifier #{project.identifier}.#{project.name} \
    --version #{project.version} \
    --preserve-xattr \
    --install-location / \
    payload/#{project.name}-#{project.version}-#{project.release}.pkg)",
   # Create a custom installer using the pkg above
   "(cd $(tempdir)/osx/build/; #{@productbuild} --distribution #{project.name}-installer.xml \
    --identifier #{project.identifier}.#{project.name}-installer \
    --package-path payload/ \
    --resources $(tempdir)/osx/build/resources  \
    --plugins $(tempdir)/osx/build/plugins  \
    pkg/#{project.name}-#{project.version}-#{project.release}-installer.pkg)",
   # Create a dmg and ship it to the output directory
   "(cd $(tempdir)/osx/build; \
     #{@hdiutil} create \
      -volname #{project.name}-#{project.version} \
      -fs JHFS+ \
      -format UDBZ \
      -srcfolder pkg \
      dmg/#{project.package_name})",
   "mkdir -p output/#{target_dir}",
   "cp $(tempdir)/osx/build/dmg/#{project.package_name} ./output/#{target_dir}"].flatten.compact
end

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

Method to generate the files required to build a osx 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



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/vanagon/platform/osx.rb', line 95

def generate_packaging_artifacts(workdir, name, binding, project) # rubocop:disable Metrics/AbcSize
  resources_dir = File.join(workdir, "resources", "osx")
  FileUtils.mkdir_p(resources_dir)
  script_dir = File.join(workdir, "scripts")
  FileUtils.mkdir_p(script_dir)

  erb_file(File.join(VANAGON_ROOT, "resources/osx/project-installer.xml.erb"), File.join(workdir, "#{name}-installer.xml"), false, { :binding => binding })

  ["postinstall", "preinstall"].each do |script_file|
    erb_file(File.join(VANAGON_ROOT, "resources/osx/#{script_file}.erb"), File.join(script_dir, script_file), false, { :binding => binding })
    FileUtils.chmod 0755, File.join(script_dir, script_file)
  end

  erb_file(File.join(VANAGON_ROOT, 'resources', 'osx', 'uninstaller.tool.erb'), File.join(workdir, "#{name}-uninstaller.tool"), false, { :binding => binding })
  FileUtils.chmod 0755, File.join(workdir, "#{name}-uninstaller.tool")

  # Probably a better way to do this, but OSX tends to need some extra stuff
  FileUtils.cp_r("resources/osx/.", resources_dir) if File.exist?("resources/osx/")
end

#install_build_dependencies(list_build_dependencies) ⇒ String

Because homebrew does not support being run by root we need to have this method to run it in the context of another user

Parameters:

  • build_dependencies (Array)

    list of all build dependencies to install

Returns:

  • (String)

    a command to install all of the build dependencies



9
10
11
12
13
14
15
# File 'lib/vanagon/platform/osx.rb', line 9

def install_build_dependencies(list_build_dependencies)
  <<-HERE.undent
    mkdir -p /etc/homebrew
    cd /etc/homebrew
    su test -c '/usr/local/bin/brew install #{list_build_dependencies.join(' ')}'
  HERE
end

#package_name(project) ⇒ String

Method to derive the package name for the project

Parameters:

Returns:

  • (String)

    name of the osx package for this project



119
120
121
# File 'lib/vanagon/platform/osx.rb', line 119

def package_name(project)
  "#{project.name}-#{project.version}-#{project.release}.#{@os_name}#{@os_version}.dmg"
end