Skip to content

Commit

Permalink
Adding Jenkins Infrastructure Demo (#55)
Browse files Browse the repository at this point in the history
* Adding Jenkins, which uses Docker

* adding missing spec tests

* update jenkins module

* adding rbenv, windows_env

* bump acl module to latest

* adding puppetlabs-service

* adding resource module

* test

* Adding reboot for ruby pre-reqs on Windows

* Rename Rubydev to PuppetDev; Use PDK for Windows

* cleanup data

* Fixing Lint issues

* Updating lint errors

* Fix pathing

* Updating Profile::App::Docker Spec to fail Windows
  • Loading branch information
ipcrm authored Jan 8, 2018
1 parent 3270ad8 commit 8f7bb3d
Show file tree
Hide file tree
Showing 23 changed files with 415 additions and 22 deletions.
25 changes: 18 additions & 7 deletions Puppetfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ forge "http://forge.puppetlabs.com"
# Modules from the Puppet Forge
# Versions should be updated to be the latest at the time you start
mod 'puppetlabs/exec', '0.1.0'
mod 'puppetlabs-resource', '0.1.0'
mod 'puppetlabs-service', '0.1.3'
mod 'puppetlabs/inifile', '1.6.0'
mod "puppetlabs/stdlib", '4.17.0'
mod 'puppetlabs-ciscopuppet', '1.7.0'
mod "puppetlabs/concat", '4.0.0'
mod 'puppetlabs-acl', '1.1.2'
mod 'puppetlabs-acl', '2.0.1'
mod 'puppetlabs/apache', '2.3.0'
mod 'puppetlabs/aws', '2.0.0'
mod 'puppetlabs/azure', '1.1.1'
mod 'puppetlabs-chocolatey', '2.0.2'
mod 'puppetlabs/dism', '1.2.0'
mod 'puppetlabs/docker_platform', '2.2.1'
mod 'puppetlabs/dsc', '1.3.0'
mod 'puppetlabs/firewall', '1.8.2'
mod 'puppetlabs/git', '0.5.0'
Expand All @@ -35,19 +36,19 @@ mod 'puppetlabs/vcsrepo', '1.5.0'
mod 'puppetlabs/sqlserver', '1.2.0'
mod 'puppetlabs-apt', '4.1.0'
mod 'puppetlabs-facter_task', '0.1.3'
mod 'puppetlabs-docker', '1.0.1'
mod 'puppetlabs-transition', '0.1.1'

# Forge Community Modules
mod 'jfryman-selinux', '0.4.0'
mod 'ghoneycutt-ssh', '3.52.0'
mod 'camptocamp-archive', '0.9.0'
mod 'garethr/docker', '5.3.0'
mod 'puppet-archive', '2.0.0'
mod 'trlinkin/domain_membership', '1.1.2'
mod 'ipcrm/echo', '0.1.3'
mod 'stahnma/epel', '1.2.2'
mod 'aristanetworks-eos', '1.5.0'
mod 'puppet-hiera', '3.3.0'

mod 'rtyler/jenkins', '1.7.0'
mod 'aristanetworks-netdev_stdlib_eos', '1.2.0'
mod 'WhatsARanjit/node_manager', '0.4.2'
mod 'cyberious/pget', '1.1.0'
Expand All @@ -59,7 +60,6 @@ mod 'thias-sysctl', '1.0.6'
mod 'reidmv/unzip', '0.1.2'
mod 'andulla/vsphere_conf', '0.0.9'
mod 'biemond/wildfly', '2.0.3'
mod 'puppet/windows_env', '2.3.0'
mod 'puppet/windows_firewall', '1.1.0'
mod 'cyberious/windows_java', '1.0.2'
mod 'puppet-windowsfeature', '2.1.0'
Expand All @@ -79,6 +79,9 @@ mod 'puppet-nginx', '0.7.1'
mod 'bodgit-rngd', '2.0.0'
mod 'jonono-auditpol', '0.1.2'
mod 'nexcess-auditd', '2.0.0'
mod 'jdowning-rbenv', '2.2.0'
mod 'puppet-windows_env', '2.3.0'
mod 'camptocamp-systemd', '1.1.0'

mod 'tse-tse_facts',
:git => 'https://github.com/puppetlabs/tse-module-tse_facts.git'
Expand All @@ -93,4 +96,12 @@ mod 'rgbank',

mod 'bolt',
:git => 'https://github.com/puppetlabs/bolt.git',
:ref => '0.5.1'
:ref => '0.6.0'

mod 'jenkins',
:git => 'https://github.com/jenkinsci/puppet-jenkins.git',
:ref => '5ab2c8a8207f6351f59706255087c6eef32778d9'

mod 'netstat',
:git => 'https://github.com/ipcrm/ipcrm-netstat.git',
:ref => 'master'
5 changes: 0 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ PuppetLint.configuration.send('disable_class_inherits_from_params_class')
PuppetLint.configuration.send('disable_documentation')
PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp", "bundle/**/*", "vendor/**/*"]

PuppetLint::RakeTask.new :lint do | config |
config.fix = true
end


Rake::Task[:spec_prep].enhance [:generate_fixtures]

desc "Run tests"
Expand Down
10 changes: 10 additions & 0 deletions site/profile/files/app/jenkins/swarm-client-win.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!-- This file is managed by Puppet. -->
<configuration>
<runtime>
<generatePublisherEvidence enabled="false"/>
</runtime>
<startup>
<supportedRuntime version="v2.0.50727"/>
<supportedRuntime version="v4.0"/>
</startup>
</configuration>
Binary file not shown.
2 changes: 1 addition & 1 deletion site/profile/manifests/app/cloudshop.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

case $::kernel {
'windows': {
if $::iis_version == "8.5" {
if $::iis_version == '8.5' {
include profile::app::cloudshop::sqlserver::init
include profile::app::cloudshop::webapp::db
include profile::app::cloudshop::webapp::init
Expand Down
9 changes: 9 additions & 0 deletions site/profile/manifests/app/docker.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class profile::app::docker {

if $::kernel == 'windows' {
fail('Unsupported OS')
}

include ::docker

}
18 changes: 18 additions & 0 deletions site/profile/manifests/app/jenkins/master.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class profile::app::jenkins::master {

if $::kernel == 'windows' {
fail('Unsupported OS')
}

docker::image { 'ipcrm/jenkins_demo':
ensure => present,
image_tag => 'latest',
}

docker::run { 'jenkins_demo':
image => 'ipcrm/jenkins_demo:latest',
ports => ['8080:8080','50000:50000'],
extra_parameters => [ '--restart=always' ],
}

}
39 changes: 39 additions & 0 deletions site/profile/manifests/app/jenkins/slave.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
class profile::app::jenkins::slave (
$master_url = 'http://localhost:8080',
){

include ::profile::platform::baseline

case $::kernel {

'Linux': {
class { '::jenkins::slave':
masterurl => $master_url,
ui_user => 'admin',
ui_pass => 'password',
labels => ['tse-slave-linux','tse-control-repo'],
slave_groups => 'wheel',
}

include ::profile::app::puppetdev
}

'windows': {
class { '::profile::app::jenkins::win_slave':
masterurl => $master_url,
ui_user => 'admin',
ui_pass => 'password',
labels => 'tse-slave-windows',
}

include ::profile::app::puppetdev
}

default:{
fail('Unsupported OS')
}

}


}
144 changes: 144 additions & 0 deletions site/profile/manifests/app/jenkins/win_slave.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
class profile::app::jenkins::win_slave (
$masterurl,
$ui_user,
$ui_pass,
$labels = undef,
$slave_home = 'C:/jenkins',
$slave_version = '2.0',
$client_jar = 'swarm-client-2.0-jar-with-dependencies.jar',
$jenkins_owner = 'jenkins',
$executors = 1,
){

include ::profile::platform::baseline

$client_url = "https://repo.jenkins-ci.org/releases/org/jenkins-ci/plugins/swarm-client/${slave_version}/"

$client_jar_flag = "-jar ${slave_home}/${client_jar}"
$mode_flag = '-mode normal'
$fs_root_flag = "-fsroot ${slave_home}"
$executors_flag = "-executors ${executors}"
$ui_user_flag = "-username ${ui_user}"
$ui_pass_flag = "-password ${ui_pass}"
$slave_alias_flag = "-name ${::fqdn}"
$master_url_flag = "-master ${masterurl}"
$labels_flag = "-labels ${labels}"

package { ['javaruntime','wget']:
ensure => installed,
provider => chocolatey,
}

user { $jenkins_owner:
ensure => present,
home => $slave_home,
password => 'S3cr3tP@$$w0rd',
managehome => true,
groups => ['Administrators'],
comment => 'Jenkins User',
}

file { $slave_home:
ensure => directory,
owner => 'S-1-5-32-544', # BUILTIN\Administrators
group => 'S-1-0-0', # NULL, managed by acl resource below
require => User[$jenkins_owner],
}

acl { $slave_home:
permissions => [
{ identity => 'S-1-5-32-544', rights => [ 'full' ] }, # BUILTIN\Administrators
{ identity => 'S-1-5-18', rights => [ 'full' ] }, # NT AUTHORITY\SYSTEM
{ identity => 'Administrator', rights => [ 'full' ] },
{ identity => $jenkins_owner, rights => [ 'full' ] },
],
inherit_parent_permissions => false,
require => File[$slave_home],
}

exec { 'download-swarm-client':
command => "wget.exe -O ${slave_home}/${client_jar} ${client_url}/${client_jar}",
path => "c:/programdata/chocolatey/bin;${::path}",
creates => "${slave_home}/${client_jar}",
notify => Exec['uninstall-jenkins-service'],
}

file { "${slave_home}/${client_jar}":
ensure => file,
owner => $jenkins_owner,
group => 'S-1-5-32-544', # Administrators
mode => '0775',
require => Exec['download-swarm-client'],
}

# Let's install the service.
file { "${slave_home}/swarm-client.xml":
content => template('profile/app/jenkins/swarm-client-win.xml.erb'),
notify => Exec['uninstall-jenkins-service'],
require => User[$jenkins_owner],
}

file { "${slave_home}/swarm-client.exe.config":
source => 'puppet:///modules/profile/app/jenkins/swarm-client-win.config',
owner => $jenkins_owner,
group => 'S-1-5-32-544', # Administrators
mode => '0775',
notify => Exec['uninstall-jenkins-service'],
require => User[$jenkins_owner],
}

# Its binary, but only 37k. Used to setup a service.
# see: https://github.com/kohsuke/winsw
file { "${slave_home}/swarm-client.exe":
source => 'puppet:///modules/profile/app/jenkins/swarm-client-win.exe',
owner => $jenkins_owner,
group => 'S-1-5-32-544', # Administrators
mode => '0775',
notify => Exec['uninstall-jenkins-service'],
require => [
File["${slave_home}/swarm-client.xml"],
File["${slave_home}/swarm-client.exe.config"],
],
}

exec { 'install-jenkins-service':
path => "c:/windows/system32;${slave_home}",
command => "${slave_home}/swarm-client.exe install",
unless => '$t = (Get-Service jenkins-slave -ErrorAction SilentlyContinue); if (-Not $t){ exit 1 } else { exit 0 }',
provider => powershell,
require => [
Exec['download-swarm-client'],
File["${slave_home}/swarm-client.exe"],
],
}

exec { 'uninstall-jenkins-service':
path => "c:/windows/system32;${slave_home}",
command => 'net stop jenkins-slave & sc.exe delete jenkins-slave',
onlyif => '$t = (Get-Service jenkins-slave -ErrorAction SilentlyContinue); if (-Not $t){ exit 1 } else { exit 0 }',
provider => powershell,
refreshonly => true,
returns => [0, 1],
notify => Exec['install-jenkins-service'],
logoutput => true,
}

windows_env { 'git-on-path':
ensure => present,
variable => 'PATH',
value => [
'C:\Program Files\Git\cmd',
'C:\Program Files (x86)\Git\cmd',
],
mergemode => 'prepend',
require => Package['git'],
}


service { 'jenkins-slave':
ensure => running,
enable => true,
require => Exec['install-jenkins-service'],
}

}
19 changes: 19 additions & 0 deletions site/profile/manifests/app/puppetdev.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class profile::app::puppetdev {

case $::kernel {

'windows': {
contain ::profile::app::puppetdev::windows
}

'Linux': {
contain ::profile::app::puppetdev::linux
}

default: {
fail('Unsupported OS')
}

}

}
14 changes: 14 additions & 0 deletions site/profile/manifests/app/puppetdev/linux.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class profile::app::puppetdev::linux {

$dev_packages = $::osfamily ? {
'RedHat' => ['gcc','gcc-c++','openssl-devel','readline-devel','zlib-devel','cmake'],
'Debian' => ['build-essential','cmake','libssl-dev','zlib1g-dev','libreadline6-dev'],
}

ensure_packages($dev_packages,{ensure => present})

include ::rbenv
rbenv::plugin { 'rbenv/ruby-build': }
rbenv::build { '2.3.1': global => true }

}
13 changes: 13 additions & 0 deletions site/profile/manifests/app/puppetdev/windows.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class profile::app::puppetdev::windows {

package { 'Puppet Development Kit':
ensure => present,
source => 'https://puppet-pdk.s3.amazonaws.com/pdk/1.2.1.0/repos/windows/pdk-1.2.1.0-x64.msi',
provider => 'windows',
}

ensure_packages('git', { ensure => present, provider => 'chocolatey' })

windows_env { 'PATH=C:\Program Files\Puppet Labs\DevelopmentKit\private\ruby\2.1.9\bin': require => Package['Puppet Development Kit'] }

}
2 changes: 1 addition & 1 deletion site/profile/manifests/app/sample_website.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

case $::kernel {
'windows': {
if $::iis_version == "8.5" { include profile::app::sample_website::windows }
if $::iis_version == '8.5' { include profile::app::sample_website::windows }
else { fail('Unsupported kernel detected') }
}
'Linux': { include profile::app::sample_website::linux }
Expand Down
6 changes: 4 additions & 2 deletions site/profile/manifests/platform/baseline/linux/firewall.pp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class profile::platform::baseline::linux::firewall {
class profile::platform::baseline::linux::firewall (
$purge = false,
) {

Firewall {
before => Class['profile::platform::baseline::linux::firewall_post'],
Expand All @@ -8,7 +10,7 @@
class { ['::profile::platform::baseline::linux::firewall_pre', '::profile::platform::baseline::linux::firewall_post']: }

resources { 'firewall':
purge => true,
purge => $purge,
}

include ::firewall
Expand Down
Loading

0 comments on commit 8f7bb3d

Please sign in to comment.