Class: BoringBuilder::Mise

Inherits:
Object
  • Object
show all
Defined in:
lib/boringbuilder/mise.rb

Constant Summary collapse

DEFAULT_IMAGE =
BoringCache::BUILD_IMAGE
CACHE_PATH =
"/mise/cache"
INSTALL_COMMAND =
%w[mise install].freeze
METADATA_FILES =
%w[mise.toml .mise.toml .tool-versions mise.lock].freeze
ENVIRONMENT =
{
  "MISE_CACHE_DIR" => CACHE_PATH,
  "MISE_DATA_DIR" => "/mise",
  "MISE_INSTALLS_DIR" => "/mise/installs",
  "MISE_SHIMS_DIR" => "/mise/shims",
  "PATH" => "/mise/shims:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project, pipeline) ⇒ Mise

Returns a new instance of Mise.



21
22
23
24
# File 'lib/boringbuilder/mise.rb', line 21

def initialize(project, pipeline)
  @project = project
  @pipeline = pipeline
end

Instance Attribute Details

#pipelineObject (readonly)

Returns the value of attribute pipeline.



19
20
21
# File 'lib/boringbuilder/mise.rb', line 19

def pipeline
  @pipeline
end

#projectObject (readonly)

Returns the value of attribute project.



19
20
21
# File 'lib/boringbuilder/mise.rb', line 19

def project
  @project
end

Instance Method Details

#container(tools: {}, image: DEFAULT_IMAGE, workdir: project.application_path) ⇒ Object



26
27
28
29
# File 'lib/boringbuilder/mise.rb', line 26

def container(tools: {}, image: DEFAULT_IMAGE, workdir: project.application_path)
  base = (pipeline.container(image), at: workdir)
  install(base, tools: tools, workdir: workdir).with_directory(workdir, pipeline.source)
end

#install(container, tools:, workdir:, only: nil) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/boringbuilder/mise.rb', line 31

def install(container, tools:, workdir:, only: nil)
  container = with_environment(container)
  container = container.with_workdir(workdir)
                       .with_new_file("/etc/mise/config.toml", system_config(tools))
  command = [*INSTALL_COMMAND, *Array(only).map(&:to_s)]
  pipeline.run(
    container,
    command,
    cache: "mise",
    at: CACHE_PATH,
    entry: "mise",
    workdir: workdir,
    name: "[build] RUN #{command.join(' ')}"
  )
end

#with_environment(container) ⇒ Object



54
55
56
57
58
# File 'lib/boringbuilder/mise.rb', line 54

def with_environment(container)
  ENVIRONMENT.reduce(container) do |result, (name, value)|
    result.with_env_variable(name, value)
  end
end

#with_project_metadata(container, at: project.application_path) ⇒ Object



47
48
49
50
51
52
# File 'lib/boringbuilder/mise.rb', line 47

def (container, at: project.application_path)
  METADATA_FILES.reduce(container) do |result, name|
    path = project.root.join(name)
    path.file? ? result.with_file("#{at}/#{name}", project.source_file(pipeline.client, name)) : result
  end
end