Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

installation via RVM #10

Merged
merged 14 commits into from
Aug 8, 2022
2 changes: 2 additions & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ fixtures:
yumrepo: "puppetlabs/yumrepo_core"
vcsrepo: "puppetlabs/vcsrepo"
systemd: "puppet/systemd"
rvm: "puppet/rvm"
gnupg: "golja/gnupg"
17 changes: 10 additions & 7 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
# This class controls the installation of HDM
#
# @param method Select the installation method.
# Avalable methods: docker
# The puppet-ruby implenentation is not yet working.
# When using puppet-ruby we install bundler gem into
# the puppet-agent ruby installation.
# Avalable methods: docker, rvm
# When using rvm we install rvm into system and add the
# bundler gem.
#
# @param manage_docker Set to false if this module should NOT
# also include the docker class (without any arguments)
Expand All @@ -19,6 +18,9 @@
# Version is the image tag name when using docker and
# the git tag when using puppet-ruby
#
# @param ruby_version Select the ruby version when installing using rvm
# Please check [hdm ruby version requirement](https://github.com/betadots/hdm/blob/main/.ruby-version)
#
# @param port The port where HDM should run on
#
# @param bind_ip The ip address to bind the process to
Expand Down Expand Up @@ -110,9 +112,10 @@
# @example
# include hdm
class hdm (
Enum['docker'] $method = 'docker',
Enum['docker', 'rvm'] $method = 'docker',
Boolean $manage_docker = true,
String[1] $version = 'main',
String[1] $ruby_version = '3.1.2',
Stdlib::Port $port = 3000,
Stdlib::IP::Address::Nosubnet $bind_ip = '0.0.0.0',
String[1] $hostname = $facts['networking']['fqdn'],
Expand All @@ -133,8 +136,8 @@
'docker': {
include hdm::docker
}
'puppet-ruby': {
include hdm::puppet_ruby
'rvm': {
include hdm::rvm
}
default: {
fail('Unknown HDM installation method.')
Expand Down
63 changes: 0 additions & 63 deletions manifests/puppet_ruby.pp

This file was deleted.

122 changes: 122 additions & 0 deletions manifests/rvm.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# class hdm::rvm
class hdm::rvm {
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}"],
}

# Fix for old g++ and sqlite3
case $facts['os']['family'] {
'RedHat': {
if versioncmp($facts['os']['release']['major'], '8') < 0 {
package { 'centos-release-scl':
ensure => present,
}

package { 'devtoolset-7':
ensure => present,
}
$exec_prefix = 'scl enable devtoolset-7 '
exec { 'update sqlite':
command => 'yum install -y https://kojipkgs.fedoraproject.org//packages/sqlite/3.8.11/1.fc21/x86_64/sqlite-devel-3.8.11-1.fc21.x86_64.rpm https://kojipkgs.fedoraproject.org//packages/sqlite/3.8.11/1.fc21/x86_64/sqlite-3.8.11-1.fc21.x86_64.rpm',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can use the package resource and provide the link to the package?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. we need to install both packages at once as we are upgrading from sqlite 3.7 to 3.8.

path => $facts['path'],
unless => 'rpm -q sqlite | grep 3.8',
}
} else {
$exec_prefix = ''
}
}
default: {
$exec_prefix = ''
}
}

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

exec { 'bundle config path':
command => "source $(rvm ${hdm::ruby_version} do rvm env --path) && 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',
}

exec { 'bundle config development':
command => "source $(rvm ${hdm::ruby_version} do rvm env --path) && 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',
}

exec { 'bundle install':
command => "${exec_prefix} 'source $(rvm ${hdm::ruby_version} do rvm env --path) && 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'),
}

exec { 'bundle db:setup':
command => "source $(rvm ${hdm::ruby_version} do rvm env --path) && 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',
}

exec { 'bundle rails credentials':
command => "source $(rvm ${hdm::ruby_version} do rvm env --path) && rvm ${hdm::ruby_version} do echo 'secret' | EDITOR='vim' 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,
}
}
12 changes: 8 additions & 4 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@
"name": "puppetlabs/docker",
"version_requirement": ">= 4.4.0 < 5.0.0"
},
{
"name": "puppetlabs/yumrepo_core",
"version_requirement": ">= 1.1.0 < 2.0.0"
},
{
"name": "puppetlabs/vcsrepo",
"version_requirement": ">= 5.2.0 < 6.0.0"
},
{
"name": "golja/gnupg",
"version_requirement": ">= 1.2.3 < 2.0.0"
},
{
"name": "puppet/rvm",
"version_requirement": ">= 2.0.0 < 3.0.0"
},
{
"name": "puppetlabs/apt",
"version_requirement": ">= 8.5.0 < 9.0.0"
Expand Down
5 changes: 5 additions & 0 deletions spec/classes/hdm_spec.rb → spec/classes/hdm_docker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
on_supported_os.each do |os, os_facts|
context "on #{os} using docker" do
let(:facts) { os_facts }
let(:params) do
{
'method' => 'docker',
}
end

it { is_expected.to compile }
end
Expand Down
18 changes: 18 additions & 0 deletions spec/classes/hdm_rvm_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'hdm' do
on_supported_os.each do |os, os_facts|
context "on #{os} using rvm" do
let(:facts) { os_facts }
let(:params) do
{
'method' => 'rvm',
}
end

it { is_expected.to compile }
tuxmea marked this conversation as resolved.
Show resolved Hide resolved
end
end
end
2 changes: 2 additions & 0 deletions spec/default_module_facts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
root_home: '/root'