Class: BoringBuilder::Exporters::BoringCache

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project, client, environment: ENV) ⇒ BoringCache

Returns a new instance of BoringCache.



10
11
12
13
14
# File 'lib/boringbuilder/exporters/boring_cache.rb', line 10

def initialize(project, client, environment: ENV)
  @project = project
  @client = client
  @cache = ::BoringBuilder::BoringCache.new(project, client, environment: environment)
end

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



8
9
10
# File 'lib/boringbuilder/exporters/boring_cache.rb', line 8

def cache
  @cache
end

#clientObject (readonly)

Returns the value of attribute client.



8
9
10
# File 'lib/boringbuilder/exporters/boring_cache.rb', line 8

def client
  @client
end

#projectObject (readonly)

Returns the value of attribute project.



8
9
10
# File 'lib/boringbuilder/exporters/boring_cache.rb', line 8

def project
  @project
end

Instance Method Details

#export(asset) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/boringbuilder/exporters/boring_cache.rb', line 29

def export(asset)
  validate!
  publisher = client.container.from(cache.cli_image)
  publisher = cache.prepare_artifact_publisher(publisher)
  path, publisher = mount_asset(publisher, asset)
  output = publisher.with_exec(publish_command(path, asset.kind)).stdout
  artifact = JSON.parse(output).fetch("artifact")
  validate_artifact!(artifact)
  Receipt.new(artifact_id: artifact.fetch("id"), artifact_name: artifact.fetch("name"))
rescue JSON::ParserError, KeyError => e
  raise ExportError, "BoringCache Artifact returned an invalid receipt: #{e.message}"
end

#nameObject



16
# File 'lib/boringbuilder/exporters/boring_cache.rb', line 16

def name = :boringcache

#validate!Object

Raises:



18
19
20
21
22
23
24
25
26
27
# File 'lib/boringbuilder/exporters/boring_cache.rb', line 18

def validate!
  if configuration.artifact_name&.strip == ""
    raise ConfigurationError, "BoringCache Artifact name cannot be empty"
  end
  raise ConfigurationError, "The boringcache exporter requires BORINGCACHE_SAVE_TOKEN" unless cache.save_token?
  return self if cache.workspace_configured?

  raise ConfigurationError,
        "The boringcache exporter requires a workspace environment variable or .boringcache.toml"
end