Class: Kuby::Docker::BundlerPhase

Inherits:
Layer
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/kuby/docker/bundler_phase.rb

Constant Summary collapse

DEFAULT_WITHOUT =
T.let(
  ['development', 'test', 'deploy'].freeze, T::Array[String]
)

Instance Attribute Summary collapse

Attributes inherited from Layer

#environment

Instance Method Summary collapse

Constructor Details

#initialize(environment) ⇒ BundlerPhase

Returns a new instance of BundlerPhase.



33
34
35
36
37
38
39
40
# File 'lib/kuby/docker/bundler_phase.rb', line 33

def initialize(environment)
  super

  @version = T.let(@version, T.nilable(String))
  @gemfile = T.let(@gemfile, T.nilable(String))
  @gemfiles = T.let([], T::Array[String])
  @without = T.let(@without, T.nilable(T::Array[String]))
end

Instance Attribute Details

#gemfileObject

Returns the value of attribute gemfile.



21
22
23
# File 'lib/kuby/docker/bundler_phase.rb', line 21

def gemfile
  @gemfile
end

#versionObject

Returns the value of attribute version.



15
16
17
# File 'lib/kuby/docker/bundler_phase.rb', line 15

def version
  @version
end

#withoutObject

Returns the value of attribute without.



27
28
29
# File 'lib/kuby/docker/bundler_phase.rb', line 27

def without
  @without
end

Instance Method Details

#apply_to(dockerfile) ⇒ Object



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
# File 'lib/kuby/docker/bundler_phase.rb', line 43

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, '.')

  @gemfiles.each do |file|
    dockerfile.copy(file, file)
  end

  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

#gemfiles(*paths) ⇒ Object



76
77
78
# File 'lib/kuby/docker/bundler_phase.rb', line 76

def gemfiles(*paths)
  @gemfiles.concat(paths)
end