diff --git a/manifests/init.pp b/manifests/init.pp index bb078a0..83fdee7 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -16,8 +16,18 @@ # String with Database password. # # [*mastodon_version*] -# String with Mastodon version (code tag) to install. Default v4.2.1 +# String with Mastodon version (code tag) to install. Default: v4.2.1 # +# [*mastodon_user*] +# String with the system user name for mastodon. Default: mastodon +# +# [*mastodon_group*] +# String with the system group name for mastodon. Default: mastodon +# +# [*ruby_version*] +# String with the ruby version to use. Default: 3.2.2 +# + class mastodon ( String $ensure = 'present', String $hostname = 'mastodon.example.org', @@ -25,6 +35,9 @@ class mastodon ( String $mastodon_home = '/opt/mastodon', String $db_password = '', String $mastodon_version = 'v4.2.1', + String $ruby_version = '3.2.2', + String $mastodon_user = 'mastodon', + String $mastodon_group = 'mastodon', ) { case $ensure { default: { @@ -106,32 +119,32 @@ class mastodon ( creates => '/root/.yarnrc', require => Exec['enable_corepack'], } - group { 'mastodon': } - user { 'mastodon': - gid => 'mastodon', + group { $mastodon_group: } + user { $mastodon_user: + gid => $mastodon_group, home => $mastodon_home, managehome => true, system => true, - require => Group['mastodon'], + require => Group[$mastodon_group], } vcsrepo { 'rbenv': path => "${mastodon_home}/.rbenv", source => 'https://github.com/rbenv/rbenv.git', provider => 'git', - owner => 'mastodon', - group => 'mastodon', - require => User['mastodon'], + owner => $mastodon_user, + group => $mastodon_group, + require => User[$mastodon_user], } exec { 'configure_rbenv': command => "${mastodon_home}/.rbenv/src/configure", - user => 'mastodon', + user => $mastodon_user, cwd => "${mastodon_home}/.rbenv/", creates => "${mastodon_home}/.rbenv/src/Makefile", require => Vcsrepo['rbenv'], } exec { 'make_rbenv': command => '/usr/bin/make -C src', - user => 'mastodon', + user => $mastodon_user, cwd => "${mastodon_home}/.rbenv/", creates => "${mastodon_home}/.rbenv/libexec/rbenv-realpath.dylib", require => Exec['configure_rbenv'], @@ -152,35 +165,35 @@ class mastodon ( path => "${mastodon_home}/.rbenv/plugins/ruby-build", source => 'https://github.com/rbenv/ruby-build.git', provider => 'git', - owner => 'mastodon', - group => 'mastodon', + owner => $mastodon_user, + group => $mastodon_group, require => Vcsrepo['rbenv'], } file { '/usr/local/bin/install_ruby.sh': ensure => $ensure, content => template('mastodon/install_ruby.sh.erb'), mode => '0750', - owner => 'mastodon', + owner => $mastodon_user, group => 'root', require => Vcsrepo['ruby_build'], } exec { 'install_ruby': command => '/usr/local/bin/install_ruby.sh', - user => 'mastodon', + user => $mastodon_user, cwd => "${mastodon_home}/.rbenv/", creates => "${mastodon_home}/.rbenv/versions/3.2.2/bin/ruby", require => File['/usr/local/bin/install_ruby.sh'], } # exec { 'set_global_ruby_version': # command => "${mastodon_home}/.rbenv/libexec/rbenv global 3.2.2", - # user => 'mastodon', + # user => $mastodon_user, # cwd => "${mastodon_home}/.rbenv/", # # creates => '', # require => Exec['install_ruby'], # } # exec { 'install_bundler': # command => 'gem install bundler --no-document', - # user => 'mastodon', + # user => $mastodon_user, # cwd => "${mastodon_home}/.rbenv/", # # creates => '', # require => Vcsrepo['ruby_build'], @@ -194,20 +207,20 @@ class mastodon ( source => 'https://github.com/mastodon/mastodon.git', revision => $mastodon_version, provider => 'git', - owner => 'mastodon', - group => 'mastodon', - require => User['mastodon'], + owner => $mastodon_user, + group => $mastodon_group, + require => User[$mastodon_user], } # exec { 'config_deployment': # command => 'bundle config deployment \'true\'', - # user => 'mastodon', + # user => $mastodon_user, # cwd => "${mastodon_home}/live", # # creates => "${mastodon_home}/.rbenv/libexec/rbenv-realpath.dylib", # require => Rvm_gemset['bundler'], # } # exec { 'config_without_devel_test': # command => 'bundle config without \'development test\'', - # user => 'mastodon', + # user => $mastodon_user, # cwd => "${mastodon_home}/live", # # creates => "${mastodon_home}/.rbenv/libexec/rbenv-realpath.dylib", # require => Exec['config_deployment'], @@ -215,7 +228,7 @@ class mastodon ( # exec { 'bundle_install': # command => 'bundle install -j$(getconf _NPROCESSORS_ONLN)', # path => '/usr/sbin:/usr/bin:/sbin:/bin', - # user => 'mastodon', + # user => $mastodon_user', # cwd => "${mastodon_home}/live", # # creates => "${mastodon_home}/.rbenv/libexec/rbenv-realpath.dylib", # require => Exec['config_without_devel_test'], @@ -223,7 +236,7 @@ class mastodon ( # exec { 'yarn_install': # command => 'yarn install --pure-lockfile', # path => '/usr/sbin:/usr/bin:/sbin:/bin', - # user => 'mastodon', + # user => $mastodon_user, # cwd => "${mastodon_home}/live", # # creates => "${mastodon_home}/.rbenv/libexec/rbenv-realpath.dylib", # require => Exec['bundle_install'], diff --git a/templates/install_ruby.sh.erb b/templates/install_ruby.sh.erb index 2502875..13d611d 100644 --- a/templates/install_ruby.sh.erb +++ b/templates/install_ruby.sh.erb @@ -1,8 +1,8 @@ #!/bin/bash set -euo pipefail -su mastodon -if [ ! -e "<%= @mastodon_home %>/.rbenv/versions/3.2.2/bin/ruby" ]; then - cd "<%= @mastodon_home %>" - RUBY_CONFIGURE_OPTS=--with-jemalloc "<%= @mastodon_home %>/.rbenv/bin/rbenv" install 3.2.2 +su '<%= @mastodon_user %>' +if [ ! -e '<%= @mastodon_home %>/.rbenv/versions/<%= @ruby_version %>/bin/ruby' ]; then + cd '<%= @mastodon_home %>' + RUBY_CONFIGURE_OPTS=--with-jemalloc '<%= @mastodon_home %>/.rbenv/bin/rbenv' install '<%= @ruby_version %>' fi