withruntime 0.28.0 → 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 -775
- 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
data/lib/withruntime/builds.rb
DELETED
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module WithRuntime
|
|
4
|
-
# +runtime.builds+: a connected repository's commit built into the server an
|
|
5
|
-
# App or Function deploys. In a private beta: an account outside it is
|
|
6
|
-
# refused with product_in_beta (403, PermissionDeniedError).
|
|
7
|
-
#
|
|
8
|
-
# repo = runtime.builds.repositories.connect(provider: "github", repository: "acme/web", deploy: "app:#{app.id}")
|
|
9
|
-
# build = runtime.builds.create(repository_id: repo.id, ref: "main")
|
|
10
|
-
# runtime.builds.logs(build.id, follow: true) { |event| puts event.text if event.type == "line" }
|
|
11
|
-
#
|
|
12
|
-
# A build: id, name, labels, repository_id, ref, branch, commit, state
|
|
13
|
-
# (queued, fetching, building, deploying, succeeded, failed, cancelled,
|
|
14
|
-
# superseded), reason, timings (milliseconds per step once done, or nil),
|
|
15
|
-
# output_snapshot_id, framework (detected for the commands the repository
|
|
16
|
-
# leaves unset: nextjs, vite, fastapi, rails, go, docker, ...; or nil),
|
|
17
|
-
# error, created_at, updated_at and deleted_at.
|
|
18
|
-
class Builds < Product
|
|
19
|
-
TERMINAL = %w[succeeded failed cancelled superseded].freeze
|
|
20
|
-
# Reconnections in a row with no new line before a follow gives up.
|
|
21
|
-
RECONNECTS = 3
|
|
22
|
-
SEEN = 10_000
|
|
23
|
-
|
|
24
|
-
attr_reader :repositories
|
|
25
|
-
|
|
26
|
-
def initialize(transport)
|
|
27
|
-
super
|
|
28
|
-
@repositories = Repositories.new(transport)
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
# Builds +ref+ of a connected repository. The same +branch:+ and commit is
|
|
32
|
-
# one build; a newer build of the branch supersedes older ones not ended.
|
|
33
|
-
def create(repository_id:, ref:, branch: nil, name: nil, labels: nil, idempotency_key: nil)
|
|
34
|
-
body = Fields.body(repository_id: repository_id, ref: ref, branch: branch, name: name, labels: labels)
|
|
35
|
-
Record.new(@t.json("POST", "/v1/builds", body: body, key: idempotency_key))
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def get(id) = Record.new(@t.json("GET", path(id)))
|
|
39
|
-
|
|
40
|
-
def list(name: nil, label: nil, state: nil, limit: nil, cursor: nil)
|
|
41
|
-
page("/v1/builds", { "name" => name, "label" => label, "state" => state, "limit" => limit, "cursor" => cursor })
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
# Cancels a build; one that already ended stays as it is.
|
|
45
|
-
def cancel(id, idempotency_key: nil) = Record.new(@t.json("POST", "#{path(id)}:cancel", key: idempotency_key))
|
|
46
|
-
|
|
47
|
-
# The last 200 lines and the failing step: lines (cursor, at, step, text,
|
|
48
|
-
# stream), cursor, state, reason, failing_step (name, exit_code,
|
|
49
|
-
# last_lines), has_more and next_cursor; +page_cursor:+ pages older lines.
|
|
50
|
-
#
|
|
51
|
-
# With +follow: true+, each event to the block as it is written (or an
|
|
52
|
-
# Enumerator without one), until the build ends: a line (type "line"), a
|
|
53
|
-
# gap where lines were lost (type "gap", earliest_cursor), then one
|
|
54
|
-
# terminal event (state, reason, failing_step). +cursor:+ resumes after
|
|
55
|
-
# that line. A lost connection reconnects from the last line, up to three
|
|
56
|
-
# times in a row; then build_log_interrupted, whose details cursor resumes.
|
|
57
|
-
# +timeout:+ bounds the whole follow, reconnections included (120 seconds;
|
|
58
|
-
# 0 for none).
|
|
59
|
-
def logs(id, follow: false, cursor: nil, page_cursor: nil, timeout: 120, &block)
|
|
60
|
-
unless follow
|
|
61
|
-
return Record.new(@t.json("GET", "#{path(id)}/logs", query: { "cursor" => cursor, "pageCursor" => page_cursor }))
|
|
62
|
-
end
|
|
63
|
-
return enum_for(:logs, id, follow: true, cursor: cursor, page_cursor: page_cursor, timeout: timeout) unless block
|
|
64
|
-
|
|
65
|
-
follow_logs(id, cursor, page_cursor, timeout, &block)
|
|
66
|
-
nil
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
private
|
|
70
|
-
|
|
71
|
-
def path(id) = "/v1/builds/#{seg(id)}"
|
|
72
|
-
|
|
73
|
-
def invalid(cursor) = failure("build_log_invalid", "Retry the log from the last received cursor.", cursor)
|
|
74
|
-
|
|
75
|
-
def valid_failure?(value)
|
|
76
|
-
return true if value.nil?
|
|
77
|
-
return false unless value.is_a?(Hash)
|
|
78
|
-
|
|
79
|
-
lines = value["lastLines"]
|
|
80
|
-
value["name"].is_a?(String) && (value["exitCode"].nil? || safe_integer?(value["exitCode"])) &&
|
|
81
|
-
lines.is_a?(Array) && lines.size <= 20 && lines.all?(String)
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
def now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
85
|
-
|
|
86
|
-
# Cursors are opaque physical positions: they cannot be ordered or
|
|
87
|
-
# counted on, so lines already given are known by their cursor.
|
|
88
|
-
def follow_logs(id, cursor, page_cursor, timeout)
|
|
89
|
-
if (cursor && !valid_cursor?(cursor)) || page_cursor
|
|
90
|
-
raise failure("invalid_log_options", "Use an opaque cursor for follow; page_cursor is only for search pages.", cursor)
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
seen = cursor ? { cursor => true } : {}
|
|
94
|
-
failures = 0
|
|
95
|
-
deadline = timeout.positive? ? now + timeout : nil
|
|
96
|
-
timed_out = lambda do
|
|
97
|
-
ConnectionError.new("The log follow reached its deadline.", code: "timeout", details: { "cursor" => cursor },
|
|
98
|
-
hint: "Resume with logs(id, follow: true, cursor: details[\"cursor\"]).")
|
|
99
|
-
end
|
|
100
|
-
loop do
|
|
101
|
-
raise timed_out.call if deadline && now >= deadline
|
|
102
|
-
|
|
103
|
-
continued = false
|
|
104
|
-
begin
|
|
105
|
-
@t.events("GET", "#{path(id)}/logs", query: { "follow" => true, "cursor" => cursor },
|
|
106
|
-
timeout: deadline && (deadline - now)) do |event|
|
|
107
|
-
raise invalid(cursor) unless event.is_a?(Hash)
|
|
108
|
-
raise invalid(cursor) unless event.key?("cursor") && (event["cursor"].nil? || valid_cursor?(event["cursor"]))
|
|
109
|
-
|
|
110
|
-
case event["type"]
|
|
111
|
-
when "line"
|
|
112
|
-
unless event["text"].is_a?(String) && %w[stdout stderr].include?(event["stream"]) &&
|
|
113
|
-
safe_integer?(event["at"]) && !event["at"].negative? &&
|
|
114
|
-
(event["step"].nil? || event["step"].is_a?(String)) && valid_cursor?(event["cursor"])
|
|
115
|
-
raise invalid(cursor)
|
|
116
|
-
end
|
|
117
|
-
next if seen.key?(event["cursor"])
|
|
118
|
-
|
|
119
|
-
seen[event["cursor"]] = true
|
|
120
|
-
seen.delete(seen.first[0]) if seen.size > SEEN
|
|
121
|
-
cursor = event["cursor"]
|
|
122
|
-
failures = 0
|
|
123
|
-
yield Record.new(event)
|
|
124
|
-
when "gap"
|
|
125
|
-
raise invalid(cursor) if !valid_cursor?(event["earliestCursor"]) || (cursor && event["cursor"] != cursor)
|
|
126
|
-
|
|
127
|
-
cursor = event["cursor"]
|
|
128
|
-
yield Record.new(event)
|
|
129
|
-
when "terminal"
|
|
130
|
-
if (cursor && event["cursor"] != cursor) || !TERMINAL.include?(event["state"]) ||
|
|
131
|
-
!event["reason"].is_a?(String) || event["reason"].empty? || !valid_failure?(event["failingStep"]) ||
|
|
132
|
-
(event["state"] != "failed" && !event["failingStep"].nil?)
|
|
133
|
-
raise invalid(cursor)
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
yield Record.new(event)
|
|
137
|
-
return
|
|
138
|
-
when "continue"
|
|
139
|
-
if cursor && event["cursor"] != cursor
|
|
140
|
-
raise failure("build_log_gap", "Resume from details.cursor; report a persistent missing log line.", cursor)
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
cursor = event["cursor"]
|
|
144
|
-
continued = true
|
|
145
|
-
break
|
|
146
|
-
when "error"
|
|
147
|
-
unless event["cursor"] == cursor && event["code"].is_a?(String) && !event["code"].empty? &&
|
|
148
|
-
event["hint"].is_a?(String) && !event["hint"].empty?
|
|
149
|
-
raise invalid(cursor)
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
raise failure(event["code"], event["hint"], cursor)
|
|
153
|
-
else
|
|
154
|
-
raise invalid(cursor)
|
|
155
|
-
end
|
|
156
|
-
end
|
|
157
|
-
rescue ConnectionError
|
|
158
|
-
# A lost connection, not a refusal: the transport itself retries
|
|
159
|
-
# retryable answers. Reconnect from the last line.
|
|
160
|
-
raise timed_out.call if deadline && now >= deadline
|
|
161
|
-
rescue Error => e
|
|
162
|
-
raise e unless e.code == "unexpected_answer" && e.status.zero?
|
|
163
|
-
|
|
164
|
-
raise failure("build_log_invalid", "The log contained invalid JSON; retry from details.cursor.", cursor)
|
|
165
|
-
end
|
|
166
|
-
failures += 1 unless continued
|
|
167
|
-
if failures > RECONNECTS
|
|
168
|
-
raise failure("build_log_interrupted", "Reconnect with logs(id, follow: true, cursor: details[\"cursor\"]).", cursor)
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
# A service that is down, or continuations one after another, never busy-loop.
|
|
172
|
-
pause = 0.05 * [1, failures].max
|
|
173
|
-
pause = [pause, [deadline - now, 0].max].min if deadline
|
|
174
|
-
sleep(pause)
|
|
175
|
-
end
|
|
176
|
-
end
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
# +runtime.builds.repositories+: the repositories Runtime builds. Every push
|
|
180
|
-
# to a repository's production branch builds it and deploys it to its
|
|
181
|
-
# +deploy+ target. In the Builds private beta (product_in_beta, 403, outside it).
|
|
182
|
-
#
|
|
183
|
-
# A repository: id, name, labels, provider (github or git), repository,
|
|
184
|
-
# deploy (app:<id>, function:<id> or container:<id>), production_branch,
|
|
185
|
-
# previews, root_directory, install_command, build_command, start_command,
|
|
186
|
-
# port, health_path, build_env, state (connected or disconnected), error,
|
|
187
|
-
# created_at, updated_at and deleted_at.
|
|
188
|
-
class Repositories < Product
|
|
189
|
-
# Connects +repository+ from +provider+ ("github" or "git") to +deploy+.
|
|
190
|
-
# Optional: production_branch, previews, root_directory, install_command
|
|
191
|
-
# (chosen by the lockfile when left out), build_command, start_command
|
|
192
|
-
# (the build then ends as that server, answering health_path with 200),
|
|
193
|
-
# port, health_path, build_env (never a secret: anyone who reads the
|
|
194
|
-
# repository sees it), name and labels.
|
|
195
|
-
def connect(provider:, repository:, deploy:, idempotency_key: nil, **settings)
|
|
196
|
-
body = Fields.body(settings.merge(provider: provider, repository: repository, deploy: deploy))
|
|
197
|
-
Record.new(@t.json("POST", "/v1/repositories", body: body, key: idempotency_key))
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
def list(name: nil, label: nil, state: nil, limit: nil, cursor: nil)
|
|
201
|
-
page("/v1/repositories", { "name" => name, "label" => label, "state" => state, "limit" => limit, "cursor" => cursor })
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
# Changes settings in place; its id and builds stay. Fields left out stay
|
|
205
|
-
# as they are; +:remove+ clears name, install_command, build_command,
|
|
206
|
-
# start_command or health_path.
|
|
207
|
-
def update(id, idempotency_key: nil, **changes)
|
|
208
|
-
Record.new(@t.json("POST", "/v1/repositories/#{seg(id)}:update", body: patch(changes), key: idempotency_key))
|
|
209
|
-
end
|
|
210
|
-
|
|
211
|
-
def disconnect(id, idempotency_key: nil) = Record.new(@t.json("DELETE", "/v1/repositories/#{seg(id)}", key: idempotency_key))
|
|
212
|
-
|
|
213
|
-
# A link (url, expires_at) to install Runtime's GitHub App, so private
|
|
214
|
-
# repositories build. Open it in a browser within 15 minutes, install the
|
|
215
|
-
# App where Runtime may read, then connect the repository with provider github.
|
|
216
|
-
def install_github = Record.new(@t.json("POST", "/v1/repositories/github:install"))
|
|
217
|
-
end
|
|
218
|
-
end
|
data/lib/withruntime/ci.rb
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module WithRuntime
|
|
4
|
-
# +runtime.ci+: CI/CD. A connected repository's checks run as jobs in
|
|
5
|
-
# sandboxes. In a private beta: an account outside it is refused with
|
|
6
|
-
# product_in_beta (403, PermissionDeniedError). Times are Unix milliseconds.
|
|
7
|
-
#
|
|
8
|
-
# repo = runtime.ci.repositories.connect("acme/web")
|
|
9
|
-
# check = runtime.ci.checks.list(repository_id: repo.id, state: ["failed"]).first
|
|
10
|
-
# job = runtime.ci.checks.get(check.id).jobs.first
|
|
11
|
-
# puts runtime.ci.jobs.get(job.id).log
|
|
12
|
-
class CI < Product
|
|
13
|
-
attr_reader :repositories, :checks, :jobs, :tests, :flakes, :releases
|
|
14
|
-
|
|
15
|
-
def initialize(transport)
|
|
16
|
-
super
|
|
17
|
-
@repositories = CIRepositories.new(transport)
|
|
18
|
-
@checks = CIChecks.new(transport)
|
|
19
|
-
@jobs = CIJobs.new(transport)
|
|
20
|
-
@tests = CITests.new(transport)
|
|
21
|
-
@flakes = CIFlakes.new(transport)
|
|
22
|
-
@releases = CIReleases.new(transport)
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
# +runtime.ci.repositories+: the repositories whose checks run.
|
|
27
|
-
#
|
|
28
|
-
# A repository: id, name, labels, repository (owner/name), production_branch,
|
|
29
|
-
# config_path, installation, github_repository_id, undo_culprits (whether a
|
|
30
|
-
# red production branch's culprit is undone: set_undo), state (connected or
|
|
31
|
-
# disconnected), error, created_at, updated_at and deleted_at.
|
|
32
|
-
class CIRepositories < Product
|
|
33
|
-
# Connects +repository+ ("owner/name"), read through Runtime's GitHub App.
|
|
34
|
-
# Pushes and pull requests then run the checks written in +config_path:+
|
|
35
|
-
# (runtime.yml; a cloudbuild.yaml or buildspec.yml runs as Cloud Build or
|
|
36
|
-
# CodeBuild runs it). Optional: production_branch (main), config_path,
|
|
37
|
-
# installation (the GitHub App installation to read it through; the newest
|
|
38
|
-
# when left out), name and labels.
|
|
39
|
-
def connect(repository, production_branch: nil, config_path: nil, installation: nil, name: nil, labels: nil,
|
|
40
|
-
idempotency_key: nil)
|
|
41
|
-
body = Fields.body(repository: repository, production_branch: production_branch, config_path: config_path,
|
|
42
|
-
installation: installation, name: name, labels: labels)
|
|
43
|
-
Record.new(@t.json("POST", "/v1/ci/repositories", body: body, key: idempotency_key))
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
# +label+ is "key:value" strings, +state+ connected or disconnected.
|
|
47
|
-
def list(name: nil, label: nil, state: nil, limit: nil, cursor: nil)
|
|
48
|
-
page("/v1/ci/repositories", { "name" => name, "label" => label, "state" => state, "limit" => limit, "cursor" => cursor })
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
# Turns on (or off) the undo of a red production branch's culprit: when
|
|
52
|
-
# main's check fails, CI/CD finds the first commit that fails it and opens
|
|
53
|
-
# a pull request reverting it, which lands once its own check passes. Off
|
|
54
|
-
# until set; only an owner's or admin's full key sets it.
|
|
55
|
-
def set_undo(id, on, idempotency_key: nil)
|
|
56
|
-
Record.new(@t.json("POST", "/v1/ci/repositories/#{seg(id)}:update", body: { "undoCulprits" => on },
|
|
57
|
-
key: idempotency_key))
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
# Stops running its checks; the checks already run stay readable.
|
|
61
|
-
def disconnect(id, idempotency_key: nil)
|
|
62
|
-
Record.new(@t.json("DELETE", "/v1/ci/repositories/#{seg(id)}", key: idempotency_key))
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
# +runtime.ci.checks+: one run of a commit's jobs.
|
|
67
|
-
#
|
|
68
|
-
# A check: id, repository_id, repository, commit, branch, event, pull_request,
|
|
69
|
-
# base_commit, actor, trusted, waiting, approved_by, approved_at, landed,
|
|
70
|
-
# state (queued, running, passed, failed or cancelled), reason, counts (jobs
|
|
71
|
-
# per state), machines (where its machines came from and how soon, or nil),
|
|
72
|
-
# created_at, updated_at, started_at and ended_at.
|
|
73
|
-
class CIChecks < Product
|
|
74
|
-
# Checks, newest first. +state+ is any of queued, running, passed, failed,
|
|
75
|
-
# cancelled; +event+ any of push, pull_request, merge_group (GitHub's merge
|
|
76
|
-
# queue) or rerun; +commit+ is a full sha.
|
|
77
|
-
def list(repository_id: nil, state: nil, event: nil, branch: nil, commit: nil, pull_request: nil, limit: nil,
|
|
78
|
-
cursor: nil)
|
|
79
|
-
page("/v1/ci/checks", { "repositoryId" => repository_id, "state" => state, "event" => event, "branch" => branch,
|
|
80
|
-
"commit" => commit, "pullRequest" => pull_request, "limit" => limit,
|
|
81
|
-
"cursor" => cursor })
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
# The check with its +jobs+ in plan order (no log).
|
|
85
|
-
def get(id) = Record.new(@t.json("GET", "/v1/ci/checks/#{seg(id)}"))
|
|
86
|
-
|
|
87
|
-
# Cancels a queued or running check: its jobs end and its machines are let
|
|
88
|
-
# go. A check that has ended is answered as it is.
|
|
89
|
-
def cancel(id) = Record.new(@t.json("POST", "/v1/ci/checks/#{seg(id)}:cancel"))
|
|
90
|
-
|
|
91
|
-
# Runs a check again, as GitHub's Re-run does: a new check of the same
|
|
92
|
-
# commit, trusted only as the commit's last check was.
|
|
93
|
-
def rerun(id) = Record.new(@t.json("POST", "/v1/ci/checks/#{seg(id)}:rerun"))
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
# +runtime.ci.jobs+: one command of a check, run in sandboxes.
|
|
97
|
-
class CIJobs < Product
|
|
98
|
-
# The job with its +log+ (the tail, at most 256 KiB). A failed job's
|
|
99
|
-
# sandbox_ids may be kept paused: wake one or exec in it with
|
|
100
|
-
# +runtime.sandboxes+. An agent step's job (+review:+ is its short form)
|
|
101
|
-
# has its +review+: the verdict (pass or block), summary, findings (kind,
|
|
102
|
-
# file, line, what, fix), notes, and the agent, the model the step asked
|
|
103
|
-
# for (nil when none) and the session that gave it; nil otherwise.
|
|
104
|
-
# +annotations+ are the lines of the repository's files its log reports
|
|
105
|
-
# (path, start_line, end_line, start_column, level: notice, warning or
|
|
106
|
-
# failure, message, title), at most 50, failures first, as its own GitHub
|
|
107
|
-
# check run (+github_check_run+, "runtime / <name>") shows them.
|
|
108
|
-
def get(id) = Record.new(@t.json("GET", "/v1/ci/jobs/#{seg(id)}"))
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
# +runtime.ci.tests+: a repository's test files and their recent runs.
|
|
112
|
-
class CITests < Product
|
|
113
|
-
# Test files by name: file, ms, quarantined_since (their failures do not
|
|
114
|
-
# fail a check), runs and updated_at.
|
|
115
|
-
def list(repository_id, quarantined: nil, limit: nil, cursor: nil)
|
|
116
|
-
page("/v1/ci/tests", { "repositoryId" => repository_id, "quarantined" => quarantined, "limit" => limit, "cursor" => cursor })
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
# +runtime.ci.flakes+: tests that passed and failed on the same inputs, one
|
|
121
|
-
# run main's. Each is quarantined at once (it still runs and reports, and
|
|
122
|
-
# blocks nothing), or still gating when the repository protects it; handed
|
|
123
|
-
# to an owner with 48 hours to fix it or delete it with a reason; fixed once
|
|
124
|
-
# 100 runs of a main commit in parallel forks all pass.
|
|
125
|
-
#
|
|
126
|
-
# A flake: id, repository_id, file, state (quarantined, gating, fixed or
|
|
127
|
-
# deleted), gates, proof, again, owner (login, from, pull_request, branch),
|
|
128
|
-
# since, due_at, overdue, tried, prove_asked_at, delete_reason, ended_at,
|
|
129
|
-
# ended_check_id and updated_at; with a get or an update, its runs and
|
|
130
|
-
# failures too.
|
|
131
|
-
class CIFlakes < Product
|
|
132
|
-
# Flaky tests, newest first. +state+ is any of quarantined, gating (the
|
|
133
|
-
# open ones), fixed, deleted.
|
|
134
|
-
def list(repository_id: nil, state: nil, limit: nil, cursor: nil)
|
|
135
|
-
page("/v1/ci/flakes", { "repositoryId" => repository_id, "state" => state, "limit" => limit, "cursor" => cursor })
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
# The flake with its test file's newest 200 +runs+ (by commit and content
|
|
139
|
-
# key) and its +failures+' jobs, whose logs +runtime.ci.jobs.get+ reads.
|
|
140
|
-
def get(id) = Record.new(@t.json("GET", "/v1/ci/flakes/#{seg(id)}"))
|
|
141
|
-
|
|
142
|
-
# +prove: true+ asks for its 100 proof runs at main's next commit; +owner:+
|
|
143
|
-
# hands it to a GitHub login or org/team; +delete_reason:+ says why its
|
|
144
|
-
# test is deleted (it ends once main no longer holds the file).
|
|
145
|
-
def update(id, prove: nil, owner: nil, delete_reason: nil, idempotency_key: nil)
|
|
146
|
-
body = Fields.body(prove: prove, owner: owner, delete_reason: delete_reason)
|
|
147
|
-
Record.new(@t.json("POST", "/v1/ci/flakes/#{seg(id)}:update", body: body, key: idempotency_key))
|
|
148
|
-
end
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
# +runtime.ci.releases+: the steps each release took, as it took them: a
|
|
152
|
-
# migration's copy test or apply, a deploy ref moved, a server's canary or
|
|
153
|
-
# release, the website's deploy or promote, or a wait and why. Only
|
|
154
|
-
# repositories whose releases CI/CD runs have any.
|
|
155
|
-
#
|
|
156
|
-
# A step: id, repository_id, commit, source (mover, or the deploy target
|
|
157
|
-
# that walked it), host (or nil), line and at.
|
|
158
|
-
class CIReleases < Product
|
|
159
|
-
# Steps, newest first; +commit:+ keeps one release's.
|
|
160
|
-
def list(repository_id: nil, commit: nil, limit: nil, cursor: nil)
|
|
161
|
-
page("/v1/ci/releases", { "repositoryId" => repository_id, "commit" => commit, "limit" => limit, "cursor" => cursor })
|
|
162
|
-
end
|
|
163
|
-
end
|
|
164
|
-
end
|
data/lib/withruntime/client.rb
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module WithRuntime
|
|
4
|
-
DEFAULT_BASE_URL = "https://api.withruntime.com"
|
|
5
|
-
|
|
6
|
-
# One client for every Runtime Cloud product. Make it once and share it: it
|
|
7
|
-
# is safe for use from many threads and keeps its connections open.
|
|
8
|
-
#
|
|
9
|
-
# runtime = WithRuntime::Client.new # RUNTIME_API_KEY, or this machine's saved connection
|
|
10
|
-
# sbx = runtime.sandboxes.create
|
|
11
|
-
# sbx.files.write("/workspace/invoice.py", "print(sum([125, 250, 375]))\n")
|
|
12
|
-
# puts sbx.exec("python3 /workspace/invoice.py", check: true).stdout
|
|
13
|
-
# sbx.stop
|
|
14
|
-
#
|
|
15
|
-
# Every product is +runtime.<product>.<verb>+. Money is integer microdollars
|
|
16
|
-
# (1,000,000 is one US dollar).
|
|
17
|
-
# The account's networks: +wireguard+, a tunnel from your own network into
|
|
18
|
-
# your sandboxes.
|
|
19
|
-
Networks = Struct.new(:wireguard)
|
|
20
|
-
|
|
21
|
-
# The day the 6 October 2026 rename stops serving its old names, set when it
|
|
22
|
-
# ships (packages/cloud/src/product-names.ts); nil until then.
|
|
23
|
-
RENAME_RETIRES = nil
|
|
24
|
-
|
|
25
|
-
class Client
|
|
26
|
-
attr_reader :transport, :sandboxes, :snapshots, :images, :volumes, :secrets, :reservations, :limits, :jobs, :emails, :referrals, :plans,
|
|
27
|
-
:switching, :events, :webhooks, :otel, :audit, :feedback, :support, :domains, :ports, :ips, :networks, :sso, :mcp, :agents,
|
|
28
|
-
:apps, :functions, :builds, :ci, :containers, :browsers
|
|
29
|
-
|
|
30
|
-
# +api_key+: default RUNTIME_API_KEY, then this machine's saved connection.
|
|
31
|
-
# +base_url+: default RUNTIME_API_URL, then https://api.withruntime.com.
|
|
32
|
-
# Inside a Runtime sandbox, calls for https://api.withruntime.com go to
|
|
33
|
-
# http://runtime.internal.
|
|
34
|
-
# +timeout+: seconds for each call, retries included (300).
|
|
35
|
-
# +max_retries+: of transport failures, 429, 502, 503 and 504 (4).
|
|
36
|
-
# +max_connections+: calls in flight at once; streams do not count (32).
|
|
37
|
-
# +wait_for_capacity+: seconds a sandbox create, wake or restart keeps retrying, with the
|
|
38
|
-
# same key and input, when the slots without credit, quota or region are full (120; 0 fails at once).
|
|
39
|
-
def initialize(api_key: nil, base_url: nil, timeout: 300, max_retries: 4, max_connections: 32,
|
|
40
|
-
wait_for_capacity: 120, env: ENV, in_sandbox: -> { Credentials.in_runtime_sandbox? })
|
|
41
|
-
origin = Credentials.origin(base_url || env["RUNTIME_API_URL"].then { |url| url.nil? || url.empty? ? DEFAULT_BASE_URL : url })
|
|
42
|
-
key = api_key
|
|
43
|
-
key ||= env["RUNTIME_API_KEY"] unless env["RUNTIME_API_KEY"].to_s.empty?
|
|
44
|
-
key ||= Credentials.saved_key(env, origin)
|
|
45
|
-
raise Error.missing_key if key.nil? || key.empty?
|
|
46
|
-
raise ArgumentError, "The Runtime API key contains whitespace." if key.match?(/\s/)
|
|
47
|
-
raise ArgumentError, "max_retries cannot be negative." if max_retries.negative?
|
|
48
|
-
|
|
49
|
-
# The saved key is found by the origin as given; the calls go where that
|
|
50
|
-
# origin is reachable from here.
|
|
51
|
-
@transport = Transport.new(api_key: key, base_url: Credentials.reachable(origin, in_sandbox: in_sandbox),
|
|
52
|
-
timeout: timeout, max_retries: max_retries,
|
|
53
|
-
max_connections: max_connections, wait_for_capacity: [0, wait_for_capacity].max)
|
|
54
|
-
@sandboxes = Sandboxes.new(@transport)
|
|
55
|
-
@snapshots = Snapshots.new(@transport)
|
|
56
|
-
@images = Images.new(@transport)
|
|
57
|
-
@volumes = Volumes.new(@transport)
|
|
58
|
-
@secrets = Secrets.new(@transport)
|
|
59
|
-
@reservations = Reservations.new(@transport)
|
|
60
|
-
@limits = Limits.new(@transport)
|
|
61
|
-
@jobs = Jobs.new(@transport)
|
|
62
|
-
@emails = Emails.new(@transport)
|
|
63
|
-
@referrals = Referrals.new(@transport)
|
|
64
|
-
@plans = Plans.new(@transport)
|
|
65
|
-
@switching = Switching.new(@transport)
|
|
66
|
-
@events = Events.new(@transport)
|
|
67
|
-
@webhooks = Webhooks.new(@transport)
|
|
68
|
-
@otel = Otel.new(@transport)
|
|
69
|
-
@audit = Audit.new(@transport)
|
|
70
|
-
@feedback = Feedback.new(@transport)
|
|
71
|
-
@support = Support.new(@transport)
|
|
72
|
-
@domains = Domains.new(@transport)
|
|
73
|
-
@ports = Ports.new(@transport)
|
|
74
|
-
@ips = Addresses.new(@transport)
|
|
75
|
-
@networks = Networks.new(PrivateTunnel.new(@transport))
|
|
76
|
-
@sso = SSO.new(@transport)
|
|
77
|
-
@mcp = MCP.new(@transport)
|
|
78
|
-
@agents = Agents.new(@transport)
|
|
79
|
-
# Private beta: outside it, product_in_beta (403).
|
|
80
|
-
@apps = Apps.new(@transport, "/v1/apps")
|
|
81
|
-
@functions = Apps.new(@transport, "/v1/functions")
|
|
82
|
-
@builds = Builds.new(@transport)
|
|
83
|
-
@ci = CI.new(@transport)
|
|
84
|
-
@containers = Containers.new(@transport)
|
|
85
|
-
@browsers = Browsers.new(@transport)
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
# Renamed on 6 October 2026, one plural word per product: each old name is the product it became, with a warning,
|
|
89
|
-
# until RENAME_RETIRES, then raises name_retired.
|
|
90
|
-
def addresses = renamed("addresses", "ips") { @ips }
|
|
91
|
-
def tunnel = renamed("tunnel", "networks.wireguard") { @networks.wireguard }
|
|
92
|
-
|
|
93
|
-
def base_url = @transport.base_url
|
|
94
|
-
|
|
95
|
-
# Who this key is: organization, agent and credential.
|
|
96
|
-
def me = Record.new(@transport.json("GET", "/v1/me"))
|
|
97
|
-
|
|
98
|
-
# The account's credit, holds, free time and per-resource charges.
|
|
99
|
-
def usage = Record.new(@transport.json("GET", "/v1/usage"))
|
|
100
|
-
|
|
101
|
-
# One page of settled usage for every product the key sees: settled at
|
|
102
|
-
# +since+ or later and before +until+ (UTC, ending in Z). Follow
|
|
103
|
-
# +next_cursor+ with the same range until it is nil; concatenate each
|
|
104
|
-
# page's +csv+ (the header is on the first only). Money and quantities are
|
|
105
|
-
# exact decimal strings. +final_through+: no row settled before it can
|
|
106
|
-
# still appear or change, so the range is final once it reaches +until+.
|
|
107
|
-
# A row's +final+ is true once its resource is deleted and can be charged
|
|
108
|
-
# nothing more.
|
|
109
|
-
def usage_export(since:, until:, cursor: nil, limit: nil)
|
|
110
|
-
# until is a Ruby keyword: its argument is read through the binding.
|
|
111
|
-
query = { "since" => since, "until" => binding.local_variable_get(:until), "cursor" => cursor, "limit" => limit }
|
|
112
|
-
Record.new(@transport.json("GET", "/v1/usage/export", query: query))
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
# Calls any API path with this client's key, retries, idempotency keys and
|
|
116
|
-
# errors, and returns the parsed JSON answer. For an endpoint newer than this SDK.
|
|
117
|
-
def request(method, path, query: nil, body: nil)
|
|
118
|
-
raise ArgumentError, "The path must start with /." unless path.start_with?("/")
|
|
119
|
-
|
|
120
|
-
method = method.to_s.upcase
|
|
121
|
-
body = {} if body.nil? && !%w[GET DELETE].include?(method)
|
|
122
|
-
@transport.json(method, path, query: query, body: body)
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
private
|
|
126
|
-
|
|
127
|
-
def renamed(old, new, retires: RENAME_RETIRES, now: Time.now.utc)
|
|
128
|
-
if retires && now >= Time.utc(*retires.split("-").map(&:to_i))
|
|
129
|
-
raise Error.new("runtime.#{old} was renamed runtime.#{new} and stopped working on #{retires}.",
|
|
130
|
-
code: "name_retired", status: 410, hint: "Use runtime.#{new}.")
|
|
131
|
-
end
|
|
132
|
-
@renamed_said ||= {}
|
|
133
|
-
unless @renamed_said[old]
|
|
134
|
-
@renamed_said[old] = true
|
|
135
|
-
warn("Runtime: runtime.#{old} is now runtime.#{new}.#{retires ? " It stops working on #{retires}." : ""}")
|
|
136
|
-
end
|
|
137
|
-
yield
|
|
138
|
-
end
|
|
139
|
-
end
|
|
140
|
-
end
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module WithRuntime
|
|
4
|
-
# +runtime.containers+: one OCI image's process on its own microVM, billed
|
|
5
|
-
# at the sandbox rates, at /v1/containers. In a private beta: an account
|
|
6
|
-
# outside it is refused with product_in_beta (403, PermissionDeniedError).
|
|
7
|
-
#
|
|
8
|
-
# box = runtime.containers.create(image: "nginx:1.27", vcpu: 1, memory_mib: 512, name: "web")
|
|
9
|
-
# box = runtime.containers.wait(box.id, "running")
|
|
10
|
-
# puts box.port
|
|
11
|
-
#
|
|
12
|
-
# A container: id, name, labels, state (waiting, running, sleeping, stopped,
|
|
13
|
-
# failed, deleting, deleted), image (pinned to its digest), entrypoint,
|
|
14
|
-
# command, working_dir, user, port (or nil), exposed_ports, on_exit, sleep,
|
|
15
|
-
# vcpu, memory_mib, env_names (the environment's names, never its values),
|
|
16
|
-
# error ({code, message} or nil), created_at, updated_at and deleted_at.
|
|
17
|
-
class Containers < ResourceProduct
|
|
18
|
-
def initialize(transport)
|
|
19
|
-
super(transport, "/v1/containers", %w[failed deleted])
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
# Runs one copy of +image:+ (an OCI reference; the answer pins its digest)
|
|
23
|
-
# with +vcpu:+ (1 to 16) and +memory_mib:+ (128 to 65536), all required.
|
|
24
|
-
# +entrypoint:+ replaces the image's Entrypoint and drops its Cmd;
|
|
25
|
-
# +command:+ replaces its Cmd. +env:+ is set over the image's own and never
|
|
26
|
-
# read back, only its names. +port:+ (1 to 65535) is required when the
|
|
27
|
-
# image exposes several TCP ports. +on_exit:+ is "restart" or "stop": by
|
|
28
|
-
# default it restarts when it serves a port, else stops. It never sleeps
|
|
29
|
-
# unless +sleep: true+. Also +name:+, +labels:+, +working_dir:+ and +user:+.
|
|
30
|
-
def create(idempotency_key: nil, **fields) = super
|
|
31
|
-
|
|
32
|
-
# Only +name:+ and +labels:+ change; +name: :remove+ clears the name.
|
|
33
|
-
def update(id, idempotency_key: nil, **changes) = super
|
|
34
|
-
|
|
35
|
-
# Follows its state to +target+ ("running", say); reaching failed or
|
|
36
|
-
# deleted first raises with its error.
|
|
37
|
-
def wait(id, target, timeout: 300, poll: 0.25) = super
|
|
38
|
-
end
|
|
39
|
-
end
|