withruntime 0.27.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/withruntime/generated/apps.rb +192 -0
- data/lib/withruntime/generated/audit.rb +78 -0
- data/lib/withruntime/generated/browsers.rb +192 -0
- data/lib/withruntime/generated/builds.rb +192 -0
- data/lib/withruntime/generated/ci.rb +192 -0
- data/lib/withruntime/generated/containers.rb +192 -0
- data/lib/withruntime/generated/desktops.rb +192 -0
- data/lib/withruntime/generated/domains.rb +152 -0
- data/lib/withruntime/generated/egress_ips.rb +81 -0
- data/lib/withruntime/generated/events.rb +60 -0
- data/lib/withruntime/generated/feedback.rb +96 -0
- data/lib/withruntime/generated/functions.rb +192 -0
- data/lib/withruntime/generated/identities.rb +68 -0
- data/lib/withruntime/generated/images.rb +391 -0
- data/lib/withruntime/generated/job_runs.rb +110 -0
- data/lib/withruntime/generated/jobs.rb +333 -0
- data/lib/withruntime/generated/keys.rb +261 -0
- data/lib/withruntime/generated/kit.rb +111 -0
- data/lib/withruntime/generated/me.rb +69 -0
- data/lib/withruntime/generated/networks.rb +72 -0
- data/lib/withruntime/generated/notebooks.rb +192 -0
- data/lib/withruntime/generated/otel.rb +94 -0
- data/lib/withruntime/generated/ports.rb +118 -0
- data/lib/withruntime/generated/previews.rb +124 -0
- data/lib/withruntime/generated/projects.rb +108 -0
- data/lib/withruntime/generated/roles.rb +68 -0
- data/lib/withruntime/generated/routes.rb +11 -0
- data/lib/withruntime/generated/runtime.rb +188 -0
- data/lib/withruntime/generated/sandboxes.rb +1835 -0
- data/lib/withruntime/generated/secrets.rb +294 -0
- data/lib/withruntime/generated/sessions.rb +143 -0
- data/lib/withruntime/generated/sites.rb +192 -0
- data/lib/withruntime/generated/snapshots.rb +32 -0
- data/lib/withruntime/generated/tunnels.rb +165 -0
- data/lib/withruntime/generated/usage.rb +287 -0
- data/lib/withruntime/generated/volumes.rb +61 -0
- data/lib/withruntime/generated/webhooks.rb +91 -0
- data/lib/withruntime/generated/workspaces.rb +192 -0
- data/lib/withruntime/signing.rb +162 -0
- data/lib/withruntime/version.rb +2 -2
- data/lib/withruntime.rb +5 -43
- metadata +45 -35
- data/lib/withruntime/agents.rb +0 -877
- data/lib/withruntime/api_defaults.rb +0 -17
- data/lib/withruntime/apps.rb +0 -377
- data/lib/withruntime/browsers.rb +0 -104
- data/lib/withruntime/builds.rb +0 -218
- data/lib/withruntime/ci.rb +0 -164
- data/lib/withruntime/client.rb +0 -140
- data/lib/withruntime/containers.rb +0 -39
- data/lib/withruntime/credentials.rb +0 -111
- data/lib/withruntime/fields.rb +0 -40
- data/lib/withruntime/file_watch.rb +0 -73
- data/lib/withruntime/images.rb +0 -258
- data/lib/withruntime/network_products.rb +0 -49
- data/lib/withruntime/parity_products.rb +0 -51
- data/lib/withruntime/products.rb +0 -560
- data/lib/withruntime/record.rb +0 -99
- data/lib/withruntime/reservations.rb +0 -76
- data/lib/withruntime/sandbox.rb +0 -770
- data/lib/withruntime/tar.rb +0 -292
- data/lib/withruntime/transport.rb +0 -575
- data/lib/withruntime/tunnel.rb +0 -275
- data/lib/withruntime/wallet.rb +0 -68
- data/lib/withruntime/websocket.rb +0 -384
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
# Generated by spec-gen from engines/front/crates/spec. Do not edit:
|
|
2
|
+
# change the spec and run `cargo run -p runtime-front-spec-gen -- write`.
|
|
3
|
+
|
|
4
|
+
require "uri"
|
|
5
|
+
require_relative "runtime"
|
|
6
|
+
require_relative "sandboxes"
|
|
7
|
+
|
|
8
|
+
module Withruntime
|
|
9
|
+
module Generated
|
|
10
|
+
# A machine that answers HTTP with a handler in /app/index.ts (`export default { fetch(request) }`, as Cloudflare Workers and Vercel take one) on port 8080, reached at its preview. It pauses after 60 seconds with nothing happening, its memory kept, and a request resumes it.
|
|
11
|
+
class Functions
|
|
12
|
+
def initialize(transport)
|
|
13
|
+
@transport = transport
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Creates a function. Asked again with the same Idempotency-Key, it returns the same function.
|
|
17
|
+
def create(vcpu: nil, memory_gb: nil, disk_gb: nil, image: nil, secrets: nil, start: nil, user: nil, volumes: nil, run: nil, name: nil, labels: nil, get_or_create: nil, max_cost: nil, idle_pause_seconds: nil, snapshot: nil, network: nil, env: nil, idempotency_key: nil)
|
|
18
|
+
Sandbox.from(@transport.request("POST", "/v2/functions", body: { "vcpu" => vcpu, "memoryGB" => memory_gb, "diskGB" => disk_gb, "image" => image, "secrets" => secrets, "start" => start, "user" => user, "volumes" => volumes, "run" => run, "name" => name, "labels" => labels, "getOrCreate" => get_or_create, "maxCost" => max_cost, "idlePauseSeconds" => idle_pause_seconds, "snapshot" => snapshot, "network" => network, "env" => env }.compact, idempotency_key: idempotency_key, idempotent: true))
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Returns a function.
|
|
22
|
+
def get(id, wait: nil, if_state: nil)
|
|
23
|
+
Sandbox.from(@transport.request("GET", "/v2/functions/#{URI.encode_www_form_component(id)}", query: { "wait" => wait, "ifState" => if_state }, idempotent: true))
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Lists the project's functions, newest first.
|
|
27
|
+
def list(state: nil, name: nil, label: nil, cursor: nil, limit: nil)
|
|
28
|
+
Generated.page(@transport.request("GET", "/v2/functions", query: { "state" => state, "name" => name, "label" => label, "cursor" => cursor, "limit" => limit }, idempotent: true)) { |i| Sandbox.from(i) }
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Deletes a function, its memory and its disk.
|
|
32
|
+
def delete(id, idempotency_key: nil)
|
|
33
|
+
Sandbox.from(@transport.request("DELETE", "/v2/functions/#{URI.encode_www_form_component(id)}", idempotency_key: idempotency_key))
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Pauses a function with its memory and disk kept. A call to it resumes it.
|
|
37
|
+
def pause(id, idempotency_key: nil)
|
|
38
|
+
Sandbox.from(@transport.request("POST", "/v2/functions/#{URI.encode_www_form_component(id)}:pause", idempotency_key: idempotency_key))
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Resumes a paused function where it was, its memory and processes as they were.
|
|
42
|
+
def resume(id, idempotency_key: nil)
|
|
43
|
+
Sandbox.from(@transport.request("POST", "/v2/functions/#{URI.encode_www_form_component(id)}:resume", idempotency_key: idempotency_key))
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Runs a command as a process and returns it once it ended, with its output; with wait false, at once, while it runs. A paused function is resumed first. Asked again with the same Idempotency-Key, it runs nothing more: it returns the first run's process, waiting for its end while it runs.
|
|
47
|
+
def exec(id, cmd:, cwd: nil, env: nil, stdin: nil, timeout_seconds: nil, stream: nil, wait: nil, stdin_open: nil, output_encoding: nil, pty: nil, user: nil, idempotency_key: nil)
|
|
48
|
+
Process.from(@transport.request("POST", "/v2/functions/#{URI.encode_www_form_component(id)}:exec", body: { "cmd" => cmd, "cwd" => cwd, "env" => env, "stdin" => stdin, "timeoutSeconds" => timeout_seconds, "stream" => stream, "wait" => wait, "stdinOpen" => stdin_open, "outputEncoding" => output_encoding, "pty" => pty, "user" => user }.compact, idempotency_key: idempotency_key, idempotent: true, runs: true, runs_seconds: timeout_seconds))
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Returns a file's bytes.
|
|
52
|
+
def read(id, path:)
|
|
53
|
+
@transport.request("GET", "/v2/functions/#{URI.encode_www_form_component(id)}/files", query: { "path" => path }, raw: true, idempotent: true)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Writes the request's bytes to a file as they come, of any size (Content-Length required), its folders made: the file whole when they all came, or as it was. With offset, they are written into it in place.
|
|
57
|
+
def write(id, data, path:, mode: nil, offset: nil, sha256: nil, idempotency_key: nil)
|
|
58
|
+
FileWritten.from(@transport.request("PUT", "/v2/functions/#{URI.encode_www_form_component(id)}/files", query: { "path" => path, "mode" => mode, "offset" => offset, "sha256" => sha256 }, data: data, idempotency_key: idempotency_key))
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Returns a process's output after a cursor, and the cursor to read on from. The latest 1 MiB is kept; truncated says when the cursor fell behind.
|
|
62
|
+
def process_output(id, process, cursor: nil, wait_seconds: nil, max_bytes: nil, follow: nil)
|
|
63
|
+
ProcessOutput.from(@transport.request("GET", "/v2/functions/#{URI.encode_www_form_component(id)}/processes/#{URI.encode_www_form_component(process)}/output", query: { "cursor" => cursor, "waitSeconds" => wait_seconds, "maxBytes" => max_bytes, "follow" => follow }, idempotent: true))
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Sends input to a process started with stdinOpen or a pty, and returns how much of its input it has taken.
|
|
67
|
+
def write_process(id, process, data: nil, offset: nil, eof: nil, idempotency_key: nil)
|
|
68
|
+
ProcessWritten.from(@transport.request("POST", "/v2/functions/#{URI.encode_www_form_component(id)}/processes/#{URI.encode_www_form_component(process)}:write", body: { "data" => data, "offset" => offset, "eof" => eof }.compact, idempotency_key: idempotency_key))
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Sends a signal to a process and its group; a process that ended is not signalled, so a retry is safe.
|
|
72
|
+
def signal_process(id, process, signal: nil, idempotency_key: nil)
|
|
73
|
+
Process.from(@transport.request("POST", "/v2/functions/#{URI.encode_www_form_component(id)}/processes/#{URI.encode_www_form_component(process)}:signal", body: { "signal" => signal }.compact, idempotency_key: idempotency_key, idempotent: true))
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Lists a function's processes, newest first: those running and those that ended lately.
|
|
77
|
+
def list_processes(id)
|
|
78
|
+
ProcessList.from(@transport.request("GET", "/v2/functions/#{URI.encode_www_form_component(id)}/processes", idempotent: true))
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# Removes a file, a link or a directory (recursive for one with contents). One missing is success, removed false.
|
|
82
|
+
def remove(id, path:, recursive: nil, idempotency_key: nil)
|
|
83
|
+
FileRemoved.from(@transport.request("POST", "/v2/functions/#{URI.encode_www_form_component(id)}/files:remove", body: { "path" => path, "recursive" => recursive }.compact, idempotency_key: idempotency_key))
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Returns what is at a path: a file, a directory or a link, or nothing (exists false). With sha256=true, a file's SHA-256 too.
|
|
87
|
+
def stat(id, path:, sha256: nil)
|
|
88
|
+
FileInfo.from(@transport.request("GET", "/v2/functions/#{URI.encode_www_form_component(id)}/files/stat", query: { "path" => path, "sha256" => sha256 }, idempotent: true))
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# Lists a directory's entries in path order, to a depth.
|
|
92
|
+
def list_files(id, path: nil, depth: nil, limit: nil, hidden: nil, glob: nil)
|
|
93
|
+
FileList.from(@transport.request("GET", "/v2/functions/#{URI.encode_www_form_component(id)}/files/list", query: { "path" => path, "depth" => depth, "limit" => limit, "hidden" => hidden, "glob" => glob }, idempotent: true))
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# Returns a folder as a tar archive (`application/x-tar`, or `application/gzip` with gzip), packed by tar in the function as it streams, of any size; its entries are relative to the folder (`./a.txt`). A folder that fails part way (a file it may not read, or one that changes as it is read) ends as an archive every tar reader refuses, never as a short one that reads whole. At most 4 at once in a function. A paused function is woken first.
|
|
97
|
+
def download_folder(id, path:, gzip: nil, user: nil, exclude: nil)
|
|
98
|
+
@transport.request("GET", "/v2/functions/#{URI.encode_www_form_component(id)}/files/archive", query: { "path" => path, "gzip" => gzip, "user" => user, "exclude" => exclude }, raw: true, idempotent: true)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# Unpacks the request's tar archive (gzip-compressed or not, told by its first bytes) into a folder, made with its parents, by tar in the function as the bytes arrive, of any size, nothing of it kept on disk but what tar writes; returns once tar has ended, or 400 `invalid_archive` with what tar said. A paused function is woken first.
|
|
102
|
+
def upload_folder(id, data, path:, user: nil, idempotency_key: nil)
|
|
103
|
+
FolderUnpacked.from(@transport.request("PUT", "/v2/functions/#{URI.encode_www_form_component(id)}/files/archive", query: { "path" => path, "user" => user }, data: data, idempotency_key: idempotency_key, idempotent: true))
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# Begins a folder's upload in parts: tar starts in the function, unpacking into the folder each part as it arrives. Send the parts in order by offset (writeFolderUpload), then commitFolderUpload; an upload no call names for 10 minutes is ended. A paused function is woken first.
|
|
107
|
+
def begin_folder_upload(id, path:, gzip: nil, user: nil, idempotency_key: nil)
|
|
108
|
+
FolderUpload.from(@transport.request("POST", "/v2/functions/#{URI.encode_www_form_component(id)}/files/archive/uploads", body: { "path" => path, "gzip" => gzip, "user" => user }.compact, idempotency_key: idempotency_key))
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# Sends the request's bytes, a part of the archive at its offset, into tar's input as they arrive, of any size, and returns the bytes received in all once tar took them. A part past them is refused 409 `upload_incomplete`, naming them: send the parts in order.
|
|
112
|
+
def write_folder_upload(id, upload, data, offset: nil, idempotency_key: nil)
|
|
113
|
+
FolderUploadReceived.from(@transport.request("PUT", "/v2/functions/#{URI.encode_www_form_component(id)}/files/archive/uploads/#{URI.encode_www_form_component(upload)}", query: { "offset" => offset }, data: data, idempotency_key: idempotency_key, idempotent: true))
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# Ends a folder upload's input and returns once tar has ended, as an exec returns once its command has: the folder, or 400 `invalid_archive` with what tar said. A front that restarts meanwhile returns 503 `run_goes_on`; sent again, it returns how tar ended. An upload no call has named for 10 minutes since its last part or commit is ended.
|
|
117
|
+
def commit_folder_upload(id, upload, idempotency_key: nil)
|
|
118
|
+
FolderUnpacked.from(@transport.request("POST", "/v2/functions/#{URI.encode_www_form_component(id)}/files/archive/uploads/#{URI.encode_www_form_component(upload)}:commit", idempotency_key: idempotency_key, idempotent: true))
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# Stops a folder upload's tar; what it unpacked so far stays.
|
|
122
|
+
def abort_folder_upload(id, upload, idempotency_key: nil)
|
|
123
|
+
FolderUploadAborted.from(@transport.request("POST", "/v2/functions/#{URI.encode_www_form_component(id)}/files/archive/uploads/#{URI.encode_www_form_component(upload)}:abort", idempotency_key: idempotency_key, idempotent: true))
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# Makes a directory, and its parents unless parents is false. One there already is success, created false.
|
|
127
|
+
def mkdir(id, path:, parents: nil, idempotency_key: nil)
|
|
128
|
+
FileMade.from(@transport.request("POST", "/v2/functions/#{URI.encode_www_form_component(id)}/files:mkdir", body: { "path" => path, "parents" => parents }.compact, idempotency_key: idempotency_key, idempotent: true))
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# Moves a file, a link or a directory; refused 409 when something is at its new path, unless overwrite. With sha256 or size, a file written in parts is put in place once whole: its writes ended, then only a file of that size with every byte written and whose bytes hash to it moves; refused 409 `upload_incomplete` or `checksum_mismatch`, nothing moved. With sha256, it is safe to send again: once moved, it returns the same answer while `from` is gone and `to` holds those bytes.
|
|
132
|
+
def rename(id, from:, to:, overwrite: nil, sha256: nil, size: nil, idempotency_key: nil)
|
|
133
|
+
FileRenamed.from(@transport.request("POST", "/v2/functions/#{URI.encode_www_form_component(id)}/files:rename", body: { "from" => from, "to" => to, "overwrite" => overwrite, "sha256" => sha256, "size" => size }.compact, idempotency_key: idempotency_key))
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# Makes an expiring address for one file that anyone may open with no API key, from a browser, curl or another service: GET downloads it (Range works, so videos play and downloads resume; archive: true downloads a folder as .tar.gz), PUT with the raw body uploads it (up to maxBytes, written whole; Content-Length required). The link acts as the key that made it: an upload link needs write, and the link ends with its key, with revokeLinks or with its function. A paused function is woken for it unless wake is false.
|
|
137
|
+
def link(id, path:, method: nil, expires_in_seconds: nil, filename: nil, max_bytes: nil, wake: nil, archive: nil, idempotency_key: nil)
|
|
138
|
+
FileLink.from(@transport.request("POST", "/v2/functions/#{URI.encode_www_form_component(id)}/files:link", body: { "path" => path, "method" => method, "expiresInSeconds" => expires_in_seconds, "filename" => filename, "maxBytes" => max_bytes, "wake" => wake, "archive" => archive }.compact, idempotency_key: idempotency_key))
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
# Ends every file link made for a function so far; links made after work.
|
|
142
|
+
def revoke_links(id, idempotency_key: nil)
|
|
143
|
+
FileLinksRevoked.from(@transport.request("POST", "/v2/functions/#{URI.encode_www_form_component(id)}/files:revokeLinks", idempotency_key: idempotency_key))
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# Returns where a function may connect out.
|
|
147
|
+
def get_network(id)
|
|
148
|
+
SandboxNetwork.from(@transport.request("GET", "/v2/functions/#{URI.encode_www_form_component(id)}/network", idempotent: true))
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
# Returns a function's CPU, memory, disks and pressure, as its host reads them from the function's own cgroup over a fifth of a second: never a call into the function, so it does not wake a paused one nor keep one from its idle pause. One that is not running has no reading.
|
|
152
|
+
def metrics(id, range: nil)
|
|
153
|
+
SandboxMetrics.from(@transport.request("GET", "/v2/functions/#{URI.encode_www_form_component(id)}/metrics", query: { "range" => range }, idempotent: true))
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
# Replaces where a function may connect out, for its next connection and within a second for its open ones: those the new rules refuse are cut.
|
|
157
|
+
def set_network(id, allow_outbound: nil, deny_outbound: nil, idempotency_key: nil)
|
|
158
|
+
SandboxNetwork.from(@transport.request("PUT", "/v2/functions/#{URI.encode_www_form_component(id)}/network", body: { "allowOutbound" => allow_outbound, "denyOutbound" => deny_outbound }.compact, idempotency_key: idempotency_key))
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
# Copies a function as it is now, memory and disk, into `count` copies of its own, each running on its host. Asked again with the same Idempotency-Key, it returns the same copies.
|
|
162
|
+
def fork(id, count: nil, name: nil, labels: nil, secrets: nil, max_cost: nil, idle_pause_seconds: nil, idempotency_key: nil)
|
|
163
|
+
Forked.from(@transport.request("POST", "/v2/functions/#{URI.encode_www_form_component(id)}:fork", body: { "count" => count, "name" => name, "labels" => labels, "secrets" => secrets, "maxCost" => max_cost, "idlePauseSeconds" => idle_pause_seconds }.compact, idempotency_key: idempotency_key, idempotent: true))
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
# Keeps a function's memory and disk as they are now, a snapshot to start functions from; with `image`, its disk alone as that image's next version. The function runs on. Asked again with the same Idempotency-Key, it returns the same snapshot.
|
|
167
|
+
def snapshot(id, name: nil, labels: nil, image: nil, start: nil, idempotency_key: nil)
|
|
168
|
+
Stored.from(@transport.request("POST", "/v2/functions/#{URI.encode_www_form_component(id)}:snapshot", body: { "name" => name, "labels" => labels, "image" => image, "start" => start }.compact, idempotency_key: idempotency_key, idempotent: true))
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
# Changes its name, labels, idle pause, maxCost, environment or sizes; each field left out stays as it is. A running one holds a changed environment before this answers (a paused one's at its wake): each process it starts after the answer has it, and its running processes keep the one they started with. Its vCPUs, memory and disk grow while it runs, its commands running on; a smaller size, or a sandbox that is not running, is refused 409 naming why, and nothing is changed. With If-Match, made only while its revision is that one, else 412.
|
|
172
|
+
def update(id, name: nil, labels: nil, idle_pause_seconds: nil, vcpu: nil, memory_gb: nil, disk_gb: nil, user: nil, env: nil, remove_env: nil, max_cost: nil, idempotency_key: nil)
|
|
173
|
+
Sandbox.from(@transport.request("POST", "/v2/functions/#{URI.encode_www_form_component(id)}:update", body: { "name" => name, "labels" => labels, "idlePauseSeconds" => idle_pause_seconds, "vcpu" => vcpu, "memoryGB" => memory_gb, "diskGB" => disk_gb, "user" => user, "env" => env, "removeEnv" => remove_env, "maxCost" => max_cost }.compact, idempotency_key: idempotency_key))
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
# Returns what a function's screen shows now, as `image/png` (or `image/jpeg`): its X display `:1`, whole. Refused 409 `display_not_running` when no display runs. A paused function is resumed first.
|
|
177
|
+
def screenshot(id, format: nil, quality: nil)
|
|
178
|
+
@transport.request("GET", "/v2/functions/#{URI.encode_www_form_component(id)}/screenshot", query: { "format" => format, "quality" => quality }, raw: true, idempotent: true)
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
# Moves, clicks, drags and scrolls the mouse and types on the keyboard of a function's screen (its X display `:1`), each step in turn as one command, and returns where the mouse is then. It stops at the first step that fails, refused 409 `act_failed` naming it; refused 409 `display_not_running` when no display runs. A paused function is resumed first.
|
|
182
|
+
def act(id, actions:, idempotency_key: nil)
|
|
183
|
+
Acted.from(@transport.request("POST", "/v2/functions/#{URI.encode_www_form_component(id)}:act", body: { "actions" => actions }.compact, idempotency_key: idempotency_key))
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
# Runs a cell of Python in a function as a notebook does, in a Jupyter kernel it keeps running for the cell's `context`: variables, imports and functions stay for the next cell. Returns what it printed, its values and displays (text, HTML, images such as charts), and its exception with its traceback. The context's kernel starts on its first cell. A cell past `timeoutSeconds` is interrupted and its context kept. Refused 409 `kernel_not_installed` when the image has no ipykernel. A paused function is resumed first.
|
|
187
|
+
def run_code(id, code:, language: nil, context: nil, timeout_seconds: nil, idempotency_key: nil)
|
|
188
|
+
CodeRun.from(@transport.request("POST", "/v2/functions/#{URI.encode_www_form_component(id)}:runCode", body: { "code" => code, "language" => language, "context" => context, "timeoutSeconds" => timeout_seconds }.compact, idempotency_key: idempotency_key))
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Generated by spec-gen from engines/front/crates/spec. Do not edit:
|
|
2
|
+
# change the spec and run `cargo run -p runtime-front-spec-gen -- write`.
|
|
3
|
+
|
|
4
|
+
require "uri"
|
|
5
|
+
require_relative "runtime"
|
|
6
|
+
require_relative "projects"
|
|
7
|
+
|
|
8
|
+
module Withruntime
|
|
9
|
+
module Generated
|
|
10
|
+
# An agent or CI pipeline: who a key acts as, besides a person.
|
|
11
|
+
# - +id+: Its ID, a key's `agentId`.
|
|
12
|
+
# - +object+: Always `identity`.
|
|
13
|
+
# - +kind+: `agent` or `ci`.
|
|
14
|
+
# - +name+: Its name, unique in the organization for its kind.
|
|
15
|
+
# - +created_at+: When it was made.
|
|
16
|
+
# - +state+: `active`; `deleted` once deleted: a delete's answer.
|
|
17
|
+
# - +deleted_at+: When it was deleted: a delete's answer, its state `deleted`.
|
|
18
|
+
Identity = Struct.new(:id, :object, :kind, :name, :created_at, :state, :deleted_at, keyword_init: true) do
|
|
19
|
+
def self.from(h)
|
|
20
|
+
return nil if h.nil?
|
|
21
|
+
|
|
22
|
+
new(
|
|
23
|
+
id: h["id"],
|
|
24
|
+
object: h["object"],
|
|
25
|
+
kind: h["kind"],
|
|
26
|
+
name: h["name"],
|
|
27
|
+
created_at: h["createdAt"],
|
|
28
|
+
state: h["state"],
|
|
29
|
+
deleted_at: h["deletedAt"],
|
|
30
|
+
)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def to_wire
|
|
34
|
+
{
|
|
35
|
+
"id" => self.id,
|
|
36
|
+
"object" => self.object,
|
|
37
|
+
"kind" => self.kind,
|
|
38
|
+
"name" => self.name,
|
|
39
|
+
"createdAt" => self.created_at,
|
|
40
|
+
"state" => self.state,
|
|
41
|
+
"deletedAt" => self.deleted_at,
|
|
42
|
+
}.compact
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# An agent or CI pipeline: who a key acts as besides a person, holding grants of its own.
|
|
47
|
+
class Identities
|
|
48
|
+
def initialize(transport)
|
|
49
|
+
@transport = transport
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Lists the organization's agents and CI pipelines, by name.
|
|
53
|
+
def list(cursor: nil, limit: nil)
|
|
54
|
+
Generated.page(@transport.request("GET", "/v2/identities", query: { "cursor" => cursor, "limit" => limit }, idempotent: true)) { |i| Identity.from(i) }
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Renames an agent or CI pipeline; its keys and grants stay as they are. A name another of its kind has returns 409.
|
|
58
|
+
def update(id, name:, idempotency_key: nil)
|
|
59
|
+
Identity.from(@transport.request("POST", "/v2/identities/#{URI.encode_www_form_component(id)}:update", body: { "name" => name }.compact, idempotency_key: idempotency_key, idempotent: true))
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Deletes an agent or CI pipeline and frees its name, with its grants and keys: refused from their next call. The caller needs `grants:delete` as well, as the grants go with it. What it made stays. Deleted again, it returns 404.
|
|
63
|
+
def delete(id, idempotency_key: nil)
|
|
64
|
+
Identity.from(@transport.request("DELETE", "/v2/identities/#{URI.encode_www_form_component(id)}", idempotency_key: idempotency_key, idempotent: true))
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
# Generated by spec-gen from engines/front/crates/spec. Do not edit:
|
|
2
|
+
# change the spec and run `cargo run -p runtime-front-spec-gen -- write`.
|
|
3
|
+
|
|
4
|
+
require "uri"
|
|
5
|
+
require_relative "runtime"
|
|
6
|
+
require_relative "sandboxes"
|
|
7
|
+
|
|
8
|
+
module Withruntime
|
|
9
|
+
module Generated
|
|
10
|
+
# Chunks of a build's context, by their SHA-256.
|
|
11
|
+
# - +digests+: At most 10,000 SHA-256 digests, each 64 lowercase hex digits.
|
|
12
|
+
ContextAsked = Struct.new(:digests, keyword_init: true) do
|
|
13
|
+
def self.from(h)
|
|
14
|
+
return nil if h.nil?
|
|
15
|
+
|
|
16
|
+
new(
|
|
17
|
+
digests: h["digests"],
|
|
18
|
+
)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def to_wire
|
|
22
|
+
{
|
|
23
|
+
"digests" => self.digests,
|
|
24
|
+
}.compact
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Which chunks of a build's context still need uploading.
|
|
29
|
+
# - +missing+: The digests asked for that the organization's build context does not hold, sorted, each once.
|
|
30
|
+
ContextMissing = Struct.new(:missing, keyword_init: true) do
|
|
31
|
+
def self.from(h)
|
|
32
|
+
return nil if h.nil?
|
|
33
|
+
|
|
34
|
+
new(
|
|
35
|
+
missing: h["missing"],
|
|
36
|
+
)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def to_wire
|
|
40
|
+
{
|
|
41
|
+
"missing" => self.missing,
|
|
42
|
+
}.compact
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# A chunk of a build's context, uploaded.
|
|
47
|
+
# - +sha256+: Its SHA-256.
|
|
48
|
+
# - +size+: Its size in bytes.
|
|
49
|
+
# - +stored+: Stored by this call: false when the build context held it already.
|
|
50
|
+
ChunkStored = Struct.new(:sha256, :size, :stored, keyword_init: true) do
|
|
51
|
+
def self.from(h)
|
|
52
|
+
return nil if h.nil?
|
|
53
|
+
|
|
54
|
+
new(
|
|
55
|
+
sha256: h["sha256"],
|
|
56
|
+
size: h["size"],
|
|
57
|
+
stored: h["stored"],
|
|
58
|
+
)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def to_wire
|
|
62
|
+
{
|
|
63
|
+
"sha256" => self.sha256,
|
|
64
|
+
"size" => self.size,
|
|
65
|
+
"stored" => self.stored,
|
|
66
|
+
}.compact
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# A file of an image build's context, sent inline.
|
|
71
|
+
# - +path+: Its path in the build context, which `COPY` and `ADD` read.
|
|
72
|
+
# - +content+: Its content: UTF-8 text, or base64 when `encoding` says so.
|
|
73
|
+
# - +encoding+: `utf8` (the default) or `base64`.
|
|
74
|
+
# - +mode+: Its permission bits, 0 to 511 (0777 in octal). At least 0. At most 511.
|
|
75
|
+
ImageFile = Struct.new(:path, :content, :encoding, :mode, keyword_init: true) do
|
|
76
|
+
def self.from(h)
|
|
77
|
+
return nil if h.nil?
|
|
78
|
+
|
|
79
|
+
new(
|
|
80
|
+
path: h["path"],
|
|
81
|
+
content: h["content"],
|
|
82
|
+
encoding: h["encoding"],
|
|
83
|
+
mode: h["mode"],
|
|
84
|
+
)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def to_wire
|
|
88
|
+
{
|
|
89
|
+
"path" => self.path,
|
|
90
|
+
"content" => self.content,
|
|
91
|
+
"encoding" => self.encoding,
|
|
92
|
+
"mode" => self.mode,
|
|
93
|
+
}.compact
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# An image described by its packages, files and commands, rendered into a Dockerfile: `FROM` its base, its `env`, one `RUN` each for its apt, pip and npm packages, its files, then its commands in `workdir`.
|
|
98
|
+
# - +base+: The image it starts from: `runtime` (the default, Runtime's own) or an OCI image, such as `python:3.12-slim`.
|
|
99
|
+
# - +apt+: Debian packages, each `name` or `name=version`. At most 500 items.
|
|
100
|
+
# - +pip+: Python packages, each as pip takes one: `pandas`, `numpy==2.1`, `uvicorn[standard]>=0.30`. At most 500 items.
|
|
101
|
+
# - +npm+: npm packages, installed globally: `typescript`, `@scope/tool@1`. At most 500 items.
|
|
102
|
+
# - +commands+: Shell commands, each run by `/bin/sh` in `workdir` after the packages and files. At most 500 items.
|
|
103
|
+
# - +env+: Environment set before the packages; `$NAME` names its base's.
|
|
104
|
+
# - +files+: Files written into the image, each `path` absolute: at most 1 MiB in all. At most 256 items.
|
|
105
|
+
# - +workdir+: Where its commands run and its machines start: `/workspace` by default.
|
|
106
|
+
ImageRecipe = Struct.new(:base, :apt, :pip, :npm, :commands, :env, :files, :workdir, keyword_init: true) do
|
|
107
|
+
def self.from(h)
|
|
108
|
+
return nil if h.nil?
|
|
109
|
+
|
|
110
|
+
new(
|
|
111
|
+
base: h["base"],
|
|
112
|
+
apt: h["apt"],
|
|
113
|
+
pip: h["pip"],
|
|
114
|
+
npm: h["npm"],
|
|
115
|
+
commands: h["commands"],
|
|
116
|
+
env: h["env"],
|
|
117
|
+
files: h["files"]&.map { |i| ImageFile.from(i) },
|
|
118
|
+
workdir: h["workdir"],
|
|
119
|
+
)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def to_wire
|
|
123
|
+
{
|
|
124
|
+
"base" => self.base,
|
|
125
|
+
"apt" => self.apt,
|
|
126
|
+
"pip" => self.pip,
|
|
127
|
+
"npm" => self.npm,
|
|
128
|
+
"commands" => self.commands,
|
|
129
|
+
"env" => self.env,
|
|
130
|
+
"files" => self.files&.map { |i| i&.to_wire },
|
|
131
|
+
"workdir" => self.workdir,
|
|
132
|
+
}.compact
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# A build context's archive: a tar (gzip allowed), cut into chunks of at most 1 MiB, each uploaded first (`images.context.put`).
|
|
137
|
+
# - +sha256+: The whole archive's SHA-256, in hex.
|
|
138
|
+
# - +size+: Its size in bytes. At least 1.
|
|
139
|
+
# - +chunks+: Its chunks' SHA-256s, in order. At most 200 items.
|
|
140
|
+
ImageArchive = Struct.new(:sha256, :size, :chunks, keyword_init: true) do
|
|
141
|
+
def self.from(h)
|
|
142
|
+
return nil if h.nil?
|
|
143
|
+
|
|
144
|
+
new(
|
|
145
|
+
sha256: h["sha256"],
|
|
146
|
+
size: h["size"],
|
|
147
|
+
chunks: h["chunks"],
|
|
148
|
+
)
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def to_wire
|
|
152
|
+
{
|
|
153
|
+
"sha256" => self.sha256,
|
|
154
|
+
"size" => self.size,
|
|
155
|
+
"chunks" => self.chunks,
|
|
156
|
+
}.compact
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
# A regular file of a build context's archive.
|
|
161
|
+
# - +path+: Its path in the context.
|
|
162
|
+
# - +sha256+: Its SHA-256, in hex.
|
|
163
|
+
# - +size+: Its size in bytes.
|
|
164
|
+
# - +mode+: Its permission bits.
|
|
165
|
+
ImageContextFile = Struct.new(:path, :sha256, :size, :mode, keyword_init: true) do
|
|
166
|
+
def self.from(h)
|
|
167
|
+
return nil if h.nil?
|
|
168
|
+
|
|
169
|
+
new(
|
|
170
|
+
path: h["path"],
|
|
171
|
+
sha256: h["sha256"],
|
|
172
|
+
size: h["size"],
|
|
173
|
+
mode: h["mode"],
|
|
174
|
+
)
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
def to_wire
|
|
178
|
+
{
|
|
179
|
+
"path" => self.path,
|
|
180
|
+
"sha256" => self.sha256,
|
|
181
|
+
"size" => self.size,
|
|
182
|
+
"mode" => self.mode,
|
|
183
|
+
}.compact
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
# A build context uploaded as chunks: the SDKs and CLI make it from a folder and its `.dockerignore`.
|
|
188
|
+
# - +archive+: The archive.
|
|
189
|
+
# - +files+: Every regular file in it.
|
|
190
|
+
ImageContext = Struct.new(:archive, :files, keyword_init: true) do
|
|
191
|
+
def self.from(h)
|
|
192
|
+
return nil if h.nil?
|
|
193
|
+
|
|
194
|
+
new(
|
|
195
|
+
archive: ImageArchive.from(h["archive"]),
|
|
196
|
+
files: h["files"]&.map { |i| ImageContextFile.from(i) },
|
|
197
|
+
)
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
def to_wire
|
|
201
|
+
{
|
|
202
|
+
"archive" => self.archive&.to_wire,
|
|
203
|
+
"files" => self.files&.map { |i| i&.to_wire },
|
|
204
|
+
}.compact
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
# What an image's build runs on: a machine of its own, deleted once the build ends.
|
|
209
|
+
# - +vcpu+: Its vCPUs. At least 1. At most 8. Default: 2.
|
|
210
|
+
# - +memory_gb+: Its memory in GB. At least 1. At most 16. Default: 4.
|
|
211
|
+
# - +disk_gb+: Its disk in GB: the base image, the earlier stages and the context. At least 4. At most 32. Default: 16.
|
|
212
|
+
# - +timeout_seconds+: Seconds the build may run before it fails. At least 60. At most 3600. Default: 1800.
|
|
213
|
+
ImageBuild = Struct.new(:vcpu, :memory_gb, :disk_gb, :timeout_seconds, keyword_init: true) do
|
|
214
|
+
def self.from(h)
|
|
215
|
+
return nil if h.nil?
|
|
216
|
+
|
|
217
|
+
new(
|
|
218
|
+
vcpu: h["vcpu"],
|
|
219
|
+
memory_gb: h["memoryGB"],
|
|
220
|
+
disk_gb: h["diskGB"],
|
|
221
|
+
timeout_seconds: h["timeoutSeconds"],
|
|
222
|
+
)
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
def to_wire
|
|
226
|
+
{
|
|
227
|
+
"vcpu" => self.vcpu,
|
|
228
|
+
"memoryGB" => self.memory_gb,
|
|
229
|
+
"diskGB" => self.disk_gb,
|
|
230
|
+
"timeoutSeconds" => self.timeout_seconds,
|
|
231
|
+
}.compact
|
|
232
|
+
end
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
# An image to build, from exactly one of `image` and `dockerfile`.
|
|
236
|
+
# - +name+: Its name, 1 to 64 of `a-z`, `0-9`, `.`, `_` and `-`: each build of a name is its next version.
|
|
237
|
+
# - +labels+: Labels to find it by.
|
|
238
|
+
# - +tags+: Tags its name takes for it once it is ready; `latest` when it has a name and none is given. At most 16 items.
|
|
239
|
+
# - +image+: An OCI image to use as it is, from a public registry: `python:3.12-slim`, `ghcr.io/org/app:1`.
|
|
240
|
+
# - +dockerfile+: A Dockerfile: multi-stage builds, `ARG`, `COPY --from`, heredocs. `COPY` reads `files`.
|
|
241
|
+
# - +recipe+: Packages, files and commands, rendered into a Dockerfile. Not with `files` or `context`.
|
|
242
|
+
# - +files+: The Dockerfile's build context, inline: at most 1 MiB in all. Not with `context`. At most 256 items.
|
|
243
|
+
# - +context+: The Dockerfile's build context, uploaded first as chunks: up to 200 MiB. Not with `files`.
|
|
244
|
+
# - +dockerignore+: The context's `.dockerignore`: what it names is never copied.
|
|
245
|
+
# - +target+: The stage to build instead of the last.
|
|
246
|
+
# - +build_args+: The Dockerfile's `ARG` values.
|
|
247
|
+
# - +env+: Environment every machine from it starts with, over the Dockerfile's `ENV`.
|
|
248
|
+
# - +start+: What every machine from it starts at each fresh boot, in place of the Dockerfile's `ENTRYPOINT` and `CMD`.
|
|
249
|
+
# - +build+: What its build runs on.
|
|
250
|
+
ImageCreate = Struct.new(:name, :labels, :tags, :image, :dockerfile, :recipe, :files, :context, :dockerignore, :target, :build_args, :env, :start, :build, keyword_init: true) do
|
|
251
|
+
def self.from(h)
|
|
252
|
+
return nil if h.nil?
|
|
253
|
+
|
|
254
|
+
new(
|
|
255
|
+
name: h["name"],
|
|
256
|
+
labels: h["labels"],
|
|
257
|
+
tags: h["tags"],
|
|
258
|
+
image: h["image"],
|
|
259
|
+
dockerfile: h["dockerfile"],
|
|
260
|
+
recipe: ImageRecipe.from(h["recipe"]),
|
|
261
|
+
files: h["files"]&.map { |i| ImageFile.from(i) },
|
|
262
|
+
context: ImageContext.from(h["context"]),
|
|
263
|
+
dockerignore: h["dockerignore"],
|
|
264
|
+
target: h["target"],
|
|
265
|
+
build_args: h["buildArgs"],
|
|
266
|
+
env: h["env"],
|
|
267
|
+
start: MachineStart.from(h["start"]),
|
|
268
|
+
build: ImageBuild.from(h["build"]),
|
|
269
|
+
)
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
def to_wire
|
|
273
|
+
{
|
|
274
|
+
"name" => self.name,
|
|
275
|
+
"labels" => self.labels,
|
|
276
|
+
"tags" => self.tags,
|
|
277
|
+
"image" => self.image,
|
|
278
|
+
"dockerfile" => self.dockerfile,
|
|
279
|
+
"recipe" => self.recipe&.to_wire,
|
|
280
|
+
"files" => self.files&.map { |i| i&.to_wire },
|
|
281
|
+
"context" => self.context&.to_wire,
|
|
282
|
+
"dockerignore" => self.dockerignore,
|
|
283
|
+
"target" => self.target,
|
|
284
|
+
"buildArgs" => self.build_args,
|
|
285
|
+
"env" => self.env,
|
|
286
|
+
"start" => self.start&.to_wire,
|
|
287
|
+
"build" => self.build&.to_wire,
|
|
288
|
+
}.compact
|
|
289
|
+
end
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
# One line of an image's build log.
|
|
293
|
+
# - +seq+: Its number, from 1.
|
|
294
|
+
# - +at+: When it was written.
|
|
295
|
+
# - +stream+: `build` (the build's output) or `system` (Runtime's).
|
|
296
|
+
# - +text+: The line, without its newline.
|
|
297
|
+
ImageLogLine = Struct.new(:seq, :at, :stream, :text, keyword_init: true) do
|
|
298
|
+
def self.from(h)
|
|
299
|
+
return nil if h.nil?
|
|
300
|
+
|
|
301
|
+
new(
|
|
302
|
+
seq: h["seq"],
|
|
303
|
+
at: h["at"],
|
|
304
|
+
stream: h["stream"],
|
|
305
|
+
text: h["text"],
|
|
306
|
+
)
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
def to_wire
|
|
310
|
+
{
|
|
311
|
+
"seq" => self.seq,
|
|
312
|
+
"at" => self.at,
|
|
313
|
+
"stream" => self.stream,
|
|
314
|
+
"text" => self.text,
|
|
315
|
+
}.compact
|
|
316
|
+
end
|
|
317
|
+
end
|
|
318
|
+
|
|
319
|
+
# An image's build log after a line.
|
|
320
|
+
# - +lines+: The lines after `after`, in order.
|
|
321
|
+
# - +next_after+: The last line's number: send it as `after` to read on.
|
|
322
|
+
# - +state+: The image's state.
|
|
323
|
+
# - +truncated+: Whether lines before these were dropped.
|
|
324
|
+
# - +done+: Whether the build has ended: no line comes after these.
|
|
325
|
+
ImageLogs = Struct.new(:lines, :next_after, :state, :truncated, :done, keyword_init: true) do
|
|
326
|
+
def self.from(h)
|
|
327
|
+
return nil if h.nil?
|
|
328
|
+
|
|
329
|
+
new(
|
|
330
|
+
lines: h["lines"]&.map { |i| ImageLogLine.from(i) },
|
|
331
|
+
next_after: h["nextAfter"],
|
|
332
|
+
state: h["state"],
|
|
333
|
+
truncated: h["truncated"],
|
|
334
|
+
done: h["done"],
|
|
335
|
+
)
|
|
336
|
+
end
|
|
337
|
+
|
|
338
|
+
def to_wire
|
|
339
|
+
{
|
|
340
|
+
"lines" => self.lines&.map { |i| i&.to_wire },
|
|
341
|
+
"nextAfter" => self.next_after,
|
|
342
|
+
"state" => self.state,
|
|
343
|
+
"truncated" => self.truncated,
|
|
344
|
+
"done" => self.done,
|
|
345
|
+
}.compact
|
|
346
|
+
end
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
# What a machine boots: a root filesystem, its environment and its start.
|
|
350
|
+
class Images
|
|
351
|
+
def initialize(transport)
|
|
352
|
+
@transport = transport
|
|
353
|
+
end
|
|
354
|
+
|
|
355
|
+
# Returns an image, by its ID, its name (its newest version) or one of its tags (`name:tag`).
|
|
356
|
+
def get(id)
|
|
357
|
+
Stored.from(@transport.request("GET", "/v2/images/#{URI.encode_www_form_component(id)}", idempotent: true))
|
|
358
|
+
end
|
|
359
|
+
|
|
360
|
+
# Lists the project's images, newest first.
|
|
361
|
+
def list(name: nil, state: nil, label: nil, cursor: nil, limit: nil)
|
|
362
|
+
Generated.page(@transport.request("GET", "/v2/images", query: { "name" => name, "state" => state, "label" => label, "cursor" => cursor, "limit" => limit }, idempotent: true)) { |i| Stored.from(i) }
|
|
363
|
+
end
|
|
364
|
+
|
|
365
|
+
# Returns which chunks of a build context still need uploading. The chunks it holds count as used, so they are kept for the build that names them: a chunk is kept 24 hours after its last use, and an organization's build context holds at most 200 MiB.
|
|
366
|
+
def missing(digests:, idempotency_key: nil)
|
|
367
|
+
ContextMissing.from(@transport.request("POST", "/v2/images/context:missing", body: { "digests" => digests }.compact, idempotency_key: idempotency_key, idempotent: true))
|
|
368
|
+
end
|
|
369
|
+
|
|
370
|
+
# Uploads one chunk of a build context: the request's bytes, 1 byte to 1 MiB, named by their SHA-256. Asked again, it stores nothing more.
|
|
371
|
+
def put(digest, data, idempotency_key: nil)
|
|
372
|
+
ChunkStored.from(@transport.request("PUT", "/v2/images/context/#{URI.encode_www_form_component(digest)}", data: data, idempotency_key: idempotency_key, idempotent: true))
|
|
373
|
+
end
|
|
374
|
+
|
|
375
|
+
# Deletes an image version. Sandboxes already started from it keep running. One an App boots from is refused with image_in_use (409) naming the App.
|
|
376
|
+
def delete(id, idempotency_key: nil)
|
|
377
|
+
Stored.from(@transport.request("DELETE", "/v2/images/#{URI.encode_www_form_component(id)}", idempotency_key: idempotency_key))
|
|
378
|
+
end
|
|
379
|
+
|
|
380
|
+
# Builds an image from an OCI image or a Dockerfile on a machine of its own, and returns it at once, `making`: `ready` once built, else `failed` with `error`. Each build of a name is its next version. Asked again with the same Idempotency-Key, it returns the same one.
|
|
381
|
+
def create(name: nil, labels: nil, tags: nil, image: nil, dockerfile: nil, recipe: nil, files: nil, context: nil, dockerignore: nil, target: nil, build_args: nil, env: nil, start: nil, build: nil, idempotency_key: nil)
|
|
382
|
+
Stored.from(@transport.request("POST", "/v2/images", body: { "name" => name, "labels" => labels, "tags" => tags, "image" => image, "dockerfile" => dockerfile, "recipe" => recipe, "files" => files, "context" => context, "dockerignore" => dockerignore, "target" => target, "buildArgs" => build_args, "env" => env, "start" => start, "build" => build }.compact, idempotency_key: idempotency_key, idempotent: true))
|
|
383
|
+
end
|
|
384
|
+
|
|
385
|
+
# Returns an image's build log after a line, as the build writes it and once it has ended.
|
|
386
|
+
def logs(id, after: nil, limit: nil, follow: nil)
|
|
387
|
+
ImageLogs.from(@transport.request("GET", "/v2/images/#{URI.encode_www_form_component(id)}/logs", query: { "after" => after, "limit" => limit, "follow" => follow }, idempotent: true))
|
|
388
|
+
end
|
|
389
|
+
end
|
|
390
|
+
end
|
|
391
|
+
end
|