Puppet Class: hdm::rvm

Defined in:
manifests/rvm.pp

Summary

Manage HDM using RVM

Overview

This class installs the required Ruby version using RVM and runs HDM as systemd service



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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'manifests/rvm.pp', line 7

class hdm::rvm {
  assert_private()

  # All exec resources need the rvm environment
  Exec {
    environment => [
      "GEM_HOME=/usr/local/rvm/gems/ruby-${hdm::ruby_version}",
      "GEM_PATH=/usr/local/rvm/gems/ruby-${hdm::ruby_version}:/usr/local/rvm/gems/ruby-${hdm::ruby_version}@global",
      "MY_RUBY_HOME=>/usr/local/rvm/rubies/ruby-${hdm::ruby_version}",
      "IRBRC=/usr/local/rvm/rubies/ruby-${hdm::ruby_version}/.irbrc",
      "RUBY_VERSION=ruby-${hdm::ruby_version}",
    ],
  }

  # CentOS needs CRB repo (libyaml-devel)
  if $facts['os']['name'] == 'CentOS' {
    yumrepo { 'crb':
      ensure          => 'present',
      descr           => 'CentOS Stream $releasever - CRB',
      enabled         => '1',
      gpgcheck        => '1',
      gpgkey          => 'file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial',
      metadata_expire => '6h',
      metalink        => 'https://mirrors.centos.org/metalink?repo=centos-crb-$stream&arch=$basearch&protocol=https,http',
      repo_gpgcheck   => '0',
    }
    package { 'libyaml-devel':
      ensure => present,
    }
  }

  group { $hdm::group:
    ensure => present,
  }

  user { $hdm::user:
    ensure => present,
    shell  => '/sbin/nologin',
    home   => $hdm::hdm_path,
    gid    => $hdm::group,
  }

  file { $hdm::hdm_path:
    ensure => directory,
    owner  => $hdm::user,
    group  => $hdm::group,
  }

  include gnupg

  include rvm

  rvm::system_user { 'hdm':
    create => false,
  }

  rvm_system_ruby { "ruby-${hdm::ruby_version}":
    ensure      => present,
    default_use => false,
  }

  rvm_gem { 'bundler':
    ensure       => present,
    ruby_version => "ruby-${hdm::ruby_version}",
    require      => Rvm_system_ruby["ruby-${hdm::ruby_version}"],
  }

  vcsrepo { $hdm::hdm_path:
    ensure   => present,
    provider => 'git',
    source   => 'https://github.com/betadots/hdm.git',
    revision => $hdm::version,
  }

  # set bundle config path
  exec { 'bundle config path':
    command  => "rvm ${hdm::ruby_version} do bundle config set --local path 'vendor/bundle'",
    cwd      => $hdm::hdm_path,
    path     => "/usr/local/rvm/bin:${facts['path']}",
    unless   => 'grep vendor/bundle .bundle/config',
    provider => 'shell',
  }

  # set bundle config development
  exec { 'bundle config development':
    command  => "rvm ${hdm::ruby_version} do bundle config set --local with 'development'",
    cwd      => $hdm::hdm_path,
    path     => "/usr/local/rvm/bin:${facts['path']}",
    unless   => 'grep development .bundle/config',
    provider => 'shell',
  }

  # run bundle install
  exec { 'bundle install':
    command  => "rvm ${hdm::ruby_version} do bundle install --jobs $(nproc) && touch .bundle_install_finished",
    cwd      => $hdm::hdm_path,
    path     => "/usr/local/rvm/bin:${facts['path']}",
    creates  => "${hdm::hdm_path}/.bundle_install_finished",
    provider => 'shell',
  }

  file { "${hdm::hdm_path}/config/hdm.yml":
    ensure  => file,
    content => epp('hdm/hdm.yml.epp'),
    notify  => Service['hdm.service'],
  }

  # run bundle hdm db setup
  exec { 'bundle db:setup':
    command  => "rvm ${hdm::ruby_version} do bundle exec rails db:setup && touch .bundle_db_setup_finished",
    cwd      => $hdm::hdm_path,
    path     => "/usr/local/rvm/bin:${facts['path']}",
    creates  => "${hdm::hdm_path}/.bundle_db_setup_finished",
    provider => 'shell',
  }

  # generate rails credentials
  exec { 'bundle rails credentials':
    command  => "echo 'secret' | EDITOR='vim' rvm ${hdm::ruby_version} do bundle exec rails credentials:edit",
    cwd      => $hdm::hdm_path,
    path     => "/usr/local/rvm/bin:${facts['path']}",
    creates  => "${hdm::hdm_path}/config/credentials.yml.enc",
    provider => 'shell',
  }

  systemd::unit_file { 'hdm.service':
    content => epp('hdm/hdm.service.epp'),
    enable  => true,
    active  => true,
  }
}