Commit 82315412 authored by Matthieu FAURE's avatar Matthieu FAURE

refactor: keep only things that go in a component module

Things removed go to the profile module
parent e9575a62
Pipeline #4836 failed with stages
in 3 minutes and 41 seconds
......@@ -3,4 +3,6 @@
---
fixtures:
forge_modules:
# stdlib: "puppetlabs/stdlib"
stdlib: "puppetlabs/stdlib"
postgres: "puppetlabs/postgresql"
archive: "puppet/archive"
\ No newline at end of file
......@@ -17,21 +17,19 @@ This module installs dans configure the application AMIES.
## Setup
### What amies affects **OPTIONAL**
### What amies affects
This module does following things dedicated to AMIES:
* creation of a system user;
* installation of needed system packages
* installation of a Postfix relay (TODO this should be enhanced as it uses a private Adullact module `base_postfix`)
* installation of a Postgres server and creation of a user and a database
* Postgres: creation of role, user and database
* creation of files for AMIES
### Setup Requirements **OPTIONAL**
### Setup Requirements
If your module requires anything extra before setting up (pluginsync enabled, another module, etc.), mention it here.
If your most recent release breaks compatibility or requires particular steps for upgrading, you might want to include an additional "Upgrading" section here.
* Being able to send emails (postfix, sendmail or any mail relay)
* Postgres 9.4+ installed
### Beginning with amies
......
......@@ -9,60 +9,53 @@ class amies (
Integer $smtp_port,
String $smtp_user_name,
String $smtp_user_passwd,
String $smtp_root_mail_recipient,
# Directory for AMIES application, eg /home/amies/AMIES
String $amies_app_dir,
String $app_dir,
# Directory for users uploaded pictures
String $amies_picture_dir,
String $picture_dir,
# Secret key (used as salt)
String $amies_security_key,
String $security_key,
# CI Job name from which downloading amies jar file (build artefact)
String $amies_job_name,
String $ci_job_name,
# Password for Amies database
String $amies_db_user_password,
# System user for Amies
String $amies_system_username = 'amies',
String $amies_gitlab_srv = 'gitlab.adullact.net',
String $amies_gitlab_group = 'amies',
String $amies_gitlab_project_name = 'amies-server',
String $amies_branch = 'master',
String $amies_db_host = 'localhost',
Integer $amies_db_port = 5432,
String $amies_db_name = 'amies',
String $amies_db_for_tests_name = 'amies_test',
String $amies_db_user_name = 'amies',
String $db_user_password,
Array $package_list, # Value of $package_list are specified in Hiera
String $gitlab_srv = 'gitlab.adullact.net',
String $gitlab_group = 'amies',
String $gitlab_project_name = 'amies-server',
String $gitlab_branch = 'master',
String $db_host = 'localhost',
Integer $db_port = 5432,
String $db_name = 'amies',
String $db_for_tests_name = 'amies_test',
String $db_user_name = 'amies',
String $system_username = 'amies',
# Activate debug / dev mode
Boolean $debug = false,
Array $package_list = [],
Boolean $debug = false,
) {
# #############################################################################
# Variables
# Home directory of AMIES user
$_amies_home = "/home/${amies_system_username}"
# URL of AMIES source code repository
$_amies_gitlab_full_url = "${amies_gitlab_srv}/${amies_gitlab_group}/${amies_gitlab_project_name}"
$_amies_gitlab_full_url = "${gitlab_srv}/${gitlab_group}/${gitlab_project_name}"
# URL of AMIES jar file (grabbed from a CI job)
# see https://docs.gitlab.com/ee/user/project/pipelines/job_artifacts.html#downloading-the-latest-artifacts
$_amies_jar_url = join(
[
"https://${_amies_gitlab_full_url}",
"/-/jobs/artifacts/${amies_branch}/raw/backend/build/libs/amies.jar",
"?job=${amies_job_name}",
"/-/jobs/artifacts/${gitlab_branch}/raw/backend/build/libs/amies.jar",
"?job=${ci_job_name}",
]
)
# Filename of AMIES jar file (build artefact)
$_amies_jar_name = 'amies.jar'
$_jar_name = 'amies.jar'
# Postgres role for Amies
$_amies_db_role = 'amies'
# JDBC URL string
$_amies_jdbc_url = "jdbc:postgresql://${amies_db_host}:${amies_db_port}/${amies_db_name}"
# #############################################################################
# PREREQUISITES system user
accounts::user { $amies_system_username: }
$_amies_jdbc_url = "jdbc:postgresql://${db_host}:${db_port}/${db_name}"
# #############################################################################
# PREREQUISITES packages
......@@ -75,72 +68,50 @@ class amies (
ensure => present,
}
# #############################################################################
# PREREQUISITES SMTP Relay
class { 'base_postfix':
relayhost => "${smtp_host}:${smtp_port}",
sasl_username => $smtp_user_name,
sasl_password => $smtp_user_passwd,
root_mail_recipient => $smtp_user_name,
}
# #############################################################################
# PREREQUISITES Postgres
class { 'postgresql::server':
}
-> postgresql::server::role { $_amies_db_role:
password_hash => postgresql_password($amies_db_user_name, $amies_db_user_password),
# Role creation
postgresql::server::role { $_amies_db_role:
password_hash => postgresql_password($db_user_name, $db_user_password),
}
-> postgresql::server::db { $amies_db_name:
user => $amies_db_user_name,
password => postgresql_password($amies_db_user_name, $amies_db_user_password),
# DB + Postgres user creation
-> postgresql::server::db { $db_name:
user => $db_user_name,
password => postgresql_password($db_user_name, $db_user_password),
}
-> postgresql::server::database_grant { $amies_db_name:
# Privileges granting
-> postgresql::server::database_grant { $db_name:
privilege => 'ALL',
db => $amies_db_name,
db => $db_name,
role => $_amies_db_role,
}
# Create DB needed for running tests
if $amies::debug {
postgresql::server::db { $amies_db_for_tests_name:
user => $amies_db_user_name,
password => postgresql_password($amies_db_user_name, $amies_db_user_password),
postgresql::server::db { $db_for_tests_name:
user => $db_user_name,
password => postgresql_password($db_user_name, $db_user_password),
}
postgresql::server::database_grant { $amies_db_for_tests_name:
postgresql::server::database_grant { $db_for_tests_name:
privilege => 'ALL',
db => $amies_db_for_tests_name,
db => $db_for_tests_name,
role => $_amies_db_role,
require => Postgresql::Server::Role[$_amies_db_role],
}
}
# PGPASS file
$_pgpass_content = "
# hostname:port:database:username:password
${amies_db_host}:${amies_db_port}:${amies_db_name}:${amies_db_user_name}:${amies_db_user_password}
"
file { 'PGPASS file':
ensure => file,
path => "${_amies_home}/.pgpass",
mode => '0600',
owner => $amies_system_username,
content => $_pgpass_content,
}
# #############################################################################
# Prepare AMIES
# Create directory for users uploaded pictures
file { 'AMIES picture dir':
ensure => directory,
path => $amies_picture_dir,
path => $picture_dir,
mode => '0700',
owner => $amies_system_username,
owner => $system_username,
}
# Create systemd unit-file
......@@ -153,10 +124,9 @@ ${amies_db_host}:${amies_db_port}:${amies_db_name}:${amies_db_user_name}:${amies
# Get AMIES jar file
archive { 'download-amies-jar':
ensure => 'present',
path => "${amies::amies_app_dir}/${amies::_amies_jar_name}",
source => $_amies_jar_url,
require => Accounts::User[$amies_system_username],
ensure => 'present',
path => "${amies::app_dir}/${amies::_jar_name}",
source => $_amies_jar_url,
}
# #############################################################################
......
......@@ -6,26 +6,10 @@
"license": "AGPL-3.0-or-later",
"source": "",
"dependencies": [
{
"name": "camptocamp-postfix",
"version_requirement": ">= 1.8.0 < 2.0.0"
},
{
"name": "puppet-archive",
"version_requirement": ">= 3.1.0 < 4.0.0"
},
{
"name": "puppetlabs-apt",
"version_requirement": ">= 7.0.0 < 8.0.0"
},
{
"name": "puppetlabs-accounts",
"version_requirement": ">= 4.1.0 < 5.0.0"
},
{
"name": "puppetlabs-concat",
"version_requirement": ">= 4.7.0 < 7.0.0"
},
{
"name": "puppetlabs-postgresql",
"version_requirement": ">= 6.1.0 < 7.0.0"
......
......@@ -6,18 +6,17 @@ describe 'amies' do
let(:facts) do
os_facts
end
let(:param) do
let(:params) do
{
smtp_host: 'smtp.example.org',
smtp_port: 587,
smtp_user_name: 'katebush@example.org',
smtp_user_passwd: 'RunningUpThatHill!',
smtp_root_mail_recipient: 'sysadmin@example.org',
amies_app_dir: '/home/amies/AMIES',
amies_picture_dir: '/home/amies/AMIES-pictures',
amies_security_key: '0123654789abcdefghijklm',
amies_job_name: 'myJob',
amies_db_user_password: 'S3cr#TPassw0rdz',
app_dir: '/home/amies/AMIES',
picture_dir: '/home/amies/AMIES-pictures',
security_key: '0123654789abcdefghijklm',
ci_job_name: 'myJob',
db_user_password: 'S3cr#TPassw0rdz',
}
end
......
......@@ -4,16 +4,16 @@ After=syslog.target
[Service]
User=amies
ExecStart=/usr/bin/java -jar "<%= $amies::amies_app_dir %>/<%= $amies::amies_jar_name %>" \
--amies.security.secret-key="<%= $amies::amies_security_key %>" \
--amies.pictures.root-directory="<%= $amies::amies_picture_dir %>" \
ExecStart=/usr/bin/java -jar "<%= $amies::app_dir %>/<%= $amies::_jar_name %>" \
--amies.security.secret-key="<%= $amies::security_key %>" \
--amies.pictures.root-directory="<%= $amies::picture_dir %>" \
--spring.mail.host=<%= $amies::smtp_host %> \
--spring.mail.port=<%= $amies::smtp_port %> \
--spring.mail.username="<%= $amies::smtp_user_name %>" \
--spring.mail.password="<%= $amies::smtp_user_passwd %>" \
--spring.datasource.url="<%= $amies::_amies_jdbc_url %>" \
--spring.datasource.username="<%= $amies::amies_db_user_name %>" \
--spring.datasource.password="<%= $amies::amies_db_user_password %>"
--spring.datasource.username="<%= $amies::db_user_name %>" \
--spring.datasource.password="<%= $amies::db_user_password %>"
SuccessExitStatus=143
[Install]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment