Class: BoringBuilder::Pipeline

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project, client, environment: ENV, progress: DaggerRuby::Progress.silent) ⇒ Pipeline

Returns a new instance of Pipeline.



7
8
9
10
11
12
# File 'lib/boringbuilder/pipeline.rb', line 7

def initialize(project, client, environment: ENV, progress: DaggerRuby::Progress.silent)
  @project = project
  @client = client
  @environment = environment
  @progress = progress
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



5
6
7
# File 'lib/boringbuilder/pipeline.rb', line 5

def client
  @client
end

#progressObject (readonly)

Returns the value of attribute progress.



5
6
7
# File 'lib/boringbuilder/pipeline.rb', line 5

def progress
  @progress
end

#projectObject (readonly)

Returns the value of attribute project.



5
6
7
# File 'lib/boringbuilder/pipeline.rb', line 5

def project
  @project
end

Instance Method Details

#buildObject

Raises:



14
15
16
17
18
19
# File 'lib/boringbuilder/pipeline.rb', line 14

def build
  container = yield self
  raise ConfigurationError, "The custom pipeline must return a Dagger container" unless container

  sync_step(container, "Build application")
end

#container(image = nil) ⇒ Object



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

def container(image = nil)
  result = client.container(container_options)
  image ? result.from(image) : result
end

#exec(container, command, name:, workdir: project.application_path, **options) ⇒ Object

Raises:



60
61
62
63
64
65
66
# File 'lib/boringbuilder/pipeline.rb', line 60

def exec(container, command, name:, workdir: project.application_path, **options)
  arguments = Array(command).map(&:to_s)
  raise ConfigurationError, "step command cannot be empty" if arguments.empty?

  result = execute(container.with_workdir(workdir.to_s), arguments, options)
  sync_step(result, name, output: -> { command_output(result) })
end

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



30
31
32
# File 'lib/boringbuilder/pipeline.rb', line 30

def mise(tools: {}, image: Mise::DEFAULT_IMAGE, workdir: project.application_path)
  Mise.new(project, self).container(tools: tools, image: image, workdir: workdir)
end

#run(container, command, cache:, at: nil, entry: nil, workdir: project.application_path, sharing: :LOCKED, name: "Run cached step", **options) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/boringbuilder/pipeline.rb', line 34

def run(container, command, cache:, at: nil, entry: nil, workdir: project.application_path, sharing: :LOCKED,
        name: "Run cached step", **options)
  arguments = Array(command).map(&:to_s)
  mounts = normalize_mounts(cache, at, entry)
  validate_step!(arguments, mounts)

  remote_cache = BoringCache.new(project, client, environment: @environment)
  container = container.with_workdir(workdir.to_s)

  result, executed = if remote_cache.enabled?
                       container = remote_cache.prepare(container, workdir: workdir)
                       command = if entry
                                   remote_cache.wrap(arguments, entry: entry.to_s)
                                 else
                                   remote_cache.wrap_mounts(arguments, mounts)
                                 end
                       command_result = execute(container, command, options)
                       final_result = entry ? command_result : remove_directories(command_result, mounts.values)
                       [final_result, command_result]
                     else
                       run_with_local_cache(container, arguments, mounts, sharing, options)
                     end

  sync_step(result, name, output: -> { command_output(executed) })
end

#sourceObject



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

def source
  project.source(client)
end

#step(name, container) ⇒ Object

Raises:



68
69
70
71
72
73
# File 'lib/boringbuilder/pipeline.rb', line 68

def step(name, container)
  result = yield container
  raise ConfigurationError, "The pipeline step must return a Dagger container" unless result

  sync_step(result, name)
end