Class: Dockdev::Context::Rubygems
- Inherits:
-
Object
- Object
- Dockdev::Context::Rubygems
- Includes:
- TR::CondUtils
- Defined in:
- lib/dockdev/context/rubygems.rb
Class Method Summary collapse
Instance Method Summary collapse
- #apply_context(dockdev_config) ⇒ Object
- #find_gemfile ⇒ Object
-
#initialize(path) ⇒ Rubygems
constructor
A new instance of Rubygems.
- #is_context? ⇒ Boolean
Constructor Details
#initialize(path) ⇒ Rubygems
Returns a new instance of Rubygems.
13 14 15 16 17 |
# File 'lib/dockdev/context/rubygems.rb', line 13 def initialize(path) @path = path @mounts = {} @ports = {} end |
Class Method Details
Instance Method Details
#apply_context(dockdev_config) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/dockdev/context/rubygems.rb', line 27 def apply_context(dockdev_config) ddConf = dockdev_config if not_empty?(ddConf) # # looking at source code # https://github.com/rubygems/rubygems/blob/master/bundler/lib/bundler/shared_helpers.rb#L246 # seems this is the way to set root for Bundler # ENV['BUNDLE_GEMFILE'] = find_gemfile.first if not_empty?(ENV['BUNDLE_GEMFILE']) cmd = ["echo 'alias be = \"bundle exec\"' >> /etc/bash.bashrc"] Bundler.load.dependencies.each do |d| if not d.source.nil? src = d.source if src.path.to_s != "." pathInsideDocker = File.join(ddConf.workdir, d.name) ddConf.add_mount(src.path..to_s,pathInsideDocker) # following line assumed 'bundle' program already installed inside the image cmd << "bundle config --global local.#{d.name} #{pathInsideDocker}" end end end if not_empty?(cmd) script = ["#!/bin/bash"] script << "if ! command -v bundle &> /dev/null" script << " echo \"Command 'bundle' is available!\"" script.concat(cmd.collect { |e| " #{e}"}) script << "then" script << " echo \"Command 'bundle' not available\"" #script << " exit 1" script << "fi" File.open("rubygems_init.sh","w") do |f| f.write script.join("\n") end ddConf.append_Dockerfile("COPY rubygems_init.sh /tmp/rubygems_init.sh") ddConf.append_Dockerfile("RUN chmod +x /tmp/rubygems_init.sh && /tmp/rubygems_init.sh") end end end ddConf end |
#find_gemfile ⇒ Object
23 24 25 |
# File 'lib/dockdev/context/rubygems.rb', line 23 def find_gemfile Dir.glob(File.join(@path,"Gemfile")) end |
#is_context? ⇒ Boolean
19 20 21 |
# File 'lib/dockdev/context/rubygems.rb', line 19 def is_context? find_gemfile.length > 0 end |