Class: E2B::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/e2b/template.rb

Constant Summary collapse

DEFAULT_BASE_IMAGE =
"e2bdev/base"
false
BASE_STEP_NAME =
"base"
FINALIZE_STEP_NAME =
"finalize"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_context_path: nil, file_ignore_patterns: []) ⇒ Template

Returns a new instance of Template.



438
439
440
441
442
443
444
445
446
447
448
449
450
451
# File 'lib/e2b/template.rb', line 438

def initialize(file_context_path: nil, file_ignore_patterns: [])
  @file_context_path = (file_context_path || default_file_context_path).to_s
  @file_ignore_patterns = Array(file_ignore_patterns)
  @base_image = DEFAULT_BASE_IMAGE
  @base_template = nil
  @registry_config = nil
  @start_cmd = nil
  @ready_cmd = nil
  @force = false
  @force_next_layer = false
  @instructions = []
  @base_source_location = capture_source_location
  @finalization_source_location = nil
end

Class Method Details

.alias_exists(alias_name, api_key: nil, access_token: nil, domain: nil) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/e2b/template.rb', line 31

def alias_exists(alias_name, api_key: nil, access_token: nil, domain: nil)
  credentials = resolve_credentials(api_key: api_key, access_token: access_token)
  http_client = build_http_client(**credentials, domain: resolve_domain(domain))
  http_client.get("/templates/aliases/#{escape_path_segment(alias_name)}")
  true
rescue E2B::NotFoundError
  false
rescue E2B::AuthenticationError => e
  return true if e.status_code == 403

  raise
end

.assign_tags(target_name, tags, api_key: nil, access_token: nil, domain: nil) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/e2b/template.rb', line 44

def assign_tags(target_name, tags, api_key: nil, access_token: nil, domain: nil)
  credentials = resolve_credentials(api_key: api_key, access_token: access_token)
  http_client = build_http_client(**credentials, domain: resolve_domain(domain))
  response = http_client.post("/templates/tags", body: {
    target: target_name,
    tags: normalize_tags(tags)
  })

  Models::TemplateTagInfo.from_hash(response)
end

.build(template, name: nil, alias_name: nil, tags: nil, cpu_count: 2, memory_mb: 1024, disk_size_mb: nil, skip_cache: false, on_build_logs: nil, api_key: nil, access_token: nil, domain: nil, **opts) ⇒ Object



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/e2b/template.rb', line 137

def build(template, name: nil, alias_name: nil, tags: nil, cpu_count: 2, memory_mb: 1024,
          disk_size_mb: nil, skip_cache: false,
          on_build_logs: nil, api_key: nil, access_token: nil, domain: nil, **opts)
  on_build_logs&.call(Models::TemplateLogEntryStart.new(timestamp: Time.now, message: "Build started"))

  build_info = build_in_background(
    template,
    name: name,
    alias_name: alias_name || opts[:alias] || opts["alias"],
    tags: tags,
    cpu_count: cpu_count,
    memory_mb: memory_mb,
    disk_size_mb: disk_size_mb,
    skip_cache: skip_cache,
    on_build_logs: on_build_logs,
    api_key: api_key,
    access_token: access_token,
    domain: domain
  )

  on_build_logs&.call(log_entry("Waiting for logs..."))

  wait_for_build_finish(
    build_info,
    on_build_logs: on_build_logs,
    api_key: api_key,
    access_token: access_token,
    domain: domain
  )

  build_info
ensure
  on_build_logs&.call(Models::TemplateLogEntryEnd.new(timestamp: Time.now, message: "Build finished"))
end

.build_in_background(template, name: nil, alias_name: nil, tags: nil, cpu_count: 2, memory_mb: 1024, disk_size_mb: nil, skip_cache: false, on_build_logs: nil, api_key: nil, access_token: nil, domain: nil, **opts) ⇒ Object



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/e2b/template.rb', line 172

def build_in_background(template, name: nil, alias_name: nil, tags: nil, cpu_count: 2, memory_mb: 1024,
                        disk_size_mb: nil, skip_cache: false, on_build_logs: nil,
                        api_key: nil, access_token: nil, domain: nil, **opts)
  alias_name ||= opts[:alias] || opts["alias"]
  resolved_name = normalize_build_name(name: name, alias_name: alias_name)
  template.send(:force_build!) if skip_cache

  credentials = resolve_credentials(api_key: api_key, access_token: access_token)
  http_client = build_http_client(**credentials, domain: resolve_domain(domain))

  tags_message = Array(tags).any? ? " with tags #{Array(tags).join(', ')}" : ""
  on_build_logs&.call(log_entry("Requesting build for template: #{resolved_name}#{tags_message}"))

  body = {
    name: resolved_name,
    tags: tags,
    cpuCount: cpu_count,
    memoryMB: memory_mb
  }
  body[:diskSizeMB] = disk_size_mb if disk_size_mb
  create_response = http_client.post("/v3/templates", body: body)

  build_info = Models::BuildInfo.new(
    alias_name: resolved_name,
    name: resolved_name,
    tags: create_response["tags"] || create_response[:tags] || [],
    template_id: create_response["templateID"] || create_response[:templateID],
    build_id: create_response["buildID"] || create_response[:buildID],
    build_step_origins: template.send(:build_step_origins)
  )

  on_build_logs&.call(
    log_entry("Template created with ID: #{build_info.template_id}, Build ID: #{build_info.build_id}")
  )

  instructions = template.send(:instructions_with_hash_metadata)
  upload_copy_instructions(
    http_client,
    template,
    build_info,
    instructions,
    on_build_logs: on_build_logs
  )

  on_build_logs&.call(log_entry("All file uploads completed"))
  on_build_logs&.call(log_entry("Starting building..."))

  http_client.post(
    "/v2/templates/#{escape_path_segment(build_info.template_id)}/builds/#{escape_path_segment(build_info.build_id)}",
    body: template.send(:build_payload, instructions)
  )

  build_info
end

.exists(name, api_key: nil, access_token: nil, domain: nil) ⇒ Object



27
28
29
# File 'lib/e2b/template.rb', line 27

def exists(name, api_key: nil, access_token: nil, domain: nil)
  alias_exists(name, api_key: api_key, access_token: access_token, domain: domain)
end

.get_build_status(build_info = nil, logs_offset: nil, api_key: nil, access_token: nil, domain: nil, template_id: nil, build_id: nil) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/e2b/template.rb', line 73

def get_build_status(build_info = nil, logs_offset: nil, api_key: nil, access_token: nil, domain: nil,
                     template_id: nil, build_id: nil)
  resolved_template_id, resolved_build_id = extract_build_identifiers(
    build_info,
    template_id: template_id,
    build_id: build_id,
    build_step_origins: nil
  )

  credentials = resolve_credentials(api_key: api_key, access_token: access_token)
  http_client = build_http_client(**credentials, domain: resolve_domain(domain))
  params = {}
  params[:logsOffset] = logs_offset unless logs_offset.nil?

  response = http_client.get(
    "/templates/#{escape_path_segment(resolved_template_id)}/builds/#{escape_path_segment(resolved_build_id)}/status",
    params: params
  )

  Models::TemplateBuildStatusResponse.from_hash(response)
end

.get_tags(template_id, api_key: nil, access_token: nil, domain: nil) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/e2b/template.rb', line 65

def get_tags(template_id, api_key: nil, access_token: nil, domain: nil)
  credentials = resolve_credentials(api_key: api_key, access_token: access_token)
  http_client = build_http_client(**credentials, domain: resolve_domain(domain))
  response = http_client.get("/templates/#{escape_path_segment(template_id)}/tags")

  Array(response).map { |item| Models::TemplateTag.from_hash(item) }
end

.remove_tags(name, tags, api_key: nil, access_token: nil, domain: nil) ⇒ Object



55
56
57
58
59
60
61
62
63
# File 'lib/e2b/template.rb', line 55

def remove_tags(name, tags, api_key: nil, access_token: nil, domain: nil)
  credentials = resolve_credentials(api_key: api_key, access_token: access_token)
  http_client = build_http_client(**credentials, domain: resolve_domain(domain))
  http_client.delete("/templates/tags", body: {
    name: name,
    tags: normalize_tags(tags)
  })
  nil
end

.to_dockerfile(template) ⇒ Object



23
24
25
# File 'lib/e2b/template.rb', line 23

def to_dockerfile(template)
  template.to_dockerfile
end

.to_json(template, compute_hashes: true) ⇒ Object



19
20
21
# File 'lib/e2b/template.rb', line 19

def to_json(template, compute_hashes: true)
  template.to_json(compute_hashes: compute_hashes)
end

.wait_for_build_finish(build_info = nil, logs_offset: 0, on_build_logs: nil, logs_refresh_frequency: 0.2, api_key: nil, access_token: nil, domain: nil, template_id: nil, build_id: nil, build_step_origins: nil) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/e2b/template.rb', line 95

def wait_for_build_finish(build_info = nil, logs_offset: 0, on_build_logs: nil, logs_refresh_frequency: 0.2,
                          api_key: nil, access_token: nil, domain: nil, template_id: nil, build_id: nil,
                          build_step_origins: nil)
  resolved_template_id, resolved_build_id, resolved_build_step_origins = extract_build_identifiers(
    build_info,
    template_id: template_id,
    build_id: build_id,
    build_step_origins: build_step_origins
  )
  current_logs_offset = logs_offset

  loop do
    status = get_build_status(
      nil,
      logs_offset: current_logs_offset,
      api_key: api_key,
      access_token: access_token,
      domain: domain,
      template_id: resolved_template_id,
      build_id: resolved_build_id
    )

    current_logs_offset += status.log_entries.length
    status.log_entries.each { |entry| on_build_logs.call(entry) } if on_build_logs

    case status.status
    when "building", "waiting"
      sleep_for_build_poll(logs_refresh_frequency)
    when "ready"
      return status
    when "error"
      raise build_error(
        status.reason&.message || "Unknown build error occurred.",
        step: status.reason&.step,
        source_location: build_step_source_location(status.reason&.step, resolved_build_step_origins)
      )
    else
      raise build_error("Unknown build status: #{status.status}")
    end
  end
end

Instance Method Details

#add_mcp_server(servers) ⇒ Object



677
678
679
680
681
682
683
684
685
686
687
# File 'lib/e2b/template.rb', line 677

def add_mcp_server(servers)
  unless @base_template == "mcp-gateway"
    raise build_error(
      "MCP servers can only be added to mcp-gateway template",
      source_location: capture_source_location
    )
  end

  server_list = Array(servers).map(&:to_s)
  run_cmd("mcp-gateway pull #{server_list.join(' ')}", user: "root")
end

#apt_install(packages, no_install_recommends: false) ⇒ Object



665
666
667
668
669
670
671
672
673
674
675
# File 'lib/e2b/template.rb', line 665

def apt_install(packages, no_install_recommends: false)
  package_list = Array(packages).map(&:to_s)
  install_flags = no_install_recommends ? "--no-install-recommends " : ""
  run_cmd(
    [
      "apt-get update",
      "DEBIAN_FRONTEND=noninteractive DEBCONF_NOWARNINGS=yes apt-get install -y #{install_flags}#{package_list.join(' ')}"
    ],
    user: "root"
  )
end

#beta_dev_container_prebuild(devcontainer_directory) ⇒ Object



700
701
702
703
# File 'lib/e2b/template.rb', line 700

def beta_dev_container_prebuild(devcontainer_directory)
  ensure_devcontainer_template!
  run_cmd("devcontainer build --workspace-folder #{devcontainer_directory}", user: "root")
end

#beta_set_dev_container_start(devcontainer_directory) ⇒ Object Also known as: beta_set_devcontainer_start



705
706
707
708
709
710
711
# File 'lib/e2b/template.rb', line 705

def beta_set_dev_container_start(devcontainer_directory)
  ensure_devcontainer_template!
  set_start_cmd(
    "sudo devcontainer up --workspace-folder #{devcontainer_directory} && sudo /prepare-exec.sh #{devcontainer_directory} | sudo tee /devcontainer.sh > /dev/null && sudo chmod +x /devcontainer.sh && sudo touch /devcontainer.up",
    E2B.wait_for_file("/devcontainer.up")
  )
end

#bun_install(packages = nil, g: false, dev: false) ⇒ Object



656
657
658
659
660
661
662
663
# File 'lib/e2b/template.rb', line 656

def bun_install(packages = nil, g: false, dev: false)
  package_list = packages.nil? ? nil : Array(packages).map(&:to_s)
  args = ["bun", "install"]
  args << "-g" if g
  args << "--dev" if dev
  args.concat(package_list) if package_list
  run_cmd(args.join(" "), user: g ? "root" : nil)
end

#copy(src, dest, force_upload: nil, user: nil, mode: nil, resolve_symlinks: nil) ⇒ Object



543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
# File 'lib/e2b/template.rb', line 543

def copy(src, dest, force_upload: nil, user: nil, mode: nil, resolve_symlinks: nil)
  source_location = capture_source_location

  Array(src).each do |source|
    source_path = source.to_s
    validate_relative_path!(source_path, source_location: source_location)

    @instructions << {
      type: "COPY",
      args: [
        source_path,
        dest.to_s,
        user || "",
        mode ? format("%04o", mode) : ""
      ],
      force: !!force_upload || @force_next_layer,
      forceUpload: force_upload,
      resolveSymlinks: resolve_symlinks.nil? ? DEFAULT_RESOLVE_SYMLINKS : resolve_symlinks,
      sourceLocation: source_location
    }
  end

  self
end

#copy_items(items) ⇒ Object



568
569
570
571
572
573
574
575
576
577
578
579
580
581
# File 'lib/e2b/template.rb', line 568

def copy_items(items)
  items.each do |item|
    copy(
      copy_item_value(item, :src),
      copy_item_value(item, :dest),
      force_upload: copy_item_value(item, :forceUpload, required: false),
      user: copy_item_value(item, :user, required: false),
      mode: copy_item_value(item, :mode, required: false),
      resolve_symlinks: copy_item_value(item, :resolveSymlinks, required: false)
    )
  end

  self
end

#from_aws_registry(image, access_key_id:, secret_access_key:, region:) ⇒ Object



492
493
494
495
496
497
498
499
500
501
502
503
504
# File 'lib/e2b/template.rb', line 492

def from_aws_registry(image, access_key_id:, secret_access_key:, region:)
  @base_image = image
  @base_template = nil
  @registry_config = {
    type: "aws",
    awsAccessKeyId: access_key_id,
    awsSecretAccessKey: secret_access_key,
    awsRegion: region
  }
  @force = true if @force_next_layer
  @base_source_location = capture_source_location
  self
end

#from_base_imageObject



473
474
475
# File 'lib/e2b/template.rb', line 473

def from_base_image
  from_image(DEFAULT_BASE_IMAGE)
end

#from_bun_image(variant = "latest") ⇒ Object



469
470
471
# File 'lib/e2b/template.rb', line 469

def from_bun_image(variant = "latest")
  from_image("oven/bun:#{variant}")
end

#from_debian_image(variant = "stable") ⇒ Object



453
454
455
# File 'lib/e2b/template.rb', line 453

def from_debian_image(variant = "stable")
  from_image("debian:#{variant}")
end

#from_dockerfile(dockerfile_content_or_path) ⇒ Object



518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
# File 'lib/e2b/template.rb', line 518

def from_dockerfile(dockerfile_content_or_path)
  @base_template = nil
  @registry_config = nil
  @base_image = E2B::DockerfileParser.parse(dockerfile_content_or_path, self)
  @force = true if @force_next_layer
  @base_source_location = capture_source_location
  self
rescue TemplateError => e
  raise template_error(
    e.message,
    source_location: capture_source_location,
    status_code: e.status_code,
    headers: e.headers
  )
end

#from_gcp_registry(image, service_account_json:) ⇒ Object



506
507
508
509
510
511
512
513
514
515
516
# File 'lib/e2b/template.rb', line 506

def from_gcp_registry(image, service_account_json:)
  @base_image = image
  @base_template = nil
  @registry_config = {
    type: "gcp",
    serviceAccountJson: ()
  }
  @force = true if @force_next_layer
  @base_source_location = capture_source_location
  self
end

#from_image(image, username: nil, password: nil) ⇒ Object



477
478
479
480
481
482
483
484
485
486
487
488
489
490
# File 'lib/e2b/template.rb', line 477

def from_image(image, username: nil, password: nil)
  @base_image = image
  @base_template = nil
  @registry_config = if username && password
                       {
                         type: "registry",
                         username: username,
                         password: password
                       }
                     end
  @force = true if @force_next_layer
  @base_source_location = capture_source_location
  self
end

#from_node_image(variant = "lts") ⇒ Object



465
466
467
# File 'lib/e2b/template.rb', line 465

def from_node_image(variant = "lts")
  from_image("node:#{variant}")
end

#from_python_image(version = "3") ⇒ Object



461
462
463
# File 'lib/e2b/template.rb', line 461

def from_python_image(version = "3")
  from_image("python:#{version}")
end

#from_template(template) ⇒ Object



534
535
536
537
538
539
540
541
# File 'lib/e2b/template.rb', line 534

def from_template(template)
  @base_template = template
  @base_image = nil
  @registry_config = nil
  @force = true if @force_next_layer
  @base_source_location = capture_source_location
  self
end

#from_ubuntu_image(variant = "latest") ⇒ Object



457
458
459
# File 'lib/e2b/template.rb', line 457

def from_ubuntu_image(variant = "latest")
  from_image("ubuntu:#{variant}")
end

#git_clone(url, path = nil, branch: nil, depth: nil, user: nil) ⇒ Object



689
690
691
692
693
694
695
696
697
698
# File 'lib/e2b/template.rb', line 689

def git_clone(url, path = nil, branch: nil, depth: nil, user: nil)
  args = ["git", "clone", url.to_s]
  if branch
    args << "--branch #{branch}"
    args << "--single-branch"
  end
  args << "--depth #{depth}" if depth
  args << path.to_s if path
  run_cmd(args.join(" "), user: user)
end

#make_dir(path, mode: nil, user: nil) ⇒ Object



731
732
733
734
735
736
# File 'lib/e2b/template.rb', line 731

def make_dir(path, mode: nil, user: nil)
  args = ["mkdir", "-p"]
  args << "-m #{format('%04o', mode)}" if mode
  args.concat(Array(path).map(&:to_s))
  run_cmd(args.join(" "), user: user)
end


738
739
740
741
742
743
744
# File 'lib/e2b/template.rb', line 738

def make_symlink(src, dest, user: nil, force: false)
  args = ["ln", "-s"]
  args << "-f" if force
  args << src.to_s
  args << dest.to_s
  run_cmd(args.join(" "), user: user)
end

#npm_install(packages = nil, g: false, dev: false) ⇒ Object



647
648
649
650
651
652
653
654
# File 'lib/e2b/template.rb', line 647

def npm_install(packages = nil, g: false, dev: false)
  package_list = packages.nil? ? nil : Array(packages).map(&:to_s)
  args = ["npm", "install"]
  args << "-g" if g
  args << "--save-dev" if dev
  args.concat(package_list) if package_list
  run_cmd(args.join(" "), user: g ? "root" : nil)
end

#pip_install(packages = nil, g: true) ⇒ Object



639
640
641
642
643
644
645
# File 'lib/e2b/template.rb', line 639

def pip_install(packages = nil, g: true)
  package_list = packages.nil? ? nil : Array(packages).map(&:to_s)
  args = ["pip", "install"]
  args << "--user" unless g
  args.concat(package_list || ["."])
  run_cmd(args.join(" "), user: g ? "root" : nil)
end

#remove(path, force: false, recursive: false, user: nil) ⇒ Object



715
716
717
718
719
720
721
# File 'lib/e2b/template.rb', line 715

def remove(path, force: false, recursive: false, user: nil)
  args = ["rm"]
  args << "-r" if recursive
  args << "-f" if force
  args.concat(Array(path).map(&:to_s))
  run_cmd(args.join(" "), user: user)
end

#rename(src, dest, force: false, user: nil) ⇒ Object



723
724
725
726
727
728
729
# File 'lib/e2b/template.rb', line 723

def rename(src, dest, force: false, user: nil)
  args = ["mv"]
  args << "-f" if force
  args << src.to_s
  args << dest.to_s
  run_cmd(args.join(" "), user: user)
end

#run_cmd(cmd, user: nil) ⇒ Object



583
584
585
586
587
588
589
590
591
592
593
594
595
# File 'lib/e2b/template.rb', line 583

def run_cmd(cmd, user: nil)
  commands = Array(cmd).map(&:to_s)
  source_location = capture_source_location

  @instructions << {
    type: "RUN",
    args: [commands.join(" && "), user || ""],
    force: @force_next_layer,
    sourceLocation: source_location
  }

  self
end

#set_envs(envs) ⇒ Object



621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
# File 'lib/e2b/template.rb', line 621

def set_envs(envs)
  return self if envs.empty?

  args = envs.each_with_object([]) do |(key, value), values|
    values << key.to_s
    values << value.to_s
  end
  source_location = capture_source_location

  @instructions << {
    type: "ENV",
    args: args,
    force: @force_next_layer,
    sourceLocation: source_location
  }
  self
end

#set_ready_cmd(ready_cmd) ⇒ Object



758
759
760
761
762
# File 'lib/e2b/template.rb', line 758

def set_ready_cmd(ready_cmd)
  @ready_cmd = normalize_ready_cmd(ready_cmd)
  @finalization_source_location = capture_source_location
  self
end

#set_start_cmd(start_cmd, ready_cmd = nil) ⇒ Object



751
752
753
754
755
756
# File 'lib/e2b/template.rb', line 751

def set_start_cmd(start_cmd, ready_cmd = nil)
  @start_cmd = start_cmd.to_s
  @ready_cmd = normalize_ready_cmd(ready_cmd) unless ready_cmd.nil?
  @finalization_source_location = capture_source_location
  self
end

#set_user(user) ⇒ Object



609
610
611
612
613
614
615
616
617
618
619
# File 'lib/e2b/template.rb', line 609

def set_user(user)
  source_location = capture_source_location

  @instructions << {
    type: "USER",
    args: [user.to_s],
    force: @force_next_layer,
    sourceLocation: source_location
  }
  self
end

#set_workdir(workdir) ⇒ Object



597
598
599
600
601
602
603
604
605
606
607
# File 'lib/e2b/template.rb', line 597

def set_workdir(workdir)
  source_location = capture_source_location

  @instructions << {
    type: "WORKDIR",
    args: [workdir.to_s],
    force: @force_next_layer,
    sourceLocation: source_location
  }
  self
end

#skip_cacheObject



746
747
748
749
# File 'lib/e2b/template.rb', line 746

def skip_cache
  @force_next_layer = true
  self
end

#to_dockerfileObject



772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
# File 'lib/e2b/template.rb', line 772

def to_dockerfile
  if @base_template
    raise template_error(
      "Cannot convert template built from another template to Dockerfile. Templates based on other templates can only be built using the E2B API.",
      source_location: capture_source_location
    )
  end

  raise template_error("No base image specified for template", source_location: capture_source_location) unless @base_image

  dockerfile = +"FROM #{@base_image}\n"
  @instructions.each do |instruction|
    case instruction[:type]
    when "RUN"
      dockerfile << "RUN #{instruction[:args][0]}\n"
    when "COPY"
      dockerfile << "COPY #{instruction[:args][0]} #{instruction[:args][1]}\n"
    when "ENV"
      values = instruction[:args].each_slice(2).map { |key, value| "#{key}=#{value}" }
      dockerfile << "ENV #{values.join(' ')}\n"
    else
      dockerfile << "#{instruction[:type]} #{instruction[:args].join(' ')}\n"
    end
  end
  dockerfile << "ENTRYPOINT #{@start_cmd}\n" if @start_cmd
  dockerfile
end

#to_h(compute_hashes: false) ⇒ Object



764
765
766
# File 'lib/e2b/template.rb', line 764

def to_h(compute_hashes: false)
  build_payload(compute_hashes ?  : @instructions)
end

#to_json(compute_hashes: true) ⇒ Object



768
769
770
# File 'lib/e2b/template.rb', line 768

def to_json(compute_hashes: true)
  JSON.pretty_generate(to_h(compute_hashes: compute_hashes))
end