Puppet Class: singularity::install::source

Defined in:
manifests/install/source.pp

Summary

Private class

Overview



3
4
5
6
7
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
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
88
89
90
91
92
93
# File 'manifests/install/source.pp', line 3

class singularity::install::source {
  assert_private()

  if $singularity::manage_go {
    include golang
    if $singularity::rebuild_on_go {
      Class['golang'] ~> Exec['singularity-mconfig']
    } else {
      Class['golang'] -> Exec['singularity-mconfig']
    }
  }
  ensure_packages($singularity::source_dependencies)
  $singularity::source_dependencies.each |$package| {
    Package[$package] -> Exec['singularity-mconfig']
  }

  $source_dir = "${singularity::source_base_dir}/singularity-${singularity::version}"
  $base_build_flags = {
    'prefix' => $singularity::prefix,
    'localstatedir' => $singularity::localstatedir,
    'sysconfdir' => $singularity::sysconfdir,
  }
  $build_flags_mapped = ($base_build_flags + $singularity::build_flags).map |$key, $value| {
    if $value == '' or $value =~ Boolean {
      "--${key}"
    } else {
      "--${key}=${value}"
    }
  }
  $build_flags = join($build_flags_mapped, ' ')
  $base_build_env = {
    'HOME' => '/root',
  }
  $build_env = ($base_build_env + $singularity::build_env).map |$key, $value| { "${key}=${value}" }

  file { 'singularity-mconfig':
      ensure  => 'file',
      path    => $singularity::source_mconfig_path,
      owner   => 'root',
      group   => 'root',
      mode    => '0755',
      content => join([
        '#!/bin/bash',
        '# File managed by Puppet, do not edit',
        "cd ${source_dir}",
        "./mconfig ${build_flags}",
        '',
      ], "\n")
    }

  file { $source_dir:
    ensure => 'directory',
    owner  => 'root',
    group  => 'root',
    mode   => '0755',
  }
  -> archive { 'singularity-source':
      path            => "/tmp/singularity-${singularity::version}.tar.gz",
      source          => "https://github.com/hpcng/singularity/releases/download/v${singularity::version}/singularity-${singularity::version}.tar.gz",
      extract         => true,
      extract_path    => $source_dir,
      extract_command => 'tar xfz %s --strip-components=1',
      creates         => "${source_dir}/mconfig",
      cleanup         => true,
      user            => 'root',
      group           => 'root',
      notify          => Exec['singularity-mconfig'],
    }
  exec { 'singularity-mconfig':
    path        => $singularity::source_exec_path,
    environment => $build_env,
    command     => $singularity::source_mconfig_path,
    cwd         => $source_dir,
    refreshonly => true,
    subscribe   => File['singularity-mconfig'],
  }
  ~> exec { 'singularity-make':
    path        => $singularity::source_exec_path,
    environment => $build_env,
    command     => 'make -C ./builddir',
    cwd         => $source_dir,
    refreshonly => true,
  }
  ~> exec { 'singularity-make-install':
    path        => $singularity::source_exec_path,
    environment => $build_env,
    command     => 'make -C ./builddir install',
    cwd         => $source_dir,
    refreshonly => true,
  }
}