Skip to content

Commit

Permalink
Allow extra runtime deps to be defined when using prune_bundler
Browse files Browse the repository at this point in the history
  • Loading branch information
daveallie committed Jul 3, 2018
1 parent 7f71af4 commit 6f23e69
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions examples/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@

# prune_bundler

# Extra gems to be loaded when the environment bundler context is pruned.
# Only applies if prune_bundler is used.

# extra_runtime_dependencies ['gem_name_1', 'gem_name_2']

# Preload the application before starting the workers; this conflicts with
# phased restart feature. (off by default)

Expand Down
4 changes: 4 additions & 0 deletions lib/puma/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ def setup_options
user_config.prune_bundler
end

o.on "--extra-runtime-dependencies GEM1,GEM2", "Defines any extra needed gems when using --prune-bundler" do |arg|
c.extra_runtime_dependencies arg.split(',')
end

o.on "-q", "--quiet", "Do not log requests internally (default true)" do
user_config.quiet
end
Expand Down
9 changes: 9 additions & 0 deletions lib/puma/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,15 @@ def prune_bundler(answer=true)
@options[:prune_bundler] = answer
end

# When using prune_bundler, if extra runtime dependencies need to be loaded to
# initialize your app, then this setting can be used.
#
# For each gem's name passed, that gem will be loaded when the environment
# is pruned.
def extra_runtime_dependencies(answer = [])
@options[:extra_runtime_dependencies] = Array(answer)
end

# Additional text to display in process listing
def tag(string)
@options[:tag] = string.to_s
Expand Down
9 changes: 9 additions & 0 deletions lib/puma/launcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,15 @@ def prune_bundler
"#{d.name}:#{spec.version.to_s}"
end

@options[:extra_runtime_dependencies].each do |d_name|
spec = Bundler.rubygems.loaded_specs(d_name) rescue nil
if spec
deps << "#{d_name}:#{spec.version.to_s}"
else
log "* Couldn't to load extra dependency: #{d_name}"
end
end

log '* Pruning Bundler environment'
home = ENV['GEM_HOME']
Bundler.with_clean_env do
Expand Down

0 comments on commit 6f23e69

Please sign in to comment.