Class: Tebako::RuntimeSdk

Inherits:
Object
  • Object
show all
Defined in:
lib/tebako/runtime_sdk.rb

Overview

Creates and installs verified, relocatable runtime SDK archives.

Constant Summary collapse

SCHEMA_VERSION =
1
MANIFEST_PATH =
"tebako-sdk-manifest.json"

Class Method Summary collapse

Class Method Details

.install(archive:, destination:, expected_sha256: nil) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/tebako/runtime_sdk.rb', line 41

def install(archive:, destination:, expected_sha256: nil)
  verify_archive_checksum!(archive, expected_sha256) if expected_sha256
  temporary = "#{File.expand_path(destination)}.#{Process.pid}.#{SecureRandom.hex(6)}.tmp"
  FileUtils.rm_rf(temporary, secure: true)
  FileUtils.mkdir_p(temporary)
  manifest = extract_and_verify(archive, temporary)
  relocate_install(temporary, manifest, destination)
  activate_runtime(temporary, manifest) if manifest["runtime_path"]
  register_environment(temporary)
  publish_install(temporary, destination)
  manifest
ensure
  FileUtils.rm_rf(temporary, secure: true) if temporary && File.exist?(temporary)
end

.pack(output:, components:, descriptor:, runtime_path: nil, build_prefix: nil) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/tebako/runtime_sdk.rb', line 29

def pack(output:, components:, descriptor:, runtime_path: nil, build_prefix: nil)
  entries = collect_entries(components)
  manifest = sdk_manifest(entries, descriptor, runtime_path, build_prefix)
  temporary = "#{output}.#{Process.pid}.#{SecureRandom.hex(6)}.tmp"
  FileUtils.mkdir_p(File.dirname(File.expand_path(output)))
  write_archive(temporary, entries, manifest)
  File.rename(temporary, output)
  output
ensure
  FileUtils.rm_f(temporary) if temporary
end

.sha256(archive) ⇒ Object



56
57
58
59
60
# File 'lib/tebako/runtime_sdk.rb', line 56

def sha256(archive)
  Digest::SHA256.file(archive).hexdigest
rescue SystemCallError => e
  raise Tebako::Error.new("Unable to checksum runtime SDK: #{e.message}", 121)
end

.write_checksum(archive, output: "#{archive}.sha256") ⇒ Object



62
63
64
65
66
67
68
69
70
71
# File 'lib/tebako/runtime_sdk.rb', line 62

def write_checksum(archive, output: "#{archive}.sha256")
  digest = sha256(archive)
  temporary = "#{output}.#{Process.pid}.#{SecureRandom.hex(6)}.tmp"
  FileUtils.mkdir_p(File.dirname(File.expand_path(output)))
  File.binwrite(temporary, "#{digest}  #{File.basename(archive)}\n")
  File.rename(temporary, output)
  output
ensure
  FileUtils.rm_f(temporary) if temporary
end