diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8a1c7c2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +# .gitignore for cd_apache +.yardoc +Gemfile.lock diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..f1c0ec8 --- /dev/null +++ b/Gemfile @@ -0,0 +1,22 @@ +source ENV['GEM_SOURCE'] || 'https://rubygems.org' + +puppetversion = ENV.key?('PUPPET_VERSION') ? ENV['PUPPET_VERSION'] : ['>= 3.3'] +gem 'metadata-json-lint' +gem 'puppet', puppetversion +gem 'puppetlabs_spec_helper', '>= 1.0.0' +gem 'puppet-lint', '>= 1.0.0' +gem 'facter', '>= 1.7.0' +gem 'rspec-puppet' +gem 'puppet-strings' +gem 'rake' +gem 'semantic_puppet' +gem 'rgen' + +# rspec must be v2 for ruby 1.8.7 +if RUBY_VERSION >= '1.8.7' && RUBY_VERSION < '1.9' + gem 'rspec', '~> 2.0' + gem 'rake', '~> 10.0' +else + # rubocop requires ruby >= 1.9 + gem 'rubocop' +end diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..7315488 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,227 @@ +pipeline { + agent { + label 'puppet' + } + + stages { + + stage('pulling master before adding files') { + steps { + sshagent(['0c22dc63-2ae0-4ad5-98e0-65aa0f0f411g']) { + sh '''git config user.name "Jenkins Server" + git config user.email jenkins@confdroid.com + git pull origin master + git checkout -b jenkins ''' + } + } + } + + stage('install required gems') { + steps { + sh 'bundle install' + } + } + + stage('puppet-lint tests') { + steps { + sh '''find . -iname *.pp -exec puppet-lint \\ + --no-class_inherits_from_params_class-check \\ + --no-variable_scope-check \\ + --no-80chars-check \\ + --no-arrow_alignment-check \\ + --no-autoloader_layout-check \\ + --log-format "%{path}:%{line}:%{check}:%{KIND}:%{message}" {} \\;''' + } + } + + stage('puppet parser test') { + steps { + sh '''for file in $(find . -iname \'*.pp\'); do + puppet parser validate --color false --render-as s --modulepath=modules $file || exit 1; + done;''' + } + } + + stage('Puppet ERB template test') { + steps{ + sh '''for file in $(find . -iname \'*.erb\'); + do erb -P -x -T "-" $file | ruby -c || exit 1; + done;''' + } + } + + stage('compiler warnings') { + steps { + warnings canComputeNew: false, canResolveRelativePaths: false, consoleParsers: [[parserName: 'Puppet-Lint']], defaultEncoding: '', excludePattern: '', healthy: '', includePattern: '', messagesPattern: '', unHealthy: '' + } + } + + stage('update repo structure') { + steps { + sh '''rm -Rf REPOSTRUCTURE.md + echo "$(tree --dirsfirst --charset=ascii .)" > REPOSTRUCTURE.md''' + } + } + + stage('create Puppet documention') { + steps { + sh 'puppet strings' + } + } + + stage('create changelog') { + steps{ + step([$class: 'GitChangelogRecorder', config: [configFile: 'git-changelog-settings.json', createFileTemplateContent: '''

Git Changelog changelog

+ +

+Changelog of Git Changelog. +

+ +{{#tags}} +

{{name}}

+ {{#issues}} + {{#hasIssue}} + {{#hasLink}} +

{{name}} {{issue}} {{title}}

+ {{/hasLink}} + {{^hasLink}} +

{{name}} {{issue}} {{title}}

+ {{/hasLink}} + {{/hasIssue}} + {{^hasIssue}} +

{{name}}

+ {{/hasIssue}} + + + {{#commits}} +{{hash}} {{authorName}} {{commitTime}} +

+

{{{messageTitle}}}

+ +{{#messageBodyItems}} +
  • {{.}}
  • +{{/messageBodyItems}} +

    + {{/commits}} + + {{/issues}} +{{/tags}} +''', createFileTemplateFile: '', createFileUseTemplateContent: true, createFileUseTemplateFile: false, customIssues: [[link: '', name: '', pattern: '', title: ''], [link: '', name: '', pattern: '', title: '']], dateFormat: 'YYYY-MM-dd HH:mm:ss', file: 'CHANGELOG.md', fromReference: '', fromType: 'firstCommit', gitHubApi: '', gitHubApiTokenCredentialsId: '', gitHubIssuePattern: '#([0-9]+)', gitHubToken: '', gitLabApiTokenCredentialsId: '', gitLabProjectName: '', gitLabServer: '', gitLabToken: '', ignoreCommitsIfMessageMatches: '^\\[maven-release-plugin\\].*|^\\[Gradle Release Plugin\\].*|^Merge.*', ignoreCommitsWithoutIssue: false, ignoreTagsIfNameMatches: '', jiraIssuePattern: '\\b[a-zA-Z]([a-zA-Z]+)-([0-9]+)\\b', jiraPassword: '', jiraServer: '', jiraUsername: '', jiraUsernamePasswordCredentialsId: '', mediaWikiPassword: '', mediaWikiTemplateContent: '''__NOTOC__ + += Git Changelog changelog = +Changelog of Git Changelog. + +{{#tags}} +== {{name}} == + {{#issues}} + {{#hasIssue}} + {{#hasLink}} +=== {{name}} [{{link}} {{issue}}] {{title}} === + {{/hasLink}} + {{^hasLink}} +=== {{name}} {{issue}} {{title}} === + {{/hasLink}} + {{/hasIssue}} + {{^hasIssue}} +=== {{name}} === + {{/hasIssue}} + + {{#commits}} +[https://gitlab.puppetsoft.com/12WW1160/git-changelog-lib/commit/{{hash}} {{hash}}] {{authorName}} {{commitTime}} + +\'\'\'{{{messageTitle}}}\'\'\' + +{{#messageBodyItems}} + * {{.}} +{{/messageBodyItems}} + + {{/commits}} + + {{/issues}} +{{/tags}} +''', mediaWikiTemplateFile: '', mediaWikiTitle: '', mediaWikiUrl: '', mediaWikiUseTemplateContent: false, mediaWikiUseTemplateFile: false, mediaWikiUsername: '', noIssueName: 'No issue', readableTagName: '/([^/]+?)$', showSummary: false, showSummaryTemplateContent: '''

    Git Changelog changelog

    + +

    +Changelog of Git Changelog. +

    + +{{#tags}} +

    {{name}}

    + {{#issues}} + {{#hasIssue}} + {{#hasLink}} +

    {{name}} {{issue}} {{title}}

    + {{/hasLink}} + {{^hasLink}} +

    {{name}} {{issue}} {{title}}

    + {{/hasLink}} + {{/hasIssue}} + {{^hasIssue}} +

    {{name}}

    + {{/hasIssue}} + + + {{#commits}} +{{hash}} {{authorName}} {{commitTime}} +

    +

    {{{messageTitle}}}

    + +{{#messageBodyItems}} +
  • {{.}}
  • +{{/messageBodyItems}} +

    + + + {{/commits}} + + {{/issues}} +{{/tags}} +''', showSummaryTemplateFile: '', showSummaryUseTemplateContent: false, showSummaryUseTemplateFile: false, subDirectory: '', timeZone: 'UTC', toReference: '', toType: 'master', untaggedName: 'Unreleased', useConfigFile: false, useFile: true, useGitHub: false, useGitHubApiTokenCredentials: false, useGitLab: false, useGitLabApiTokenCredentials: false, useIgnoreTagsIfNameMatches: false, useJira: false, useJiraUsernamePasswordCredentialsId: false, useMediaWiki: false, useReadableTagName: false, useSubDirectory: false]]) + + } + } + + stage('show diff') { + steps { + sh 'git diff' + } + } + + stage('recommit changes to repo') { + steps { + sshagent(['0c22dc63-2ae0-4ad5-98e0-65aa0f0f411g']) { + sh '''git config user.name "Jenkins Server" + git config user.email jenkins@confdroid.com + echo `git add -A && git commit -am "recommit for updates in build $BUILD_NUMBER"` + git push origin HEAD:jenkins''' + } + } + } + + stage('update Gitlab') { + steps { + updateGitlabCommitStatus state: 'success' + } + } + } + + post { + always { + deleteDir() /* clean up our workspace */ + } + success { + echo 'Pipeline finished successfully!' + } + unstable { + echo 'I am unstable :/' + } + failure { + echo 'I failed :(' + step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: 'support@confdroid.com', sendToIndividuals: true]) + } + changed { + echo 'Things were different before...' + mail bcc: '', body: "Pipeline Job '${JOB_NAME}' has changed, please verify.", cc: '', from: '', replyTo: '', subject: "Pipeline Job '${JOB_NAME}' has changed", to: 'support@confdroid.com' + } + } +} diff --git a/README.md b/README.md index 90a98d5..c3e30aa 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ |Repo Name| version | Build Status| |---|---|---|---| -|`cd_apache`| 0.0.0.2 | [![Build Status](https://jenkins.puppetsoft.com/buildStatus/icon?job=cd_apache)](https://jenkins.puppetsoft.com/job/cd_apache/)| +|`cd_apache`| 0.0.1.0 | [![Build Status](https://jenkins.puppetsoft.com/buildStatus/icon?job=cd_apache)](https://jenkins.puppetsoft.com/job/cd_apache/)| ### Synopsis `Apache httpd` is a very powerful and widely used web server. @@ -32,39 +32,15 @@ ### Features * install required binaries and dependencies * manage user settings (optional) -* manage directory structure +* manage directory structure (optional) * manage configuration files (optional): * file system permissions * selinux context * manage the service ### Repo Structure +Repostructure as been moved to REPOSTRUCTURE.md -``` -. -|-- lib -|-- manifests -| |-- main -| | `-- config.pp -| |-- server -| | |-- config.pp -| | |-- dirs.pp -| | |-- files.pp -| | |-- install.pp -| | |-- service.pp -| | `-- user.pp -| |-- init.pp -| `-- params.pp -|-- templates -| |-- autoindex_conf.erb -| |-- httpd_conf.erb -| |-- magic.erb -| |-- ssl_conf.erb -| |-- userdir_conf.erb -| `-- welcome.conf -|-- CHANGELOG.md -`-- README.md -``` ### Dependencies All dependencies must be included in the catalogue. diff --git a/manifests/init.pp b/manifests/init.pp index dcb299a..0e7c333 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -19,9 +19,8 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . +# @summary Initialze the cd_apache Puppet module. ############################################################################## - - class cd_apache { include cd_apache::params } diff --git a/manifests/main/config.pp b/manifests/main/config.pp index d92087b..4e18fcc 100644 --- a/manifests/main/config.pp +++ b/manifests/main/config.pp @@ -19,9 +19,8 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . +# @summary configure the module classes to be used. ############################################################################## - - class cd_apache::main::config ( ) inherits cd_apache::params { diff --git a/manifests/params.pp b/manifests/params.pp index 86cc938..caee414 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -19,8 +19,42 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . +# @summary This class holds all parameters for the cd_apache module, which are +# inherited by all classes except defines. +# @param [string] pkg_ensure Specify which +# [package type] (https://confdroid.com/2017/05/puppet-type-package/) +# to use, i.e. `latest`, `present` or `absent`. +# @param [boolean] ae_manage_user Whether or not to manage details for the +# httpd service user. This is generally only required when using httpd on +# a number of servers sharing storage resources, i.e. NFS, where UID and GID +# settings must be same accross all nodes. +# @param [string] ae_user_name Specify the user name for the httpd user. +# only active if `ae_manage_user` is set to true. +# @param [string] ae_user_uid Specify the UID for teh httpd service user. +# only active if `ae_manage_user` is set to true. +# @param [string] ae_u_comment Specify the user comment for /etc/passwd. +# Shows up in email notofications as sender informations. +# only active if `ae_manage_user` is set to true. +# @param [string] ae_u_groups Specify any secondary groups the httpd service +# user shoould be in. Must not contain teh primary group. +# only active if `ae_manage_user` is set to true. +# @param [string] ae_user_home Specify the home of the httpd service user. +# only active if `ae_manage_user` is set to true. +# @param [string] ae_user_shell Specify the shell for teh httpd service user, +# which normally should not be allowed to log in . +# only active if `ae_manage_user` is set to true. +# @param [boolean] ae_manage_cfg Whether or not to manage the httpd +# configuration. httpd is very often a sub system used by many other services, +# and the required configuration depends on the use case. If using httpd as +# sub-service ( i.e. for phpmyadmin, Nagios etc.), the main configuration +# should be done on that end, not in cd_apache. IN that case, set `ae_manage_cfg` +# to `false`. +# @param [boolean] ae_manage_dirs Whether or not main directories required +# to run httpd should be managed. Tyically this should be set to true. +# @param [boolean] ae_allow_user_dirs Whether or not to allow user directories +# should be allowed to share content through httpd. Usually this is a security +# problem and as such should be disabled. ############################################################################## - class cd_apache::params ( $pkg_ensure = 'latest', diff --git a/manifests/server/config.pp b/manifests/server/config.pp deleted file mode 100644 index dcf4aaf..0000000 --- a/manifests/server/config.pp +++ /dev/null @@ -1,31 +0,0 @@ -## cd_apache::server::config.pp -# Module name: cd_apache -# Author: Arne Teuke (arne_teuke@confdroid.com) -# License: -# This file is part of cd_apache. -# -# cd_apache is used for providing automatic configuration of -# Apache Webserver. -# Copyright (C) 2014 confdroid (copyright@confdroid.com) -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -############################################################################## - - -class cd_apache::server::config ( - -) inherits cd_apache::params { - - require cd_apache::server::files - -} diff --git a/manifests/server/dirs.pp b/manifests/server/dirs.pp index 07afceb..5cb7387 100644 --- a/manifests/server/dirs.pp +++ b/manifests/server/dirs.pp @@ -19,9 +19,9 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . +# @summary Manage all aspects of the directory structure required for the +# httpd service. ############################################################################## - - class cd_apache::server::dirs ( ) inherits cd_apache::params { diff --git a/manifests/server/files.pp b/manifests/server/files.pp index 0741bba..e8cd667 100644 --- a/manifests/server/files.pp +++ b/manifests/server/files.pp @@ -19,9 +19,8 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . +# @summary Manage all aspects for the httpd configuration, if enabled. ############################################################################## - - class cd_apache::server::files ( ) inherits cd_apache::params { diff --git a/manifests/server/install.pp b/manifests/server/install.pp index c930ed8..c56b022 100644 --- a/manifests/server/install.pp +++ b/manifests/server/install.pp @@ -19,9 +19,8 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . +# @summary Install required binaries ############################################################################## - - class cd_apache::server::install ( ) inherits cd_apache::params { diff --git a/manifests/server/service.pp b/manifests/server/service.pp index 6da5b0c..e69a126 100644 --- a/manifests/server/service.pp +++ b/manifests/server/service.pp @@ -19,8 +19,8 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . +# @summary manage the httpd service. ############################################################################## - class cd_apache::server::service ( ) inherits cd_apache::params { diff --git a/manifests/server/user.pp b/manifests/server/user.pp index 408b826..1114034 100644 --- a/manifests/server/user.pp +++ b/manifests/server/user.pp @@ -19,8 +19,8 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . +# @summary manage all aspects of the httpd service user, if enabled ############################################################################## - class cd_apache::server::user ( ) inherits cd_apache::params {