Class: Kuby::Docker::BundlerPhase

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

Constant Summary collapse

DEFAULT_GEMFILE =

extend T::Sig

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

Instance Attribute Summary collapse

Attributes inherited from Layer

#environment

Instance Method Summary collapse

Constructor Details

#initialize(environment) ⇒ BundlerPhase

T::Sig::WithoutRuntime.sig { params(environment: Environment).void }



40
41
42
43
44
45
46
47
48
# File 'lib/kuby/docker/bundler_phase.rb', line 40

def initialize(environment)
  super

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

Instance Attribute Details

#executableObject

T::Sig::WithoutRuntime.sig { returns(T.nilable(String)) }



34
35
36
# File 'lib/kuby/docker/bundler_phase.rb', line 34

def executable
  @executable
end

#gemfileObject

T::Sig::WithoutRuntime.sig { returns(T.nilable(String)) }



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

def gemfile
  @gemfile
end

#versionObject

T::Sig::WithoutRuntime.sig { returns(T.nilable(String)) }



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

def version
  @version
end

#withoutObject

T::Sig::WithoutRuntime.sig { returns(T.nilable(T::Array)) }



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

def without
  @without
end

Instance Method Details

#apply_to(dockerfile) ⇒ Object

T::Sig::WithoutRuntime.sig { override.params(dockerfile: Dockerfile).void }



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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/kuby/docker/bundler_phase.rb', line 51

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

  host_path = Pathname(environment.docker.app_root_path)
  container_path = Pathname(dockerfile.current_workdir).join(environment.docker.app_root_path)

  dockerfile.run('gem', 'install', 'bundler', '-v', v)

  dockerfile.copy(host_path.join(gf), container_path.join(gf))
  dockerfile.copy(host_path.join(lf), container_path.join(lf))
  @gemfiles.each do |file|
    dockerfile.copy(host_path.join(file), container_path.join(file))
    extra_lf = host_path.join("#{file}.lock")

    if extra_lf.exist?
      dockerfile.copy(extra_lf, container_path.join("#{file}.lock"))
    end
  end

  dockerfile.env("BUNDLE_GEMFILE=#{container_path.join(gf)}")

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

  dockerfile.run(
    executable || 'bundle', 'lock', '--lockfile', container_path.join(lf)
  )

  dockerfile.run(
    executable || 'bundle', 'install',
    '--jobs', '$(nproc)',
    '--retry', '3'
  )

  # generate binstubs and add the bin directory to our path
  dockerfile.run(executable || 'bundle', 'binstubs', '--all')
  dockerfile.env("PATH=#{container_path.join('bin')}:$PATH")
end

#gemfiles(*paths) ⇒ Object

T::Sig::WithoutRuntime.sig { params(paths: String).void }



95
96
97
# File 'lib/kuby/docker/bundler_phase.rb', line 95

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