Skip to content
This repository has been archived by the owner on Jan 29, 2022. It is now read-only.

Commit

Permalink
Merge pull request #96 from dhollinger/sidekiq
Browse files Browse the repository at this point in the history
Add sidekiq support with puppet and r10k libs
  • Loading branch information
binford2k authored Mar 27, 2019
2 parents e9ebb0c + 9fb0cfa commit b3af89d
Show file tree
Hide file tree
Showing 13 changed files with 205 additions and 136 deletions.
9 changes: 7 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
source 'https://rubygems.org'

puppet_version = ENV['PUPPET_GEM_VERSION'] ||= '6.3.0'

gem 'sinatra'
gem 'sinatra-contrib'
# gem 'sinatra-authentication'
gem 'activerecord', '~> 4.2', '>= 4.2.6', require: 'active_record'
gem 'activerecord', '4.2.11', require: 'active_record'
gem 'bcrypt'
gem 'github_changelog_generator'
gem 'mcollective-client'
gem 'pry'
gem 'puma'
gem 'puppet', puppet_version
gem 'puppet_forge', '2.2.8'
gem 'r10k'
gem 'rake'
gem 'require_all'
gem 'rocket-chat-notifier'
gem 'shotgun'
gem 'sidekiq'
gem 'sinatra-activerecord', require: 'sinatra/activerecord'
gem 'slack-notifier'
gem 'sqlite3'
gem 'sqlite3', '1.3.13'
gem 'thin'
gem 'tux'
gem 'warden'
Expand Down
81 changes: 53 additions & 28 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ GEM
ansi (1.5.0)
arel (6.0.4)
ast (2.4.0)
backports (3.11.4)
backports (3.12.0)
bcrypt (3.1.12)
bond (0.5.1)
builder (3.2.3)
capybara (3.12.0)
capybara (3.15.0)
addressable
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
Expand All @@ -38,7 +38,8 @@ GEM
xpath (~> 3.2)
coderay (1.1.2)
colored (1.2)
concurrent-ruby (1.1.4)
concurrent-ruby (1.1.5)
connection_pool (2.2.2)
coveralls (0.8.22)
json (>= 1.8, < 3)
simplecov (~> 0.16.1)
Expand All @@ -47,7 +48,7 @@ GEM
tins (~> 1.6)
crack (0.4.3)
safe_yaml (~> 1.0.0)
cri (2.15.2)
cri (2.15.3)
colored (~> 1.2)
daemons (1.3.1)
debase (0.2.2)
Expand All @@ -56,11 +57,12 @@ GEM
diff-lcs (1.3)
docile (1.3.1)
eventmachine (1.2.7)
faraday (0.13.1)
facter (2.5.1)
faraday (0.9.2)
multipart-post (>= 1.2, < 3)
faraday-http-cache (2.0.0)
faraday (~> 0.8)
faraday_middleware (0.12.2)
faraday_middleware (0.10.1)
faraday (>= 0.7.4, < 1.0)
fast_gettext (1.1.2)
gettext (3.2.9)
Expand All @@ -79,11 +81,14 @@ GEM
rake (>= 10.0)
retriable (~> 2.1)
hashdiff (0.3.8)
hiera (3.5.0)
hirb (0.7.3)
hocon (1.2.5)
httpclient (2.8.3)
i18n (0.9.5)
concurrent-ruby (~> 1.0)
jaro_winkler (1.5.1)
json (2.1.0)
jaro_winkler (1.5.2)
json (2.2.0)
locale (2.1.2)
log4r (1.1.10)
mcollective-client (2.12.4)
Expand All @@ -93,31 +98,42 @@ GEM
method_source (0.9.2)
mini_mime (1.0.1)
mini_portile2 (2.4.0)
minitar (0.7)
minitar (0.8)
minitest (5.11.3)
multi_json (1.13.1)
multipart-post (2.0.0)
mustermann (1.0.3)
nokogiri (1.9.1)
nokogiri (1.10.2)
mini_portile2 (~> 2.4.0)
octokit (4.13.0)
sawyer (~> 0.8.0, >= 0.5.3)
parallel (1.12.1)
parser (2.5.3.0)
parallel (1.15.0)
parser (2.6.2.0)
ast (~> 2.4.0)
powerpack (0.1.2)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
psych (3.1.0)
public_suffix (3.0.3)
puma (3.12.0)
puppet_forge (2.2.9)
faraday (>= 0.9.0, < 0.14.0)
faraday_middleware (>= 0.9.0, < 0.13.0)
puma (3.12.1)
puppet (6.3.0)
facter (> 2.0.1, < 4)
fast_gettext (~> 1.1.2)
hiera (>= 3.2.1, < 4)
httpclient (~> 2.8)
locale (~> 2.1)
multi_json (~> 1.10)
puppet-resource_api (~> 1.5)
semantic_puppet (~> 1.0)
puppet-resource_api (1.8.1)
hocon (>= 1.0)
puppet_forge (2.2.8)
faraday (~> 0.9.0)
faraday_middleware (>= 0.9.0, < 0.11.0)
gettext-setup (~> 0.11)
minitar
semantic_puppet (~> 1.0)
r10k (3.1.0)
r10k (3.1.1)
colored (= 1.2)
cri (~> 2.15.1)
gettext-setup (~> 0.24)
Expand All @@ -131,6 +147,7 @@ GEM
rack (>= 1.0, < 3)
rainbow (3.0.0)
rake (12.3.2)
redis (4.1.0)
regexp_parser (1.3.0)
require_all (2.0.0)
retriable (2.1.0)
Expand All @@ -156,24 +173,29 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.0)
rubocop (0.61.1)
rubocop (0.66.0)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.5, != 2.5.1.1)
powerpack (~> 0.1)
psych (>= 3.1.0)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.4.0)
unicode-display_width (>= 1.4.0, < 1.6)
ruby-debug-ide (0.6.1)
rake (>= 0.8.1)
ruby-progressbar (1.10.0)
safe_yaml (1.0.4)
safe_yaml (1.0.5)
sawyer (0.8.1)
addressable (>= 2.3.5, < 2.6)
faraday (~> 0.8, < 1.0)
semantic_puppet (1.0.2)
shotgun (0.9.2)
rack (>= 1.0)
sidekiq (5.2.5)
connection_pool (~> 2.2, >= 2.2.2)
rack (>= 1.5.0)
rack-protection (>= 1.5.0)
redis (>= 3.3.5, < 5)
simplecov (0.16.1)
docile (~> 1.1)
json (>= 1.8, < 3)
Expand Down Expand Up @@ -220,22 +242,22 @@ GEM
sinatra (>= 1.2.1)
tzinfo (1.2.5)
thread_safe (~> 0.1)
unicode-display_width (1.4.1)
warden (1.2.7)
rack (>= 1.0)
unicode-display_width (1.5.0)
warden (1.2.8)
rack (>= 2.0.6)
webmock (3.5.1)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff
xpath (3.2.0)
nokogiri (~> 1.8)
yard (0.9.16)
yard (0.9.18)

PLATFORMS
ruby

DEPENDENCIES
activerecord (~> 4.2, >= 4.2.6)
activerecord (= 4.2.11)
bcrypt
capybara
coveralls
Expand All @@ -245,6 +267,8 @@ DEPENDENCIES
mcollective-client
pry
puma
puppet (= 6.3.0)
puppet_forge (= 2.2.8)
r10k
rack-test
rake
Expand All @@ -254,13 +278,14 @@ DEPENDENCIES
rubocop
ruby-debug-ide
shotgun
sidekiq
simplecov
simplecov-console
sinatra
sinatra-activerecord
sinatra-contrib
slack-notifier
sqlite3
sqlite3 (= 1.3.13)
thin
tux
warden
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/api/v1/r10k/environment_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class EnvironmentController < ApplicationController
prefix = get_prefix(data)
branch = get_branch(data)
env = get_env(branch, prefix)
paths = APP_CONFIG.module_paths ||= []

EnvironmentController.helpers R10kHelpers

Expand All @@ -22,7 +23,7 @@ class EnvironmentController < ApplicationController
else
logger.info("Deploying environment #{env}")
# Replace this with Sidekiq
Process.detach(fork { deploy_environment(env, data.deleted) })
Deploy::EnvironmentWorker.perform_async(branch, config, paths, data.deleted)
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/r10k/module_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ModuleController < ApplicationController

module_name = sanitize_input(module_name)
logger.info("Deploying module #{module_name}")
Process.detach(fork { deploy_module(module_name) })
Deploy::ModuleWorker.perform_async(module_name, config)
end

private
Expand Down
55 changes: 55 additions & 0 deletions app/helpers/puppet_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
require 'puppet/generate/type'

# Public methods for executing Puppet methods via the Puppet API.
module PuppetHelpers
# Return an array of modulepaths for the Puppet environment.
#
# @api public
#
# @param name [String] Name of the environment
# @param paths [Array] Array of absolute paths.
#
# @return Array
def self.mod_paths(name, paths)
return paths unless paths.empty?

["/etc/puppetlabs/code/environments/#{name}/modules"]
end

# Create new environment object that will be used for the Puppet Generate types.
#
# @api public
#
# @param name [String] Name of the environment
# @param paths [Array] Array of module path(s) for the environment
#
# @return Puppet::Node::Environment
def self.set_environment(name, paths = [])
module_path = PuppetHelpers.mod_paths(name, paths)

Puppet::Node::Environment.create(name, module_path)
end

# Find the inputs from the environment's modulepath
#
# @api public
#
# @param environment [Puppet::Node::Environment] A Puppet environment object.
#
# @return Array[Puppet::Generate::Type::Input]
def self.find_inputs(environment)
Puppet::Generate::Type.find_inputs(:pcore, environment)
end

# Generate type files from puppet inputs and place them in the output directory.
#
# @api public
#
# @param inputs [Array[Puppet::Generate::Inputs]] Array of Puppet inputs
# @param output [String] Output directory for the generated types.
def self.gen_types(inputs, output)
FileUtils.mkdir(output) unless File.directory?(output)
types = Puppet::Generate::Type.generate(inputs, output)
logger.info(types.message) unless types.nil?
end
end
Loading

0 comments on commit b3af89d

Please sign in to comment.