Class: Kuby::Docker::YarnPhase

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

Instance Attribute Summary

Attributes inherited from Layer

#environment

Instance Method Summary collapse

Methods inherited from Layer

#initialize

Constructor Details

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

Instance Method Details

#apply_to(dockerfile) ⇒ Object

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



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/kuby/docker/yarn_phase.rb', line 9

def apply_to(dockerfile)
  host_path = environment.docker.app_root_path

  # if more than one file is passed to the COPY directive, the destination must be
  # a directory and must end with a slash
  container_path = ensure_trailing_delimiter(
    File.join(
      dockerfile.current_workdir,
      environment.docker.app_root_path
    )
  )

  if File.exist?(File.join(host_path, 'package.json'))
    # use brackets as a hack to only copy the files if they exist
    dockerfile.copy(
      "#{host_path}/package.json #{host_path}/yarn.loc[k] #{host_path}/.npmr[c] #{host_path}/.yarnr[c]",
      container_path
    )

    dockerfile.run('yarn', 'install', '--cwd', container_path)
  end
end