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

Bugfix for issue #23: Adding info about required JS engine (and do not fail if one is not present) #28

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file, indent by 2 spaces
[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ end

local_gemfile = File.join(File.dirname(__FILE__), 'Gemfile.local')
eval_gemfile local_gemfile if File.exist?(local_gemfile)
eval_gemfile './Gemfile.ruby19' if RUBY_VERSION < '2.0.0'

begin
npmbin = `npm bin`.strip
Expand Down
12 changes: 4 additions & 8 deletions Gemfile.local.example
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@

gem 'pg'
gem 'puma'
# gem 'thin'
gem 'pg' # for PostgreSQL support
gem 'puma' # for multithreaded speed
gem 'therubyracer' # for Javascript uglifier support

# Until released without support for 1.8
gem 'travis', '<= 1.6.11', require: false


# vim:ft=ruby
# vim:ft=ruby
7 changes: 7 additions & 0 deletions Gemfile.ruby19
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env ruby

group :development do
gem 'tins', '~> 1.6.0', require: false
end

# vim:ft=ruby
66 changes: 56 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ puppet-herald gem
[![Build Status](https://img.shields.io/travis/wavesoftware/gem-puppet-herald/master.svg)](https://travis-ci.org/wavesoftware/gem-puppet-herald) [![Dependency Status](https://gemnasium.com/wavesoftware/gem-puppet-herald.svg)](https://gemnasium.com/wavesoftware/gem-puppet-herald) [![Coverage Status](https://img.shields.io/coveralls/wavesoftware/gem-puppet-herald/master.svg)](https://coveralls.io/r/wavesoftware/gem-puppet-herald?branch=master) [![Code Climate](https://codeclimate.com/github/wavesoftware/gem-puppet-herald/badges/gpa.svg?branch=master)](https://codeclimate.com/github/wavesoftware/gem-puppet-herald) [![Inline docs](http://inch-ci.org/github/wavesoftware/gem-puppet-herald.svg?branch=master)](http://inch-ci.org/github/wavesoftware/gem-puppet-herald)

##### Development branch
[![Build Status](https://img.shields.io/travis/wavesoftware/gem-puppet-herald/develop.svg)](https://travis-ci.org/wavesoftware/gem-puppet-herald) [![Dependency Status](https://gemnasium.com/wavesoftware/gem-puppet-herald.svg)](https://gemnasium.com/wavesoftware/gem-puppet-herald) [![Coverage Status](https://img.shields.io/coveralls/wavesoftware/gem-puppet-herald/develop.svg)](https://coveralls.io/r/wavesoftware/gem-puppet-herald?branch=develop) [![Code Climate](https://codeclimate.com/github/wavesoftware/gem-puppet-herald/badges/gpa.svg?branch=develop)](https://codeclimate.com/github/wavesoftware/gem-puppet-herald) [![Inline docs](http://inch-ci.org/github/wavesoftware/gem-puppet-herald.svg?branch=develop)](http://inch-ci.org/github/wavesoftware/gem-puppet-herald)
[![Build Status](https://img.shields.io/travis/wavesoftware/gem-puppet-herald/develop.svg)](https://travis-ci.org/wavesoftware/gem-puppet-herald) [![Dependency Status](https://gemnasium.com/wavesoftware/gem-puppet-herald.svg)](https://gemnasium.com/wavesoftware/gem-puppet-herald) [![Coverage Status](https://img.shields.io/coveralls/wavesoftware/gem-puppet-herald/develop.svg)](https://coveralls.io/r/wavesoftware/gem-puppet-herald?branch=develop) [![Code Climate](https://codeclimate.com/github/wavesoftware/gem-puppet-herald/badges/gpa.svg?branch=develop)](https://codeclimate.com/github/wavesoftware/gem-puppet-herald) [![Inline docs](http://inch-ci.org/github/wavesoftware/gem-puppet-herald.svg?branch=develop)](http://inch-ci.org/github/wavesoftware/gem-puppet-herald)

Overview
--------
Expand All @@ -19,25 +19,70 @@ Herald is a puppet report processor. He provides a gateway for consuming puppet

![A logs of single report](https://raw.githubusercontent.com/wavesoftware/gem-puppet-herald/gh-pages/images/logs.png)

Puppet module
Docker container
-----

There is/will be a puppet module that handle installation and configuration of Herald and prerequisites. Installing configuring and running with puppet is recommended. If you decided to take that approch check out: https://github.com/wavesoftware/puppet-herald
Installation and usage could be pretty much simplified when you decide to use a Docker container for this application. Docker container is maintained by guys at COI.gov.pl here: https://hub.docker.com/r/coigovpl/herald For more details go to theirs page. Simple usages are pasted below:

Installation, configuration and usage point seen below does not apply to installing with puppet!
#### Run with PostgreSQL docker container

If you like to run Herald with private docker container execute commands below:

```
docker run -d --name=postgres postgres
docker run -d --link postgres -p 11303:11303 --name=herald coigovpl/herald
```

#### Run with remote PostgreSQL

If you like to run Herald with external postgres set appropriate configuration options with environment variables `HERALD_*` similar to:

```
docker run -d \
-e HERALD_POSTGRES_HOST=herald-db.localdomain \
-p 11303:11303 \
--name=herald coigovpl/herald
```

Puppet module (not yet functional)
-----

There is/will be a puppet module that handle installation and configuration of Herald and prerequisites. Installing configuring and running with puppet is recommended. If you decided to take that approach check out: https://github.com/wavesoftware/puppet-herald (not yet available)

Installation, configuration and usage point seen below does not apply to installing with puppet!

Installation
-----

Herald typically should be installed on the same node or in management network of your puppet master. It will listen by default to localhost (this can be changed by `--bind` option). You should take care to properlly secure Herald if its publicly avialable (SSL, Authorization, Access List, Firewalls etc.). This could be easily done with Apache web server. Is approch is taken in puppet module (see above).
Herald typically should be installed on the same node or in management network of your puppet master. It will listen by default to localhost (this can be changed by `--bind` option). You should take care to properly secure Herald if its publicly available (SSL, Authorization, Access List, Firewalls etc.). This could be easily done with Apache web server. This approach is taken in puppet module (see above).

If you decided to install Herald by yourself, issue just:

```shell
sudo gem install puppet-herald
```

###Prerequisites for Herald

To use Herald you should have some Javascript engine installed. This is due to fact that Herald uses a [`uglifier` gem](https://rubygems.org/gems/uglifier) that uses a `execjs` gem and this means you should provide one of supported JS engines:

* [therubyracer](https://github.com/cowboyd/therubyracer) - Google V8
embedded within Ruby
* [therubyrhino](https://github.com/cowboyd/therubyrhino) - Mozilla
Rhino embedded within JRuby
* [Duktape.rb](https://github.com/judofyr/duktape.rb) - Duktape JavaScript interpreter
* [Node.js](http://nodejs.org/)
* Apple JavaScriptCore - Included with Mac OS X
* [Microsoft Windows Script Host](http://msdn.microsoft.com/en-us/library/9bbdkx3k.aspx) (JScript)
* [Google V8](http://code.google.com/p/v8/)

Basically if you have NodeJS installed that means you should be fine. Other wise just install embedded V8 engine like this:

```shell
sudo apt-get install make gcc g++ ruby-dev
sudo gem install therubyracer
```

Configuration
-----

Expand Down Expand Up @@ -104,7 +149,7 @@ puppet-herald \
Configuring puppet master
-------------------------

To send reports to Herald, you need to configure your puppet master to use custom report proccessor. This processor is also automatically configured if you choose to use a puppet module installation version. If not you must configure it by yourself.
To send reports to Herald, you need to configure your puppet master to use custom report processor. This processor is also automatically configured if you choose to use a puppet module installation version. If not you must configure it by yourself.

First install a puppet-herald gem if you didn't do it already on puppet master:

Expand All @@ -118,7 +163,7 @@ If you are running PE, run instead:
sudo /opt/puppet/bin/gem install puppet-herald
```

Then create a file in your puppet module directory (you can get modulepath with command: `puppet config print modulepath`). For example: `<puppet modules>/herald/lib/puppet/reports/herald.rb` with contents:
Then create a file in your puppet module directory (you can get module path with command: `puppet config print modulepath`). For example: `<puppet modules>/herald/lib/puppet/reports/herald.rb` with contents:

```ruby
require 'puppet'
Expand All @@ -141,7 +186,8 @@ require 'puppet-herald/client'
Puppet::Reports.register_report(:herald) do
desc "Process reports via the Herald API."
def process
PuppetHerald::Client.new('master.secure.vm', 8082).process(self)
# Posts a reports to master.secure.vm:11303
PuppetHerald::Client.new('master.secure.vm', 11303).process(self)
end
end
```
Expand Down Expand Up @@ -214,9 +260,9 @@ Contributions are welcome!
To contribute, follow the standard [git flow](http://danielkummer.github.io/git-flow-cheatsheet/) of:

1. Fork it
1. Create your feature branch (`git checkout -b feature/my-new-feature`)
1. Create your feature or bugfix branch (`git checkout -b feature/my-new-feature`)
1. Commit your changes (`git commit -am 'Add some feature'`)
1. Push to the branch (`git push origin feature/my-new-feature`)
1. Push to the origin (`git push origin feature/my-new-feature`)
1. Create new Pull Request

Even if you can't contribute code, if you have an idea for an improvement please open an [issue](https://github.com/wavesoftware/gem-puppet-herald/issues).
1 change: 1 addition & 0 deletions lib/puppet-herald.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

require 'puppet-herald/database'
require 'logger'
require 'logger/colors'

# A module for Herald
module PuppetHerald
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet-herald/app/frontend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def initialize
# Gets an app.html
# @dodgy executed also to raise an exception for testing (application_spec)
def app_html
if PuppetHerald.in_prod?
if PuppetHerald.in_prod? && @js.supports?
minified = '.min'
files = ['/app.min.js']
else
Expand Down
15 changes: 14 additions & 1 deletion lib/puppet-herald/javascript.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ class Javascript
def initialize
@files = nil
@base = 'lib/puppet-herald/public'
begin
require 'uglifier'
@supports = true
rescue ::StandardError => ex
PuppetHerald.errlogger.warn("Cant find Javascript engine. Ugifing of JS app is disabled!!! Please " +
"install one of Javascript engines for ex.: gem install therubyracer (consult README.md file) - #{ex.message}")
@supports = false
end
end

# Checks if app properly supports uglifing JS
# @return [Boolean] true, if supports
def supports?
@supports
end

# Returns a list of JS files to be inserted into main HTML
Expand All @@ -26,7 +40,6 @@ def files
# @param mapname [String] name of source map to be put into uglified JS
# @return [Hash] a hash with uglified JS and source map
def uglify(mapname)
require 'uglifier'
filenames = files
sources = filenames.collect { |file| File.read(PuppetHerald.relative_dir("#{@base}/#{file}")) }
source = sources.join "\n"
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet-herald/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def self.version_prep(desired)
end

# Version for Herald
VERSION = version_prep '0.9.0.pre'
VERSION = version_prep '0.8.2.pre'
# Lincense for Herald
LICENSE = 'Apache-2.0'
# Project name
Expand Down
13 changes: 7 additions & 6 deletions puppet-herald.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ Gem::Specification.new do |gem|
gem.required_ruby_version = '>= 1.9.2'

# Runtime
gem.add_runtime_dependency 'sinatra', '~> 1.4', '>= 1.4.0'
gem.add_runtime_dependency 'sinatra-contrib', '~> 1.4', '>= 1.4.0'
gem.add_runtime_dependency 'sinatra-activerecord', '~> 2.0', '>= 2.0.0'
gem.add_runtime_dependency 'rufus-scheduler', '~> 3.0', '>= 3.0.0'
gem.add_runtime_dependency 'micro-optparse', '~> 1.2', '>= 1.2.0'
gem.add_runtime_dependency 'uglifier', '~> 2.7', '>= 2.7.0'
gem.add_runtime_dependency 'sinatra', '~> 1.4.0'
gem.add_runtime_dependency 'sinatra-contrib', '~> 1.4.0'
gem.add_runtime_dependency 'sinatra-activerecord', '~> 2.0.0'
gem.add_runtime_dependency 'rufus-scheduler', '~> 3.2.0'
gem.add_runtime_dependency 'micro-optparse', '~> 1.2.0'
gem.add_runtime_dependency 'uglifier', '~> 2.7.0'
gem.add_runtime_dependency 'logger-colors', '~> 1.0.0'
end

# vim:ft=ruby