Skip to content

Commit

Permalink
Merge pull request #2409 from jeff1evesque/feature-2349
Browse files Browse the repository at this point in the history
#2349: Modularize puppet logic into classes
  • Loading branch information
jeff1evesque committed Mar 17, 2016
2 parents 0e027ff + 41cdd96 commit 1ec88d6
Show file tree
Hide file tree
Showing 68 changed files with 817 additions and 491 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/interface/static/js/
/interface/static/css/
/interface/static/img/
/puppet/modules/
/puppet/environment/development/modules_contrib/
/test/.cache
/test/programmatic_interface/.cache
/test/programmatic_interface/__pycache__
Expand Down
50 changes: 30 additions & 20 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,18 @@ Vagrant.configure(2) do |config|
exec "vagrant #{ARGV.join(' ')}"
end

## ensure puppet/modules directory on the host before 'vagrant up'
## ensure puppet modules directory on the host before 'vagrant up'
config.trigger.before :up do
run 'mkdir -p puppet/modules'
run 'mkdir -p puppet/environment/development/modules'
run 'mkdir -p puppet/environment/development/modules_contrib'
end

## Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "ubuntu/trusty64"

## Update latest version of puppet
config.vm.provision :shell, :path => "puppet/scripts/puppet_updater.sh"
config.vm.provision :shell, :path => "puppet/environment/development/scripts/puppet_updater.sh"

## Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
Expand All @@ -46,68 +47,77 @@ Vagrant.configure(2) do |config|
config.vm.network "forwarded_port", guest: 443, host: 8585

## Run r10k
config.r10k.puppet_dir = 'puppet'
config.r10k.puppetfile_path = 'puppet/Puppetfile'
config.r10k.puppet_dir = 'puppet/environment/development'
config.r10k.puppetfile_path = 'puppet/environment/development/Puppetfile'

## Custom Manifest: install needed packages
#
# Note: future parser allow array iteration in the puppet manifest
config.vm.provision "puppet" do |puppet|
puppet.manifests_path = "puppet/manifests"
puppet.manifests_path = "puppet/environment/development/manifests"
puppet.manifest_file = "install_packages.pp"
puppet.module_path = "puppet/modules"
puppet.module_path = ['puppet/environment/development/modules_contrib', 'puppet/environment/development/modules']
puppet.options = ["--parser", "future"]
end

## Custom Manifest: build scikit-learn
config.vm.provision "puppet" do |puppet|
puppet.manifests_path = "puppet/manifests"
puppet.manifests_path = "puppet/environment/development/manifests"
puppet.manifest_file = "install_sklearn.pp"
puppet.module_path = "puppet/modules"
puppet.module_path = ['puppet/environment/development/modules_contrib', 'puppet/environment/development/modules']
end

## Custom Manifest: ensure vagrant-mounted event
#
# Note: future parser allow heredoc syntax in the puppet manifest (since puppet 3.5)
config.vm.provision "puppet" do |puppet|
puppet.manifests_path = "puppet/manifests"
puppet.manifests_path = "puppet/environment/development/manifests"
puppet.manifest_file = "vagrant_mounted.pp"
puppet.module_path = "puppet/modules"
puppet.module_path = ['puppet/environment/development/modules_contrib', 'puppet/environment/development/modules']
puppet.options = ["--parser", "future"]
end

## Custom Manifest: install, and configure SQL database
config.vm.provision "puppet" do |puppet|
puppet.manifests_path = "puppet/manifests"
puppet.manifests_path = "puppet/environment/development/manifests"
puppet.manifest_file = "setup_database.pp"
puppet.module_path = "puppet/modules"
puppet.module_path = ['puppet/environment/development/modules_contrib', 'puppet/environment/development/modules']
end

## Custom Manifest: install redis client / server
#
# Note: future parser allow heredoc syntax in the puppet manifest (since puppet 3.5)
config.vm.provision "puppet" do |puppet|
puppet.manifests_path = "puppet/environment/development/manifests"
puppet.manifest_file = "configure_redis.pp"
puppet.module_path = ['puppet/environment/development/modules_contrib', 'puppet/environment/development/modules']
end

## Custom Manifest: start webserver
#
# Note: future parser allow heredoc syntax in the puppet manifest (since puppet 3.5)
config.vm.provision "puppet" do |puppet|
puppet.manifests_path = "puppet/manifests"
puppet.manifests_path = "puppet/environment/development/manifests"
puppet.manifest_file = "start_webserver.pp"
puppet.module_path = "puppet/modules"
puppet.module_path = ['puppet/environment/development/modules_contrib', 'puppet/environment/development/modules']
puppet.options = ["--parser", "future"]
end

## Custom Manifest: configure system (i.e. system timezone)
config.vm.provision "puppet" do |puppet|
puppet.manifests_path = "puppet/manifests"
puppet.manifests_path = "puppet/environment/development/manifests"
puppet.manifest_file = "configure_system.pp"
puppet.module_path = "puppet/modules"
puppet.module_path = ['puppet/environment/development/modules_contrib', 'puppet/environment/development/modules']
end

## Custom Manifest: define webcompilers
#
# Note: future parser allow heredoc sytnax (since puppet 3.5), and allows array
# iteration in the puppet manifest.
config.vm.provision "puppet" do |puppet|
puppet.manifests_path = "puppet/manifests"
puppet.manifests_path = "puppet/environment/development/manifests"
puppet.manifest_file = "compile_asset.pp"
puppet.module_path = "puppet/modules"
puppet.module_path = ['puppet/environment/development/modules_contrib', 'puppet/environment/development/modules']
puppet.options = ["--parser", "future"]
end

Expand All @@ -118,7 +128,7 @@ Vagrant.configure(2) do |config|
run 'rm -Rf interface/static/css'
run 'rm -Rf interface/static/img'
run 'rm -Rf interface/static/js'
run 'rm -Rf puppet/modules'
run 'rm -Rf puppet/environment/development/modules_contrib'
run 'rm -f src/js/.gitignore'
run 'rm -f src/js/select_session.js'
end
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ mod 'apt',
## Install Module: nodejs
mod 'nodejs',
:git => 'git@github.com:puppet-community/puppet-nodejs.git',
:ref => '1.2.0'
:ref => 'v1.3.0'

## Install Module: git
mod 'git',
Expand Down
4 changes: 4 additions & 0 deletions puppet/environment/development/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""@__init__
This file allows the containing directory to be considered a python package,
consisting of python module(s).
"""
48 changes: 48 additions & 0 deletions puppet/environment/development/manifests/compile_asset.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
### compile_asset.pp: install, configure, and run initial compile against
### source files.
###
### Note: the prefix 'package::', corresponds to a puppet convention:
###
### https://github.com/jeff1evesque/machine-learning/issues/2349
###

## install package dependencies
class dependencies {
contain package::webcompilers
}

## configure webcompilers
class configure {
## set dependency
require dependencies

## configure webcompilers
contain compiler::webcompilers
}

## start webcompilers
class start {
## set dependency
require dependencies
require configure

## start compiler(s)
contain compiler::start_sass
contain compiler::start_uglifyjs
contain compiler::start_browserify
contain compiler::start_imagemin
}

## initial compile
class initiate {
## set dependency
require dependencies
require configure
require start

## initial compile
contain compiler::initial_compile
}

## initiate
include initiate
12 changes: 12 additions & 0 deletions puppet/environment/development/manifests/configure_redis.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
### configure_redis.pp: install redis client, and redis server.
###
### Note: the prefix 'package::', corresponds to a puppet convention:
###
### https://github.com/jeff1evesque/machine-learning/issues/2349
###

## install redis client
include redis::client

## install redis-server
include redis::server
9 changes: 9 additions & 0 deletions puppet/environment/development/manifests/configure_system.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
### configure_system.pp: configure system with general requirements.
###
### Note: the prefix 'package::', corresponds to a puppet convention:
###
### https://github.com/jeff1evesque/machine-learning/issues/2349
###

## define system timezone
include system::set_timezone
12 changes: 12 additions & 0 deletions puppet/environment/development/manifests/configure_webserver.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
### configure_webserver.pp: implement webserver, with necessary dependencies.
###
### Note: the prefix 'package::', corresponds to a puppet convention:
###
### https://github.com/jeff1evesque/machine-learning/issues/2349
###

## create log directory
include system::log_directory

## install webserver
include webserver::service
39 changes: 39 additions & 0 deletions puppet/environment/development/manifests/install_packages.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
### install_packages.pp: install general packages.
###
### Note: the prefix 'package::', corresponds to a puppet convention:
###
### https://github.com/jeff1evesque/machine-learning/issues/2349
###

## nodejs, with npm: this cannot be wrapped into a module, and included, as
# needed. Puppet will only allow one instance of this class, regardless of
# of its implementation.
class install_nodejs {
## set dependency
require apt

## install nodejs, with npm
class { 'nodejs':
repo_url_suffix => '5.x',
}
contain nodejs
}

## general packages
class general_packages {
## set dependency
require apt
require install_nodejs

## install packages
contain package::dos2unix
contain package::inotify_tools
contain package::react_presets
contain package::jsonschema
contain package::xmltodict
contain package::six
contain system::webcompiler_directories
}

## initiate
include general_packages
21 changes: 21 additions & 0 deletions puppet/environment/development/manifests/install_sklearn.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
### install_sklearn.pp: install sklearn, with all necessary dependencies.
###
### Note: the prefix 'package::', corresponds to a puppet convention:
###
### https://github.com/jeff1evesque/machine-learning/issues/2349
###

## create '/vagrant/build/' directory
include system::build_directory

## install sklearn dependencies
include package::sklearn_dependencies

## download scikit-learn
include package::sklearn

## build scikit-learn
include sklearn::build_sklearn

## install scikit-learn
include sklearn::install_sklearn
19 changes: 19 additions & 0 deletions puppet/environment/development/manifests/setup_database.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### setup_database.pp: install client, server, bindings, and initialize
### database with required tables.
###
### Note: the prefix 'package::', corresponds to a puppet convention:
###
### https://github.com/jeff1evesque/machine-learning/issues/2349
###

## install mariadb
include database::server

## install mariadb client
include database::client

## install mariad bindings
include database::bindings

## create database tables
include database::database
9 changes: 9 additions & 0 deletions puppet/environment/development/manifests/start_webserver.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
### start_webserver.pp: start webserver.
###
### Note: the prefix 'package::', corresponds to a puppet convention:
###
### https://github.com/jeff1evesque/machine-learning/issues/2349
###

## start webservers
include webserver::start
17 changes: 17 additions & 0 deletions puppet/environment/development/manifests/vagrant_mounted.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
### vagrant_mounted.pp: ensure 'vagrant-mounted' event fires, when '/vagrant'
### shared directory, is mounted within the guest virtual
### machine.
###
### Note: the prefix 'package::', corresponds to a puppet convention:
###
### https://github.com/jeff1evesque/machine-learning/issues/2349
###

## install dos2unix
include package::dos2unix

## configure service
include vagrant::service

## start service
include vagrant::start
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
### Note: the prefix 'compiler::::', corresponds to a puppet convention:
###
### https://github.com/jeff1evesque/machine-learning/issues/2349
###
class compiler::initial_compile {
$sources = [
'jsx',
'img',
'scss',
'js'
]

$sources.each |String $source| {
## variables
$check_files = "if [ \"$(ls -A /vagrant/src/${source}/)\" ];"
$touch_files = "then touch /vagrant/src/${source}/*; fi"

## touch source: ensure initial build compiles every source file.
#
# @touch, changes the modification time to the current system time.
#
# Note: the current inotifywait implementation watches close_write, move,
# and create. However, the source files will already exist before
# this 'inotifywait', since the '/vagrant' directory will already
# have been mounted on the initial build.
#
# Note: every 'command' implementation checks if directory is nonempty,
# then touch all files in the directory, respectively.
exec { "touch-${source}-files":
command => "${check_files} ${touch_files}",
provider => shell,
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
### Note: the prefix 'compiler::', corresponds to a puppet convention:
###
### https://github.com/jeff1evesque/machine-learning/issues/2349
###
class compiler::start_browserify {
service { 'browserify':
ensure => 'running',
enable => true,
}
}
Loading

0 comments on commit 1ec88d6

Please sign in to comment.