Class: Kuby::Docker::BundlerPhase

Inherits:
Phase
  • Object
show all
Defined in:
lib/kuby/docker/bundler_phase.rb

Constant Summary collapse

DEFAULT_WITHOUT =
['development', 'test', 'deploy'].freeze

Instance Attribute Summary collapse

Attributes inherited from Phase

#definition

Instance Method Summary collapse

Methods inherited from Phase

#initialize

Constructor Details

This class inherits a constructor from Kuby::Docker::Phase

Instance Attribute Details

#gemfileObject

Returns the value of attribute gemfile.



6
7
8
# File 'lib/kuby/docker/bundler_phase.rb', line 6

def gemfile
  @gemfile
end

#versionObject

Returns the value of attribute version.



6
7
8
# File 'lib/kuby/docker/bundler_phase.rb', line 6

def version
  @version
end

#withoutObject

Returns the value of attribute without.



6
7
8
# File 'lib/kuby/docker/bundler_phase.rb', line 6

def without
  @without
end

Instance Method Details

#apply_to(dockerfile) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/kuby/docker/bundler_phase.rb', line 8

def apply_to(dockerfile)
  gf = gemfile || default_gemfile
  lf = "#{gf}.lock"
  v = version || default_version
  wo = without || DEFAULT_WITHOUT

  dockerfile.run("gem install bundler -v #{v}")

  # bundle install
  dockerfile.copy(gf, '.')
  dockerfile.copy(lf, '.')

  # set bundle path so docker will cache the bundle
  dockerfile.run('mkdir ./bundle')
  dockerfile.env('BUNDLE_PATH=./bundle')

  unless wo.empty?
    dockerfile.env("BUNDLE_WITHOUT='#{wo.join(' ')}'")
  end

  dockerfile.run(
    'bundle', 'install',
    '--jobs', '$(nproc)',
    '--retry', '3',
    '--gemfile', gf
  )

  # generate binstubs and add the bin directory to our path
  dockerfile.run('bundle binstubs --all')
  dockerfile.env("PATH=./bin:$PATH")
end