2023-11-26 11:59:01 +01:00
|
|
|
# Class to install a Mastodon instance
|
|
|
|
#
|
|
|
|
# [*ensure*]
|
|
|
|
# String defining if is present or absent
|
|
|
|
#
|
|
|
|
# [*hostname*]
|
|
|
|
# String with the full qualified hostname of the instance. There must be a DNS record for it.
|
|
|
|
#
|
|
|
|
# [*smtp_server*]
|
|
|
|
# String with the SMTP server to use.
|
|
|
|
#
|
2023-11-27 17:35:50 +01:00
|
|
|
# [*mastodon_home*]
|
|
|
|
# String path to Mastodon user home directory. Default /opt/mastodon
|
|
|
|
#
|
2023-11-27 18:19:40 +01:00
|
|
|
# [*db_password*]
|
|
|
|
# String with Database password.
|
|
|
|
#
|
|
|
|
# [*mastodon_version*]
|
2023-11-28 08:25:07 +01:00
|
|
|
# String with Mastodon version (code tag) to install. Default: v4.2.1
|
2023-11-27 18:19:40 +01:00
|
|
|
#
|
2023-11-28 08:25:07 +01:00
|
|
|
# [*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
|
|
|
|
#
|
2023-11-28 08:27:41 +01:00
|
|
|
#
|
2023-11-26 11:59:01 +01:00
|
|
|
class mastodon (
|
|
|
|
String $ensure = 'present',
|
|
|
|
String $hostname = 'mastodon.example.org',
|
2023-11-27 17:35:50 +01:00
|
|
|
String $smtp_server = 'mail.example.org',
|
|
|
|
String $mastodon_home = '/opt/mastodon',
|
2023-11-27 18:19:40 +01:00
|
|
|
String $db_password = '',
|
|
|
|
String $mastodon_version = 'v4.2.1',
|
2023-11-28 08:25:07 +01:00
|
|
|
String $ruby_version = '3.2.2',
|
|
|
|
String $mastodon_user = 'mastodon',
|
|
|
|
String $mastodon_group = 'mastodon',
|
2023-11-26 11:59:01 +01:00
|
|
|
) {
|
|
|
|
case $ensure {
|
|
|
|
default: {
|
|
|
|
$package_ensure = 'installed'
|
|
|
|
$directory_ensure = 'directory'
|
|
|
|
$link_ensure = 'link'
|
|
|
|
$service_ensure = 'running'
|
|
|
|
$file_ensure = 'present'
|
|
|
|
}
|
|
|
|
/^(absent|delete|uninstall|remove|unregister)$/: {
|
|
|
|
$package_ensure = 'absent'
|
|
|
|
$directory_ensure = 'absent'
|
|
|
|
$link_ensure = 'absent'
|
|
|
|
$file_ensure = 'absent'
|
|
|
|
$service_ensure = 'stopped'
|
|
|
|
$cron_ensure = 'absent'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$packages = [
|
|
|
|
'apt-transport-https',
|
|
|
|
'autoconf',
|
|
|
|
'bison',
|
|
|
|
'build-essential',
|
|
|
|
'ca-certificates',
|
|
|
|
'certbot',
|
|
|
|
'ffmpeg',
|
|
|
|
'file',
|
|
|
|
'g++',
|
|
|
|
'gcc',
|
|
|
|
'git-core',
|
|
|
|
'gnupg',
|
|
|
|
'imagemagick',
|
|
|
|
'libffi-dev',
|
|
|
|
'libgdbm-dev',
|
|
|
|
'libicu-dev',
|
|
|
|
'libidn11-dev',
|
|
|
|
'libjemalloc-dev',
|
|
|
|
'libncurses5-dev',
|
|
|
|
'libpq-dev',
|
|
|
|
'libprotobuf-dev',
|
|
|
|
'libreadline6-dev',
|
|
|
|
'libssl-dev',
|
|
|
|
'libxml2-dev',
|
|
|
|
'libxslt1-dev',
|
|
|
|
'libyaml-dev',
|
|
|
|
'lsb-release',
|
|
|
|
'nginx',
|
|
|
|
# 'nodejs',
|
|
|
|
'pkg-config',
|
|
|
|
# 'postgresql-contrib',
|
|
|
|
# 'postgresql',
|
|
|
|
'protobuf-compiler',
|
|
|
|
'python3-certbot-nginx',
|
|
|
|
# 'redis-server',
|
|
|
|
# 'redis-tools',
|
|
|
|
'wget',
|
|
|
|
'zlib1g-dev',
|
|
|
|
]
|
2023-11-27 14:07:57 +01:00
|
|
|
$packages.each | $package | {
|
|
|
|
if (!defined(Package[$package])) {
|
|
|
|
package { $package:
|
|
|
|
ensure => $package_ensure,
|
|
|
|
}
|
2023-11-26 11:59:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
class { 'nodejs':
|
|
|
|
repo_url_suffix => '16.x',
|
|
|
|
}
|
|
|
|
class { 'postgresql::server':
|
|
|
|
}
|
2023-11-27 09:26:30 +01:00
|
|
|
include redis
|
2023-11-27 17:35:50 +01:00
|
|
|
exec { 'enable_corepack':
|
|
|
|
command => '/usr/bin/corepack enable',
|
|
|
|
creates => '/usr/bin/yarn',
|
|
|
|
require => Class['nodejs'],
|
|
|
|
}
|
|
|
|
exec { 'yarn_classic':
|
|
|
|
command => '/usr/bin/yarn set version classic',
|
|
|
|
creates => '/root/.yarnrc',
|
|
|
|
require => Exec['enable_corepack'],
|
|
|
|
}
|
2023-11-28 08:25:07 +01:00
|
|
|
group { $mastodon_group: }
|
|
|
|
user { $mastodon_user:
|
|
|
|
gid => $mastodon_group,
|
2023-11-27 17:35:50 +01:00
|
|
|
home => $mastodon_home,
|
|
|
|
managehome => true,
|
|
|
|
system => true,
|
2023-11-28 08:25:07 +01:00
|
|
|
require => Group[$mastodon_group],
|
2023-11-27 17:35:50 +01:00
|
|
|
}
|
2023-11-27 18:37:17 +01:00
|
|
|
vcsrepo { 'rbenv':
|
|
|
|
path => "${mastodon_home}/.rbenv",
|
|
|
|
source => 'https://github.com/rbenv/rbenv.git',
|
|
|
|
provider => 'git',
|
2023-11-28 08:25:07 +01:00
|
|
|
owner => $mastodon_user,
|
|
|
|
group => $mastodon_group,
|
|
|
|
require => User[$mastodon_user],
|
2023-11-27 18:37:17 +01:00
|
|
|
}
|
|
|
|
exec { 'configure_rbenv':
|
|
|
|
command => "${mastodon_home}/.rbenv/src/configure",
|
2023-11-28 08:25:07 +01:00
|
|
|
user => $mastodon_user,
|
2023-11-27 18:37:17 +01:00
|
|
|
cwd => "${mastodon_home}/.rbenv/",
|
|
|
|
creates => "${mastodon_home}/.rbenv/src/Makefile",
|
|
|
|
require => Vcsrepo['rbenv'],
|
|
|
|
}
|
|
|
|
exec { 'make_rbenv':
|
|
|
|
command => '/usr/bin/make -C src',
|
2023-11-28 08:25:07 +01:00
|
|
|
user => $mastodon_user,
|
2023-11-27 18:37:17 +01:00
|
|
|
cwd => "${mastodon_home}/.rbenv/",
|
|
|
|
creates => "${mastodon_home}/.rbenv/libexec/rbenv-realpath.dylib",
|
|
|
|
require => Exec['configure_rbenv'],
|
|
|
|
}
|
|
|
|
file_line { 'mastodon_path':
|
2023-11-27 18:41:49 +01:00
|
|
|
path => "${mastodon_home}/.bashrc",
|
2023-11-27 18:37:17 +01:00
|
|
|
line => 'export PATH="$HOME/.rbenv/bin:$PATH"',
|
|
|
|
match => '^export PATH="$HOME/.rbenv',
|
|
|
|
require => Vcsrepo['rbenv'],
|
|
|
|
}
|
|
|
|
file_line { 'mastodon_rbenv_init':
|
2023-11-27 18:41:49 +01:00
|
|
|
path => "${mastodon_home}/.bashrc",
|
2023-11-27 18:37:17 +01:00
|
|
|
line => 'eval "$(rbenv init -)"',
|
|
|
|
match => '^eval "$(rbenv init -)"',
|
|
|
|
require => Vcsrepo['rbenv'],
|
2023-11-27 18:19:40 +01:00
|
|
|
}
|
2023-11-27 18:37:17 +01:00
|
|
|
vcsrepo { 'ruby_build':
|
|
|
|
path => "${mastodon_home}/.rbenv/plugins/ruby-build",
|
|
|
|
source => 'https://github.com/rbenv/ruby-build.git',
|
|
|
|
provider => 'git',
|
2023-11-28 08:25:07 +01:00
|
|
|
owner => $mastodon_user,
|
|
|
|
group => $mastodon_group,
|
2023-11-27 18:37:17 +01:00
|
|
|
require => Vcsrepo['rbenv'],
|
|
|
|
}
|
2023-11-28 08:20:18 +01:00
|
|
|
file { '/usr/local/bin/install_ruby.sh':
|
|
|
|
ensure => $ensure,
|
|
|
|
content => template('mastodon/install_ruby.sh.erb'),
|
|
|
|
mode => '0750',
|
2023-11-28 08:25:07 +01:00
|
|
|
owner => $mastodon_user,
|
2023-11-28 08:20:18 +01:00
|
|
|
group => 'root',
|
|
|
|
require => Vcsrepo['ruby_build'],
|
|
|
|
}
|
2023-11-27 18:55:38 +01:00
|
|
|
exec { 'install_ruby':
|
2023-11-28 08:20:18 +01:00
|
|
|
command => '/usr/local/bin/install_ruby.sh',
|
2023-11-28 08:50:07 +01:00
|
|
|
# user => $mastodon_user,
|
2023-11-28 08:42:22 +01:00
|
|
|
# cwd => "${mastodon_home}/.rbenv/",
|
2023-11-28 10:07:31 +01:00
|
|
|
creates => "${mastodon_home}/.rbenv/versions/3.2.2/bin/bundler",
|
2023-11-28 08:59:45 +01:00
|
|
|
timeout => 0,
|
2023-11-28 08:20:18 +01:00
|
|
|
require => File['/usr/local/bin/install_ruby.sh'],
|
2023-11-27 18:37:17 +01:00
|
|
|
}
|
2023-11-27 18:19:40 +01:00
|
|
|
postgresql::server::db { 'mastodon':
|
|
|
|
user => 'mastodon',
|
|
|
|
password => postgresql::postgresql_password('mastodon', $db_password),
|
|
|
|
}
|
|
|
|
vcsrepo { 'mastodon_code':
|
|
|
|
path => "${mastodon_home}/live",
|
|
|
|
source => 'https://github.com/mastodon/mastodon.git',
|
|
|
|
revision => $mastodon_version,
|
2023-11-27 17:35:50 +01:00
|
|
|
provider => 'git',
|
2023-11-28 08:25:07 +01:00
|
|
|
owner => $mastodon_user,
|
|
|
|
group => $mastodon_group,
|
|
|
|
require => User[$mastodon_user],
|
2023-11-27 17:35:50 +01:00
|
|
|
}
|
2023-11-28 10:07:31 +01:00
|
|
|
exec { 'config_deployment':
|
|
|
|
command => "${mastodon_home}/live/bin/bundle config deployment 'true'",
|
|
|
|
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 => "${mastodon_home}/live/bin/bundle config without 'development test'",
|
|
|
|
user => $mastodon_user,
|
|
|
|
cwd => "${mastodon_home}/live",
|
|
|
|
# creates => "${mastodon_home}/.rbenv/libexec/rbenv-realpath.dylib",
|
|
|
|
require => Exec['config_deployment'],
|
|
|
|
}
|
|
|
|
exec { 'bundle_install':
|
|
|
|
command => "${mastodon_home}/live/bin/bundle install -j$(getconf _NPROCESSORS_ONLN)",
|
|
|
|
path => '/usr/sbin:/usr/bin:/sbin:/bin',
|
|
|
|
user => $mastodon_user,
|
|
|
|
cwd => "${mastodon_home}/live",
|
|
|
|
# creates => "${mastodon_home}/.rbenv/libexec/rbenv-realpath.dylib",
|
|
|
|
require => Exec['config_without_devel_test'],
|
|
|
|
}
|
|
|
|
exec { 'yarn_install':
|
|
|
|
command => "${mastodon_home}/live/bin/yarn install --pure-lockfile",
|
|
|
|
path => '/usr/sbin:/usr/bin:/sbin:/bin',
|
|
|
|
user => $mastodon_user,
|
|
|
|
cwd => "${mastodon_home}/live",
|
|
|
|
# creates => "${mastodon_home}/.rbenv/libexec/rbenv-realpath.dylib",
|
|
|
|
require => Exec['bundle_install'],
|
|
|
|
}
|
2023-11-26 11:59:01 +01:00
|
|
|
}
|