sandcovery 0.5.1 → 0.6.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.
- package/README.md +2 -2
- package/dist/cli/index.mjs +1 -1
- package/dist/cli/sandcovery-docker.mjs +1 -1
- package/dist/cli/sandcovery-kubectl.mjs +1 -1
- package/dist/{handlers-CGHTslWU.mjs → handlers-U3pqRNro.mjs} +96 -8
- package/dist/index.d.mts +3 -1
- package/dist/index.mjs +1 -1
- package/dist/{port-forwarder-Dot4oNtz.mjs → port-forwarder-Du1VlKxg.mjs} +176 -71
- package/dist/{src-BoT9S6C3.mjs → src-lrpT0LG_.mjs} +1143 -1108
- package/dist/{start-C2p7R_Hj.mjs → start-Dg7sRQ28.mjs} +3 -3
- package/dist/{types-BGjvzP6q.d.mts → types-C7lGEXT5.d.mts} +18 -3
- package/dist/types.d.mts +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -68,7 +68,7 @@ sandcovery sandboxes destroy "$id" --yes
|
|
|
68
68
|
- `sandcovery-kubectl <args>` does the same on the same cluster, takes `kubectl`'s arguments alone, and adds nothing to `kubectl`'s stdout or stderr, so `alias kubectl=sandcovery-kubectl` runs `kubectl` on the sandbox's cluster. It reads the key from `SANDCOVERY_API_KEY` or the saved login.
|
|
69
69
|
- `--json` prints one JSON document on stdout, and every failure prints a JSON error with a stable `reason` on stderr.
|
|
70
70
|
- `sandboxes destroy`, `keys revoke`, `credentials delete`, and `x-account unlink` ask first, and need `--yes` without a terminal.
|
|
71
|
-
- `sandcovery providers list --routed` lists only the providers Sandcovery routes to, `sandcovery credentials offer` shows the free vCPU-hours your keys have earned, `sandcovery credentials count-x-post <URL>` counts your post on X that tags @Sandcovery as one key, `sandcovery pricing inspect` shows the Pro price and the credit terms with no key, `sandcovery pricing monthly --size 2x4 --hours-per-day 8` prices a size for a month on each provider Sandcovery routes to with no key,
|
|
71
|
+
- `sandcovery providers list --routed` lists only the providers Sandcovery routes to, `sandcovery credentials offer` shows the free vCPU-hours your keys have earned, `sandcovery credentials count-x-post <URL>` counts your post on X that tags @Sandcovery as one key, `sandcovery pricing inspect` shows the Pro price and the credit terms with no key, `sandcovery pricing monthly --size 2x4 --hours-per-day 8` prices a size for a month on each provider Sandcovery routes to with no key, `sandcovery billing inspect` and `sandcovery billing buy-credits --amount <USD>` show the plan and start a credit payment, and `sandcovery billing set-auto-top-up --amount <USD> --threshold <USD>` and `sandcovery billing stop-auto-top-up` turn auto top-up on and off.
|
|
72
72
|
- `sandcovery x-account inspect` shows the X account linked to you, `sandcovery x-account link` prints the dashboard page where you link one, since X confirms the link in the browser, and `sandcovery x-account unlink` unlinks it.
|
|
73
73
|
- `sandcovery problems report <text> --page <path>` tells the Sandcovery team about a problem with no key, as `sandcovery.problems.report({ message, path })` does from code.
|
|
74
74
|
- `sandcovery help search <words>` finds a command, and `--help` works on every command.
|
|
@@ -94,7 +94,7 @@ await admin.credentials.set('e2b', { api_key: process.env.E2B_API_KEY })
|
|
|
94
94
|
|
|
95
95
|
An organization holds as many credentials as it needs: `credentials.add(provider, fields)` adds another, a create tries a provider's credentials in the order they were added, and `credentials.deleteOne(provider, id)` deletes one. A Free organization routes only its oldest credential, and `paused` is `true` on each other one until it has Pro.
|
|
96
96
|
|
|
97
|
-
The fields each provider takes are its `credential_fields` on `sandcovery.providers.get(provider)`. `sandcovery.providers.catalog()` lists every provider on the [provider board](https://www.sandcovery.com/providers), where `routed` is `false` for a provider that is coming soon. `credentials.offer()` reads the free vCPU-hours your keys have earned, `credentials.countXPost({ url })` counts your post on X that tags @Sandcovery as one key, `billing.get()` reads the plan
|
|
97
|
+
The fields each provider takes are its `credential_fields` on `sandcovery.providers.get(provider)`. `sandcovery.providers.catalog()` lists every provider on the [provider board](https://www.sandcovery.com/providers), where `routed` is `false` for a provider that is coming soon. `credentials.offer()` reads the free vCPU-hours your keys have earned, `credentials.countXPost({ url })` counts your post on X that tags @Sandcovery as one key, `billing.get()` reads the plan, the credit balance, and auto top-up, `billing.buyCredits({ amount_micro_usd })` answers the Stripe Checkout page that takes a credit payment, `billing.setAutoTopUp({ amount_micro_usd, threshold_micro_usd })` sets the amount Sandcovery charges the saved card each time the credit balance falls below the threshold and answers the Stripe Checkout page that saves a card when none is saved, and `billing.stopAutoTopUp()` turns auto top-up off.
|
|
98
98
|
|
|
99
99
|
## X account
|
|
100
100
|
|
package/dist/cli/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { $ as CurrentRedactedNames, $n as merge$1, $t as timeoutOrElse, An as exitInterrupt$1, Ar as toJson, At as interrupt$1, B as makeFilter, Bn as TaggedError, Br as isString, Bt as provide, C as decodeUnknownEffect, Cn as hasInterrupts, Cr as makePrimitive, Ct as fail$2, D as encodeSync, Dn as andThen, Dr as BaseProto, Dt as forever, E as decodeUnknownSync, Er as setStackTraceLimit, Et as fnUntraced, Fn as succeed, Fr as symbol$1, Ft as onExit$1, G as CurrentRedactedNames$1, Gn as of, Gr as identity, Gt as runPromise, H as optionalKey, Hn as seconds, Hr as constTrue, Ht as provideService, In as suspend$2, Ir as hasProperty, It as onExitPrimitive, J as redactUrl, Jn as isSuccess, Jt as succeed$1, K as empty$2, Kn as getSuccess, Kr as pipeArguments, Kt as runSync, Ln as sync, Lr as isNotNull, Lt as onInterrupt, M as isGreaterThan, Mn as exitZipRight, Mr as redact, Mt as mapError, Nn as fiberInterrupt, Nr as symbol, Nt as matchCauseEffect, O as fromJsonString, On as callback, Or as Class, Ot as forkIn, P as isMaxCodePoints, Pn as makeLatchUnsafe, Pr as random, Pt as onError, Q as unwrap, Qn as getOrUndefined$1, R as isSchemaError, Rn as TracerTimingEnabled$1, Rr as isNotNullish, Rt as orElseSucceed, S as decodeTo, Sn as done, Sr as isExit, St as ensuring$2, T as decodeUnknownResult, Tn as squash, Tr as getStackTraceLimit, Tt as flatMap, Ur as constVoid, V as optional, Vr as constFalse, Vt as provideContext, W as makeFormatterStandardSchemaV1, Wn as toSeconds, Wr as dual, Wt as runFork, X as toString, Xn as Reference, Xt as sync$1, Y as setAll$1, Yn as try_, Yt as suspend$3, Z as fromBody, Zn as Service$1, Zt as tap$1, _ as String$1, _n as close, _r as args, _t as catchIf, an as void_, at as remove, b as Unknown, bn as fail$3, br as exitFailCause, bt as contextWith, c as Json, cn as withParentSpan, cr as isSome, ct as fromSetCookie, dn as catchDone, dr as match, dt as as$1, en as tryPromise, er as exists$1, et as empty$3, fn as doneExitFromCause, fr as none, ft as asVoid, g as Record, gn as addFinalizerExit, gr as PipeInspectableProto, hn as addFinalizer, hr as Done, ht as catchCause, in as useSpan, ir as getOrNull, it as merge$2, jn as exitVoid, jr as format, jt as map, k as is$1, kr as NodeInspectSymbol, kt as gen, l as Literal, lr as liftThrowable, m as NullOr, mn as effect, mr as toArray, mt as callback$1, nn as uninterruptibleMask, nr as fromNullishOr, nt as fromRecordUnsafe, o as FiniteFromString, on as whileLoop, or as getOrUndefined, ot as set, p as NonEmptyString, pn as isDoneCause, pr as some, pt as cached, q as fromInput, qn as isFailure, qt as sleep, r as DateFromString, rn as updateContext, rr as getOrElse, rt as isRedactedName, s as Int, sn as withFiber$1, sr as isNone, st as setAll, t as ArraySchema, tn as try_$1, tr as flatMap$1, tt as fromInput$1, u as Literals, ur as map$1, ut as andThen$1, v as Struct, vn as forkUnsafe, vr as evaluate, vt as catchTag, w as decodeUnknownOption, wn as isTimeoutError, wr as withFiber, wt as failCause$1, xn as TimeoutError, xr as exitSucceed, y as Union, yn as makeUnsafe$1, yr as exitFail, yt as context, zn as DisablePropagation, zr as isPropertyKey, zt as promise } from "./Schema-CoX0a2_o.mjs";
|
|
2
|
-
import { C as enabledVariable, F as rerunArgv, I as valuesOf$1, O as flagOf, Q as CliFailure, R as ellipsis, S as writePrivateFile, U as escapeUnprintable, Y as isDigits, Z as isWordCharacter, _ as formatMoney, a as RELAY_PORT, at as holdCluster, c as onPath, ct as Clock, d as BIN, f as CLEARABLE, g as formatCount, h as counted, i as forwarderSocket, j as lastValue, m as PROBLEM_REPORT_MAX, n as attachForwarder, nt as Canceled, o as RELAY_SOURCE, q as consistsOf, rt as IDLE_MS, s as v7, st as noop, tt as usageFailure, u as shimsOf, v as formatPercent, x as withFileLock, y as version } from "./port-forwarder-
|
|
3
|
-
import { A as
|
|
2
|
+
import { C as enabledVariable, F as rerunArgv, I as valuesOf$1, O as flagOf, Q as CliFailure, R as ellipsis, S as writePrivateFile, U as escapeUnprintable, Y as isDigits, Z as isWordCharacter, _ as formatMoney, a as RELAY_PORT, at as holdCluster, c as onPath, ct as Clock, d as BIN, f as CLEARABLE, g as formatCount, h as counted, i as forwarderSocket, j as lastValue, m as PROBLEM_REPORT_MAX, n as attachForwarder, nt as Canceled, o as RELAY_SOURCE, q as consistsOf, rt as IDLE_MS, s as v7, st as noop, tt as usageFailure, u as shimsOf, v as formatPercent, x as withFileLock, y as version } from "./port-forwarder-Du1VlKxg.mjs";
|
|
3
|
+
import { A as NO_MARKUP_TERMS, C as AUTO_TOP_UP_THRESHOLD_MIN_MICRO_USD, D as ENTERPRISE_PLAN, E as CREDIT_PURCHASE_MIN_MICRO_USD, G as CiJobId, J as KeySecret, K as CredentialId, L as CreateSandboxRequest, M as thresholdBelowTopUp, N as ApiError, O as FREE_PLAN, Q as UsageShareId, R as Port, S as AUTO_TOP_UP_THRESHOLD_MAX_MICRO_USD, T as CREDIT_PURCHASE_MAX_MICRO_USD, V as ProviderSort, W as ApiKeyId, X as Provider, Y as ProcessId, Z as SandboxId, _ as KeyKind, a as USAGE_SHARE_FIGURES, b as CredentialFields, c as EstimateRequest, d as UsagePeriod, f as API_PREFIX, g as CreateKeyRequest, i as ShareToken, j as creditsAfterFeeMicroUsd, k as MICRO_USD_PER_DOLLAR, l as MONTH_TEXT, m as SANDCOVERY_ORIGIN, n as CreateUsageShareRequest, o as UsageShareFigure, p as LocalPath, q as KeyId, r as DEFAULT_SHARED_FIGURES, s as CalendarDay, t as Sandcovery, u as MonthlyCostQuery, v as SpendLimit, x as GitHubId, y as UpdateKeyRequest, z as SandboxStatus } from "./src-lrpT0LG_.mjs";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
import { spawn } from "node:child_process";
|
|
6
6
|
import { createHash, randomBytes } from "node:crypto";
|
|
@@ -4713,11 +4713,21 @@ const activityList = async (context) => {
|
|
|
4713
4713
|
// src/cli/commands/billing.ts
|
|
4714
4714
|
const BILLING_TARGET = "billing, which opens once Sandcovery sells credits";
|
|
4715
4715
|
const AMOUNT_FLAG = "--amount";
|
|
4716
|
+
const THRESHOLD_FLAG = "--threshold";
|
|
4717
|
+
const AUTO_TOP_UP_FLAGS = ["amount", "threshold"];
|
|
4716
4718
|
const PLAN_NAMES = {
|
|
4717
4719
|
[ENTERPRISE_PLAN]: "Enterprise",
|
|
4718
4720
|
[FREE_PLAN]: "Free",
|
|
4719
4721
|
["pro"]: "Pro"
|
|
4720
4722
|
};
|
|
4723
|
+
const autoTopUpText = ({ amount_micro_usd: amount, enabled, threshold_micro_usd: threshold }) => enabled && amount !== null && threshold !== null ? `${moneyText(amount)} each time credits fall below ${moneyText(threshold)}` : "Off";
|
|
4724
|
+
const autoTopUpDetails = (autoTopUp) => [{
|
|
4725
|
+
label: "Auto Top-Up",
|
|
4726
|
+
value: autoTopUpText(autoTopUp)
|
|
4727
|
+
}, ...autoTopUp.failure === null ? [] : [{
|
|
4728
|
+
label: "Auto Top-Up Stopped",
|
|
4729
|
+
value: `${timeText(autoTopUp.failed_at)}: ${autoTopUp.failure}`
|
|
4730
|
+
}]];
|
|
4721
4731
|
const billingInspect = async (context) => {
|
|
4722
4732
|
const billing = await callApi({
|
|
4723
4733
|
call: {
|
|
@@ -4739,6 +4749,7 @@ const billingInspect = async (context) => {
|
|
|
4739
4749
|
label: "Credits",
|
|
4740
4750
|
value: moneyText(billing.credit_balance_micro_usd)
|
|
4741
4751
|
},
|
|
4752
|
+
...autoTopUpDetails(billing.auto_top_up),
|
|
4742
4753
|
{
|
|
4743
4754
|
label: "Pro Price",
|
|
4744
4755
|
value: planPriceText(billing.pro_price)
|
|
@@ -4759,6 +4770,17 @@ const billingInspect = async (context) => {
|
|
|
4759
4770
|
],
|
|
4760
4771
|
benefit: "Add credits through Stripe Checkout",
|
|
4761
4772
|
optional: true
|
|
4773
|
+
}, {
|
|
4774
|
+
argv: [
|
|
4775
|
+
"billing",
|
|
4776
|
+
"set-auto-top-up",
|
|
4777
|
+
"--amount",
|
|
4778
|
+
"<USD>",
|
|
4779
|
+
"--threshold",
|
|
4780
|
+
"<USD>"
|
|
4781
|
+
],
|
|
4782
|
+
benefit: "Charge a saved card each time the credit balance runs low",
|
|
4783
|
+
optional: true
|
|
4762
4784
|
}]
|
|
4763
4785
|
};
|
|
4764
4786
|
};
|
|
@@ -4794,6 +4816,72 @@ const billingBuyCredits = async (context) => {
|
|
|
4794
4816
|
}]);
|
|
4795
4817
|
return { document: { checkout } };
|
|
4796
4818
|
};
|
|
4819
|
+
const billingSetAutoTopUp = async (context) => {
|
|
4820
|
+
const request = readInputs({
|
|
4821
|
+
build: (inputs) => {
|
|
4822
|
+
for (const name of AUTO_TOP_UP_FLAGS) if (inputs.text(name) === void 0) inputs.issue({
|
|
4823
|
+
field: `--${name}`,
|
|
4824
|
+
message: `Can't set auto top-up without --${name}, in whole US dollars.`
|
|
4825
|
+
});
|
|
4826
|
+
const amount = inputs.integer("amount", {
|
|
4827
|
+
maximum: CREDIT_PURCHASE_MAX_MICRO_USD / MICRO_USD_PER_DOLLAR,
|
|
4828
|
+
minimum: CREDIT_PURCHASE_MIN_MICRO_USD / MICRO_USD_PER_DOLLAR
|
|
4829
|
+
});
|
|
4830
|
+
const threshold = inputs.integer("threshold", {
|
|
4831
|
+
maximum: AUTO_TOP_UP_THRESHOLD_MAX_MICRO_USD / MICRO_USD_PER_DOLLAR,
|
|
4832
|
+
minimum: AUTO_TOP_UP_THRESHOLD_MIN_MICRO_USD / MICRO_USD_PER_DOLLAR
|
|
4833
|
+
});
|
|
4834
|
+
const rule = {
|
|
4835
|
+
amount_micro_usd: (amount ?? 0) * MICRO_USD_PER_DOLLAR,
|
|
4836
|
+
threshold_micro_usd: (threshold ?? 0) * MICRO_USD_PER_DOLLAR
|
|
4837
|
+
};
|
|
4838
|
+
if (amount !== void 0 && threshold !== void 0 && !thresholdBelowTopUp({
|
|
4839
|
+
amountMicroUsd: rule.amount_micro_usd,
|
|
4840
|
+
thresholdMicroUsd: rule.threshold_micro_usd
|
|
4841
|
+
})) inputs.issue({
|
|
4842
|
+
field: THRESHOLD_FLAG,
|
|
4843
|
+
message: `${THRESHOLD_FLAG} must be below the ${moneyText(creditsAfterFeeMicroUsd(rule.amount_micro_usd))} of credit a ${moneyText(rule.amount_micro_usd)} top-up adds.`
|
|
4844
|
+
});
|
|
4845
|
+
return rule;
|
|
4846
|
+
},
|
|
4847
|
+
context,
|
|
4848
|
+
verb: "set auto top-up"
|
|
4849
|
+
});
|
|
4850
|
+
const change = await callApi({
|
|
4851
|
+
call: {
|
|
4852
|
+
action: "set auto top-up",
|
|
4853
|
+
idempotent: false,
|
|
4854
|
+
key: "required",
|
|
4855
|
+
management: true,
|
|
4856
|
+
run: async (client, signal) => await client.billing.setAutoTopUp(request, { signal }),
|
|
4857
|
+
target: BILLING_TARGET
|
|
4858
|
+
},
|
|
4859
|
+
context
|
|
4860
|
+
});
|
|
4861
|
+
context.io.details([...autoTopUpDetails(change.auto_top_up), ...change.url === null ? [] : [{
|
|
4862
|
+
label: "Save Card",
|
|
4863
|
+
value: change.url
|
|
4864
|
+
}]]);
|
|
4865
|
+
return { document: {
|
|
4866
|
+
auto_top_up: change.auto_top_up,
|
|
4867
|
+
url: change.url
|
|
4868
|
+
} };
|
|
4869
|
+
};
|
|
4870
|
+
const billingStopAutoTopUp = async (context) => {
|
|
4871
|
+
const autoTopUp = await callApi({
|
|
4872
|
+
call: {
|
|
4873
|
+
action: "stop auto top-up",
|
|
4874
|
+
idempotent: true,
|
|
4875
|
+
key: "required",
|
|
4876
|
+
management: true,
|
|
4877
|
+
run: async (client, signal) => await client.billing.stopAutoTopUp({ signal }),
|
|
4878
|
+
target: BILLING_TARGET
|
|
4879
|
+
},
|
|
4880
|
+
context
|
|
4881
|
+
});
|
|
4882
|
+
context.io.details(autoTopUpDetails(autoTopUp));
|
|
4883
|
+
return { document: { auto_top_up: autoTopUp } };
|
|
4884
|
+
};
|
|
4797
4885
|
// ../cli-core/src/consent.ts
|
|
4798
4886
|
const SEVERE_ATTEMPTS = 3;
|
|
4799
4887
|
const typedName = async ({ attempts, io, prompter, request }) => {
|
|
@@ -5360,7 +5448,7 @@ const credentialsDelete = async (context) => {
|
|
|
5360
5448
|
} };
|
|
5361
5449
|
};
|
|
5362
5450
|
// ../sandcovery-runner/src/start-script.gen.ts
|
|
5363
|
-
const START_SCRIPT = "#!/usr/bin/env bash\nset -euo pipefail\n\nreadonly RUNNER_VERSION=2.338.2\nreadonly RUNNER_SHA256_X64=baebf204307bac6193480852732f0aba2ae97b6c5597c244f4d5558390147c40\nreadonly RUNNER_SHA256_ARM64=670adb2f268fe21dcbb58b3db0e0aa9d5b3bddfe2c651481336e561ff86de945\nreadonly RUNNER_DIR=/home/runner/runners/$RUNNER_VERSION\nreadonly RUNNER_LOG=/var/log/sandcovery-runner.log\nreadonly DOCKER_LOG=/var/log/sandcovery-dockerd.log\nreadonly DOCKER_WAIT_SECONDS=60\nreadonly JIT_CONFIG_ENV=ACTIONS_RUNNER_INPUT_JITCONFIG\nreadonly JIT_CONFIG_FILE_NAME=.sandcovery-runner-jitconfig\nreadonly K3S_VERSION=v1.37.2+k3s1\nreadonly K3S_SHA256_X64=265b3ee6a3198ef14033c63ef46cbb32370d83795199fb6d1b01f21575eddbda\nreadonly K3S_SHA256_ARM64=a779ccf1e5e2e33a62f5a29c2f1c0bbf99431e100579d4c10f0aa0742a6aa84b\nreadonly K3S_IMAGES_SHA256_X64=35a5af1e69b57b8b627a4f6b1c29ea104209b661067b8c97fd40dc3f860bfcd2\nreadonly K3S_IMAGES_SHA256_ARM64=ca384f1a77aa83024bd82ad26fa4774971adb038e656a3b5b9af926be445a442\nreadonly K3S_BIN=/usr/local/bin/k3s\nreadonly K3S_DATA=/var/lib/rancher/k3s\nreadonly K3S_LOG=/var/log/sandcovery-k3s.log\nreadonly GATEWAY_LOG=/var/log/sandcovery-k3s-gateway.log\nreadonly KUBERNETES_WAIT_SECONDS=600\n\njit_config_file=${HOME-}/$JIT_CONFIG_FILE_NAME\n\nif [[ -f $jit_config_file ]]; then\n if [[ -n ${!JIT_CONFIG_ENV-} ]]; then\n echo \"start.sh takes the JIT config from $JIT_CONFIG_ENV or $jit_config_file, not both\" >&2\n exit 1\n fi\n\n jit_config=$(<\"$jit_config_file\")\n rm -f \"$jit_config_file\"\n export \"$JIT_CONFIG_ENV=$jit_config\"\nfi\n\nif ((EUID != 0)); then\n exec sudo -n --preserve-env=\"$JIT_CONFIG_ENV\" bash \"$0\" \"$@\"\nfi\n\nexport DEBIAN_FRONTEND=noninteractive\n\napt_install() {\n apt-get update -q\n apt-get install -y -q \"$@\"\n}\n\nensure_base_packages() {\n local missing=()\n\n command -v curl >/dev/null || missing+=(curl)\n command -v sudo >/dev/null || missing+=(sudo)\n [[ -f /etc/ssl/certs/ca-certificates.crt ]] || missing+=(ca-certificates)\n\n if ((${#missing[@]} > 0)); then\n apt_install \"${missing[@]}\"\n fi\n}\n\nchecked() {\n [[ -f $2 ]] && sha256sum --check --strict --status <<<\"$1 $2\"\n}\n\nfetch_checked() {\n local url=$1 sha=$2 file=$3\n\n curl -fsSL --retry 3 -o \"$file\" \"$url\"\n\n if ! checked \"$sha\" \"$file\"; then\n echo \"the SHA-256 of $url is not $sha\" >&2\n rm -f \"$file\"\n exit 1\n fi\n}\n\ninstall_runner() {\n if [[ -x $RUNNER_DIR/run.sh ]]; then\n return\n fi\n\n local arch sha tarball\n\n case $(uname -m) in\n x86_64) arch=x64 sha=$RUNNER_SHA256_X64 ;;\n aarch64) arch=arm64 sha=$RUNNER_SHA256_ARM64 ;;\n *)\n echo \"start.sh has no GitHub Actions runner for $(uname -m)\" >&2\n exit 1\n ;;\n esac\n\n tarball=$(mktemp)\n fetch_checked \"https://github.com/actions/runner/releases/download/v$RUNNER_VERSION/actions-runner-linux-$arch-$RUNNER_VERSION.tar.gz\" \"$sha\" \"$tarball\"\n mkdir -p \"$RUNNER_DIR\"\n tar -xzf \"$tarball\" -C \"$RUNNER_DIR\"\n rm -f \"$tarball\"\n chown -R runner:runner \"$RUNNER_DIR\"\n \"$RUNNER_DIR/bin/installdependencies.sh\"\n}\n\ndocker_running() {\n docker info >/dev/null 2>&1\n}\n\nadd_docker_repository() {\n local id codename\n\n id=$(. /etc/os-release && echo \"$ID\")\n codename=$(. /etc/os-release && echo \"${UBUNTU_CODENAME:-$VERSION_CODENAME}\")\n\n case $id in\n ubuntu | debian) ;;\n *)\n echo \"start.sh installs Docker only on Ubuntu or Debian, not $id\" >&2\n exit 1\n ;;\n esac\n\n install -m 0755 -d /etc/apt/keyrings\n curl -fsSL --retry 3 -o /etc/apt/keyrings/docker.asc \"https://download.docker.com/linux/$id/gpg\"\n chmod a+r /etc/apt/keyrings/docker.asc\n printf '%s\\n' \\\n 'Types: deb' \\\n \"URIs: https://download.docker.com/linux/$id\" \\\n \"Suites: $codename\" \\\n 'Components: stable' \\\n \"Architectures: $(dpkg --print-architecture)\" \\\n 'Signed-By: /etc/apt/keyrings/docker.asc' \\\n >/etc/apt/sources.list.d/docker.sources\n}\n\ninstall_docker() {\n add_docker_repository\n apt_install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin\n}\n\nadd_docker_plugins() {\n local plugins=()\n\n docker compose version >/dev/null 2>&1 || plugins+=(docker-compose-plugin)\n docker buildx version >/dev/null 2>&1 || plugins+=(docker-buildx-plugin)\n\n if ((${#plugins[@]} > 0)); then\n add_docker_repository\n apt_install \"${plugins[@]}\"\n fi\n}\n\nnest_cgroups() {\n local root=/sys/fs/cgroup controllers\n\n if [[ ! -f $root/cgroup.controllers || ! -w $root/cgroup.subtree_control ]]; then\n return\n fi\n\n controllers=$(sed -e 's/ / +/g' -e 's/^/+/' <\"$root/cgroup.controllers\")\n\n if [[ -z ${controllers#+} ]]; then\n return\n fi\n\n if ! echo \"$controllers\" >\"$root/cgroup.subtree_control\" 2>/dev/null; then\n mkdir -p \"$root/init\"\n xargs -rn1 <\"$root/cgroup.procs\" >\"$root/init/cgroup.procs\" || :\n echo \"$controllers\" >\"$root/cgroup.subtree_control\"\n fi\n}\n\nwait_until() {\n local seconds=$1 what=$2 log=$3\n local deadline=$((SECONDS + seconds))\n\n shift 3\n\n until \"$@\"; do\n if ((SECONDS >= deadline)); then\n echo \"$what within $seconds seconds\" >&2\n if [[ -f $log ]]; then\n tail -n 40 \"$log\" >&2\n fi\n exit 1\n fi\n sleep 1\n done\n}\n\nstart_docker() {\n if [[ -d /run/systemd/system ]]; then\n systemctl start docker\n else\n nest_cgroups\n setsid --fork dockerd </dev/null >>\"$DOCKER_LOG\" 2>&1\n fi\n\n wait_until \"$DOCKER_WAIT_SECONDS\" 'dockerd did not answer' \"$DOCKER_LOG\" docker_running\n}\n\nprepare_runner_user() {\n groupadd --force docker\n\n if ! id runner >/dev/null 2>&1; then\n useradd --create-home --shell /bin/bash runner\n fi\n\n usermod --append --groups docker runner\n printf 'runner ALL=(ALL) NOPASSWD:ALL\\n' >/etc/sudoers.d/runner\n chmod 0440 /etc/sudoers.d/runner\n}\n\nstart_runner() {\n cd \"$RUNNER_DIR\"\n setsid --fork sudo -n -u runner -H --preserve-env=\"$JIT_CONFIG_ENV\" \"$RUNNER_DIR/run.sh\" </dev/null >>\"$RUNNER_LOG\" 2>&1\n}\n\nkubectl() {\n \"$K3S_BIN\" kubectl \"$@\"\n}\n\ninstall_k3s() {\n local binary images sha images_sha\n\n case $(uname -m) in\n x86_64) binary=k3s images=amd64 sha=$K3S_SHA256_X64 images_sha=$K3S_IMAGES_SHA256_X64 ;;\n aarch64) binary=k3s-arm64 images=arm64 sha=$K3S_SHA256_ARM64 images_sha=$K3S_IMAGES_SHA256_ARM64 ;;\n *)\n echo \"start.sh has no k3s for $(uname -m)\" >&2\n exit 1\n ;;\n esac\n\n local release=https://github.com/k3s-io/k3s/releases/download/${K3S_VERSION/+/%2B}\n local archive=$K3S_DATA/agent/images/k3s-airgap-images-$images.tar.zst\n\n if ! checked \"$sha\" \"$K3S_BIN\"; then\n fetch_checked \"$release/$binary\" \"$sha\" \"$K3S_BIN.download\"\n chmod 0755 \"$K3S_BIN.download\"\n mv \"$K3S_BIN.download\" \"$K3S_BIN\"\n fi\n\n if ! checked \"$images_sha\" \"$archive\"; then\n mkdir -p \"$(dirname \"$archive\")\"\n fetch_checked \"$release/k3s-airgap-images-$images.tar.zst\" \"$images_sha\" \"$archive\"\n fi\n}\n\nk3s_answers() {\n kubectl get --raw=/readyz >/dev/null 2>&1\n}\n\nstart_k3s() {\n if k3s_answers; then\n return\n fi\n\n local flags=(\n server\n --disable=traefik\n --flannel-backend=host-gw\n --kube-apiserver-arg=anonymous-auth=false\n --node-name=sandcovery\n --write-kubeconfig-mode=600\n )\n\n if [[ $(stat -f -c %T \"$K3S_DATA\") == overlayfs ]]; then\n flags+=(--snapshotter=native)\n fi\n\n if [[ ! -d /run/systemd/system ]]; then\n nest_cgroups\n fi\n\n setsid --fork \"$K3S_BIN\" \"${flags[@]}\" </dev/null >>\"$K3S_LOG\" 2>&1 3>&-\n}\n\ncluster_ready() {\n local node coredns\n\n node=$(kubectl get node sandcovery -o 'jsonpath={.status.conditions[?(@.type==\"Ready\")].status}' 2>/dev/null) &&\n [[ $node == True ]] &&\n kubectl -n default get serviceaccount default >/dev/null 2>&1 &&\n coredns=$(kubectl -n kube-system get deployment coredns -o 'jsonpath={.status.availableReplicas}' 2>/dev/null) &&\n ((${coredns:-0} >= 1))\n}\n\ngrant_admin() {\n kubectl apply -f - >/dev/null <<'YAML'\napiVersion: v1\nkind: ServiceAccount\nmetadata:\n name: sandcovery-admin\n namespace: kube-system\n---\napiVersion: rbac.authorization.k8s.io/v1\nkind: ClusterRoleBinding\nmetadata:\n name: sandcovery-admin\nroleRef:\n apiGroup: rbac.authorization.k8s.io\n kind: ClusterRole\n name: cluster-admin\nsubjects:\n - kind: ServiceAccount\n name: sandcovery-admin\n namespace: kube-system\n---\napiVersion: v1\nkind: Secret\nmetadata:\n name: sandcovery-admin\n namespace: kube-system\n annotations:\n kubernetes.io/service-account.name: sandcovery-admin\ntype: kubernetes.io/service-account-token\nYAML\n}\n\ntoken_issued() {\n token=$(kubectl -n kube-system get secret sandcovery-admin -o 'jsonpath={.data.token}' 2>/dev/null) &&\n [[ -n $token ]]\n}\n\ngateway_answers() {\n curl -s -o /dev/null --max-time 5 \"http://127.0.0.1:$gateway_port/\"\n}\n\ngateway_authorizes() {\n curl -fsS -o /dev/null --max-time 5 -H @- \"http://127.0.0.1:$gateway_port/readyz\" <<<\"Authorization: Bearer $token\"\n}\n\nstart_gateway() {\n command -v socat >/dev/null || apt_install socat\n\n if ! gateway_answers; then\n setsid --fork socat \"TCP-LISTEN:$gateway_port,fork,reuseaddr\" \"OPENSSL:127.0.0.1:6443,cafile=$K3S_DATA/server/tls/server-ca.crt,commonname=localhost\" </dev/null >>\"$GATEWAY_LOG\" 2>&1 3>&-\n fi\n}\n\nstart_kubernetes() {\n install_k3s\n start_k3s\n wait_until \"$KUBERNETES_WAIT_SECONDS\" 'k3s did not answer' \"$K3S_LOG\" k3s_answers\n wait_until \"$KUBERNETES_WAIT_SECONDS\" 'the node, the default service account, and CoreDNS were not ready' \"$K3S_LOG\" cluster_ready\n grant_admin\n wait_until \"$KUBERNETES_WAIT_SECONDS\" 'k3s issued no token for sandcovery-admin' \"$K3S_LOG\" token_issued\n token=$(base64 -d <<<\"$token\")\n start_gateway\n wait_until \"$KUBERNETES_WAIT_SECONDS\" \"the gateway on port $gateway_port did not pass a request with the token to k3s\" \"$GATEWAY_LOG\" gateway_authorizes\n printf '%s\\n' \"$token\" >&3\n}\n\ncase ${1-} in\n docker | install | '') ;;\n kubernetes)\n gateway_port=${2-}\n if [[ ! $gateway_port =~ ^[1-9][0-9]*$ ]] || ((gateway_port > 65535)); then\n echo 'usage: start.sh kubernetes <gateway port>' >&2\n exit 2\n fi\n exec 3>&1 1>&2\n ;;\n *)\n echo 'usage: start.sh [docker | install | kubernetes <gateway port>]' >&2\n exit 2\n ;;\nesac\n\nensure_base_packages\n\nif [[ ${1-} == kubernetes ]]; then\n start_kubernetes\n exit\nfi\n\nif [[ ${1-} != docker ]]; then\n prepare_runner_user\n install_runner\nfi\n\nif [[ ${1-} == install ]]; then\n command -v dockerd >/dev/null || install_docker\n exit\nfi\n\nif ! docker_running; then\n command -v dockerd >/dev/null || install_docker\n start_docker\nfi\n\nadd_docker_plugins\n\nif [[ ${1-} != docker ]]; then\n start_runner\nfi\n";
|
|
5451
|
+
const START_SCRIPT = "#!/usr/bin/env bash\nset -euo pipefail\n\nreadonly RUNNER_VERSION=2.338.2\nreadonly RUNNER_SHA256_X64=baebf204307bac6193480852732f0aba2ae97b6c5597c244f4d5558390147c40\nreadonly RUNNER_SHA256_ARM64=670adb2f268fe21dcbb58b3db0e0aa9d5b3bddfe2c651481336e561ff86de945\nreadonly RUNNER_DIR=/home/runner/runners/$RUNNER_VERSION\nreadonly RUNNER_LOG=/var/log/sandcovery-runner.log\nreadonly DOCKER_LOG=/var/log/sandcovery-dockerd.log\nreadonly DOCKER_WAIT_SECONDS=60\nreadonly JIT_CONFIG_ENV=ACTIONS_RUNNER_INPUT_JITCONFIG\nreadonly JIT_CONFIG_FILE_NAME=.sandcovery-runner-jitconfig\nreadonly K3S_VERSION=v1.37.2+k3s1\nreadonly K3S_SHA256_X64=265b3ee6a3198ef14033c63ef46cbb32370d83795199fb6d1b01f21575eddbda\nreadonly K3S_SHA256_ARM64=a779ccf1e5e2e33a62f5a29c2f1c0bbf99431e100579d4c10f0aa0742a6aa84b\nreadonly K3S_IMAGES_SHA256_X64=35a5af1e69b57b8b627a4f6b1c29ea104209b661067b8c97fd40dc3f860bfcd2\nreadonly K3S_IMAGES_SHA256_ARM64=ca384f1a77aa83024bd82ad26fa4774971adb038e656a3b5b9af926be445a442\nreadonly K3S_BIN=/usr/local/bin/k3s\nreadonly K3S_DATA=/var/lib/rancher/k3s\nreadonly K3S_LOG=/var/log/sandcovery-k3s.log\nreadonly GATEWAY_LOG=/var/log/sandcovery-k3s-gateway.log\nreadonly KUBERNETES_WAIT_SECONDS=600\nreadonly DOCKER_KEY_SHA256=1500c1f56fa9e26b9b8f42452a553675796ade0807cdce11975eb98170b3a570\nreadonly GH_KEYRING_SHA256=6084d5d7bd8e288441e0e94fc6275570895da18e6751f70f057485dc2d1a811b\nreadonly GH_KEYRING=/etc/apt/keyrings/githubcli-archive-keyring.gpg\n\njit_config_file=${HOME-}/$JIT_CONFIG_FILE_NAME\n\nif [[ -f $jit_config_file ]]; then\n if [[ -n ${!JIT_CONFIG_ENV-} ]]; then\n echo \"start.sh takes the JIT config from $JIT_CONFIG_ENV or $jit_config_file, not both\" >&2\n exit 1\n fi\n\n jit_config=$(<\"$jit_config_file\")\n rm -f \"$jit_config_file\"\n export \"$JIT_CONFIG_ENV=$jit_config\"\nfi\n\nif ((EUID != 0)); then\n exec sudo -n --preserve-env=\"$JIT_CONFIG_ENV\" bash \"$0\" \"$@\"\nfi\n\nexport DEBIAN_FRONTEND=noninteractive\n\napt_install() {\n apt-get update -q\n apt-get install -y -q \"$@\"\n}\n\nensure_base_packages() {\n local missing=()\n\n command -v curl >/dev/null || missing+=(curl)\n command -v sudo >/dev/null || missing+=(sudo)\n [[ -f /etc/ssl/certs/ca-certificates.crt ]] || missing+=(ca-certificates)\n\n if ((${#missing[@]} > 0)); then\n apt_install \"${missing[@]}\"\n fi\n}\n\nchecked() {\n [[ -f $2 ]] && sha256sum --check --strict --status <<<\"$1 $2\"\n}\n\nfetch_checked() {\n local url=$1 sha=$2 file=$3\n\n curl -fsSL --retry 3 -o \"$file\" \"$url\"\n\n if ! checked \"$sha\" \"$file\"; then\n echo \"the SHA-256 of $url is not $sha\" >&2\n rm -f \"$file\"\n exit 1\n fi\n}\n\ninstall_runner() {\n if [[ -x $RUNNER_DIR/run.sh ]]; then\n return\n fi\n\n local arch sha tarball\n\n case $(uname -m) in\n x86_64) arch=x64 sha=$RUNNER_SHA256_X64 ;;\n aarch64) arch=arm64 sha=$RUNNER_SHA256_ARM64 ;;\n *)\n echo \"start.sh has no GitHub Actions runner for $(uname -m)\" >&2\n exit 1\n ;;\n esac\n\n tarball=$(mktemp)\n fetch_checked \"https://github.com/actions/runner/releases/download/v$RUNNER_VERSION/actions-runner-linux-$arch-$RUNNER_VERSION.tar.gz\" \"$sha\" \"$tarball\"\n mkdir -p \"$RUNNER_DIR\"\n tar -xzf \"$tarball\" -C \"$RUNNER_DIR\"\n rm -f \"$tarball\"\n chown -R runner:runner \"$RUNNER_DIR\"\n \"$RUNNER_DIR/bin/installdependencies.sh\"\n}\n\ndocker_running() {\n docker info >/dev/null 2>&1\n}\n\nadd_docker_repository() {\n local id codename\n\n id=$(. /etc/os-release && echo \"$ID\")\n codename=$(. /etc/os-release && echo \"${UBUNTU_CODENAME:-$VERSION_CODENAME}\")\n\n case $id in\n ubuntu | debian) ;;\n *)\n echo \"start.sh installs Docker only on Ubuntu or Debian, not $id\" >&2\n exit 1\n ;;\n esac\n\n install -m 0755 -d /etc/apt/keyrings\n fetch_checked \"https://download.docker.com/linux/$id/gpg\" \"$DOCKER_KEY_SHA256\" /etc/apt/keyrings/docker.asc\n chmod a+r /etc/apt/keyrings/docker.asc\n printf '%s\\n' \\\n 'Types: deb' \\\n \"URIs: https://download.docker.com/linux/$id\" \\\n \"Suites: $codename\" \\\n 'Components: stable' \\\n \"Architectures: $(dpkg --print-architecture)\" \\\n 'Signed-By: /etc/apt/keyrings/docker.asc' \\\n >/etc/apt/sources.list.d/docker.sources\n}\n\ninstall_docker() {\n add_docker_repository\n apt_install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin\n}\n\ninstall_gh() {\n install -m 0755 -d /etc/apt/keyrings\n fetch_checked https://cli.github.com/packages/githubcli-archive-keyring.gpg \"$GH_KEYRING_SHA256\" \"$GH_KEYRING\"\n chmod a+r \"$GH_KEYRING\"\n printf 'deb [arch=%s signed-by=%s] https://cli.github.com/packages stable main\\n' \"$(dpkg --print-architecture)\" \"$GH_KEYRING\" >/etc/apt/sources.list.d/github-cli.list\n apt_install gh\n}\n\nadd_docker_plugins() {\n local plugins=()\n\n docker compose version >/dev/null 2>&1 || plugins+=(docker-compose-plugin)\n docker buildx version >/dev/null 2>&1 || plugins+=(docker-buildx-plugin)\n\n if ((${#plugins[@]} > 0)); then\n add_docker_repository\n apt_install \"${plugins[@]}\"\n fi\n}\n\nnest_cgroups() {\n local root=/sys/fs/cgroup controllers\n\n if [[ ! -f $root/cgroup.controllers || ! -w $root/cgroup.subtree_control ]]; then\n return\n fi\n\n controllers=$(sed -e 's/ / +/g' -e 's/^/+/' <\"$root/cgroup.controllers\")\n\n if [[ -z ${controllers#+} ]]; then\n return\n fi\n\n if ! echo \"$controllers\" >\"$root/cgroup.subtree_control\" 2>/dev/null; then\n mkdir -p \"$root/init\"\n xargs -rn1 <\"$root/cgroup.procs\" >\"$root/init/cgroup.procs\" || :\n echo \"$controllers\" >\"$root/cgroup.subtree_control\"\n fi\n}\n\nwait_until() {\n local seconds=$1 what=$2 log=$3\n local deadline=$((SECONDS + seconds))\n\n shift 3\n\n until \"$@\"; do\n if ((SECONDS >= deadline)); then\n echo \"$what within $seconds seconds\" >&2\n if [[ -f $log ]]; then\n tail -n 40 \"$log\" >&2\n fi\n exit 1\n fi\n sleep 1\n done\n}\n\nstart_docker() {\n if [[ -d /run/systemd/system ]]; then\n systemctl start docker\n else\n nest_cgroups\n setsid --fork dockerd </dev/null >>\"$DOCKER_LOG\" 2>&1\n fi\n\n wait_until \"$DOCKER_WAIT_SECONDS\" 'dockerd did not answer' \"$DOCKER_LOG\" docker_running\n}\n\nprepare_runner_user() {\n groupadd --force docker\n\n if ! id runner >/dev/null 2>&1; then\n useradd --create-home --shell /bin/bash runner\n fi\n\n usermod --append --groups docker runner\n printf 'runner ALL=(ALL) NOPASSWD:ALL\\n' >/etc/sudoers.d/runner\n chmod 0440 /etc/sudoers.d/runner\n}\n\nstart_runner() {\n cd \"$RUNNER_DIR\"\n setsid --fork sudo -n -u runner -H --preserve-env=\"$JIT_CONFIG_ENV\" \"$RUNNER_DIR/run.sh\" </dev/null >>\"$RUNNER_LOG\" 2>&1\n}\n\nkubectl() {\n \"$K3S_BIN\" kubectl \"$@\"\n}\n\ninstall_k3s() {\n local binary images sha images_sha\n\n case $(uname -m) in\n x86_64) binary=k3s images=amd64 sha=$K3S_SHA256_X64 images_sha=$K3S_IMAGES_SHA256_X64 ;;\n aarch64) binary=k3s-arm64 images=arm64 sha=$K3S_SHA256_ARM64 images_sha=$K3S_IMAGES_SHA256_ARM64 ;;\n *)\n echo \"start.sh has no k3s for $(uname -m)\" >&2\n exit 1\n ;;\n esac\n\n local release=https://github.com/k3s-io/k3s/releases/download/${K3S_VERSION/+/%2B}\n local archive=$K3S_DATA/agent/images/k3s-airgap-images-$images.tar.zst\n\n if ! checked \"$sha\" \"$K3S_BIN\"; then\n fetch_checked \"$release/$binary\" \"$sha\" \"$K3S_BIN.download\"\n chmod 0755 \"$K3S_BIN.download\"\n mv \"$K3S_BIN.download\" \"$K3S_BIN\"\n fi\n\n if ! checked \"$images_sha\" \"$archive\"; then\n mkdir -p \"$(dirname \"$archive\")\"\n fetch_checked \"$release/k3s-airgap-images-$images.tar.zst\" \"$images_sha\" \"$archive\"\n fi\n}\n\nk3s_answers() {\n kubectl get --raw=/readyz >/dev/null 2>&1\n}\n\nstart_k3s() {\n if k3s_answers; then\n return\n fi\n\n local flags=(\n server\n --disable=traefik\n --flannel-backend=host-gw\n --kube-apiserver-arg=anonymous-auth=false\n --node-name=sandcovery\n --write-kubeconfig-mode=600\n )\n\n if [[ $(stat -f -c %T \"$K3S_DATA\") == overlayfs ]]; then\n flags+=(--snapshotter=native)\n fi\n\n if [[ ! -d /run/systemd/system ]]; then\n nest_cgroups\n fi\n\n setsid --fork \"$K3S_BIN\" \"${flags[@]}\" </dev/null >>\"$K3S_LOG\" 2>&1 3>&-\n}\n\ncluster_ready() {\n local node coredns\n\n node=$(kubectl get node sandcovery -o 'jsonpath={.status.conditions[?(@.type==\"Ready\")].status}' 2>/dev/null) &&\n [[ $node == True ]] &&\n kubectl -n default get serviceaccount default >/dev/null 2>&1 &&\n coredns=$(kubectl -n kube-system get deployment coredns -o 'jsonpath={.status.availableReplicas}' 2>/dev/null) &&\n ((${coredns:-0} >= 1))\n}\n\ngrant_admin() {\n kubectl apply -f - >/dev/null <<'YAML'\napiVersion: v1\nkind: ServiceAccount\nmetadata:\n name: sandcovery-admin\n namespace: kube-system\n---\napiVersion: rbac.authorization.k8s.io/v1\nkind: ClusterRoleBinding\nmetadata:\n name: sandcovery-admin\nroleRef:\n apiGroup: rbac.authorization.k8s.io\n kind: ClusterRole\n name: cluster-admin\nsubjects:\n - kind: ServiceAccount\n name: sandcovery-admin\n namespace: kube-system\n---\napiVersion: v1\nkind: Secret\nmetadata:\n name: sandcovery-admin\n namespace: kube-system\n annotations:\n kubernetes.io/service-account.name: sandcovery-admin\ntype: kubernetes.io/service-account-token\nYAML\n}\n\ntoken_issued() {\n token=$(kubectl -n kube-system get secret sandcovery-admin -o 'jsonpath={.data.token}' 2>/dev/null) &&\n [[ -n $token ]]\n}\n\ngateway_answers() {\n curl -s -o /dev/null --max-time 5 \"http://127.0.0.1:$gateway_port/\"\n}\n\ngateway_authorizes() {\n curl -fsS -o /dev/null --max-time 5 -H @- \"http://127.0.0.1:$gateway_port/readyz\" <<<\"Authorization: Bearer $token\"\n}\n\nstart_gateway() {\n command -v socat >/dev/null || apt_install socat\n\n if ! gateway_answers; then\n setsid --fork socat \"TCP-LISTEN:$gateway_port,fork,reuseaddr\" \"OPENSSL:127.0.0.1:6443,cafile=$K3S_DATA/server/tls/server-ca.crt,commonname=localhost\" </dev/null >>\"$GATEWAY_LOG\" 2>&1 3>&-\n fi\n}\n\nstart_kubernetes() {\n install_k3s\n start_k3s\n wait_until \"$KUBERNETES_WAIT_SECONDS\" 'k3s did not answer' \"$K3S_LOG\" k3s_answers\n wait_until \"$KUBERNETES_WAIT_SECONDS\" 'the node, the default service account, and CoreDNS were not ready' \"$K3S_LOG\" cluster_ready\n grant_admin\n wait_until \"$KUBERNETES_WAIT_SECONDS\" 'k3s issued no token for sandcovery-admin' \"$K3S_LOG\" token_issued\n token=$(base64 -d <<<\"$token\")\n start_gateway\n wait_until \"$KUBERNETES_WAIT_SECONDS\" \"the gateway on port $gateway_port did not pass a request with the token to k3s\" \"$GATEWAY_LOG\" gateway_authorizes\n printf '%s\\n' \"$token\" >&3\n}\n\ncase ${1-} in\n docker | install | '') ;;\n kubernetes)\n gateway_port=${2-}\n if [[ ! $gateway_port =~ ^[1-9][0-9]*$ ]] || ((gateway_port > 65535)); then\n echo 'usage: start.sh kubernetes <gateway port>' >&2\n exit 2\n fi\n exec 3>&1 1>&2\n ;;\n *)\n echo 'usage: start.sh [docker | install | kubernetes <gateway port>]' >&2\n exit 2\n ;;\nesac\n\nensure_base_packages\n\nif [[ ${1-} == kubernetes ]]; then\n start_kubernetes\n exit\nfi\n\nif [[ ${1-} != docker ]]; then\n prepare_runner_user\n install_runner\nfi\n\nif [[ ${1-} == install ]]; then\n command -v dockerd >/dev/null || install_docker\n command -v gh >/dev/null || install_gh\n exit\nfi\n\nif ! docker_running; then\n command -v dockerd >/dev/null || install_docker\n start_docker\nfi\n\nadd_docker_plugins\n\nif [[ ${1-} != docker ]]; then\n start_runner\nfi\n";
|
|
5364
5452
|
// ../sandcovery-runner/src/start.ts
|
|
5365
5453
|
const ESCAPED_QUOTE$1 = String.raw`'\''`;
|
|
5366
5454
|
const WRITE_SCRIPT = `script="$(mktemp)" && printf %s '${START_SCRIPT.replaceAll("'", () => ESCAPED_QUOTE$1)}' >"$script"`;
|
|
@@ -18026,12 +18114,12 @@ const priceText = (price) => {
|
|
|
18026
18114
|
if (price === void 0 || price.offered === false) return "-";
|
|
18027
18115
|
return price.hourly_micro_usd === null ? COMING_SOON : `${rateText(price.hourly_micro_usd)}/h`;
|
|
18028
18116
|
};
|
|
18029
|
-
const listedRow = ({ entry,
|
|
18117
|
+
const listedRow = ({ entry, status, statusUrl }) => [
|
|
18030
18118
|
entry.provider,
|
|
18031
18119
|
status,
|
|
18032
18120
|
priceText(entry.prices.find((candidate) => candidate.size === LISTED_SIZE)),
|
|
18033
|
-
|
|
18034
|
-
|
|
18121
|
+
latencyText(entry.create_latency_ms.p50),
|
|
18122
|
+
shareText(entry.uptime.last_24_hours),
|
|
18035
18123
|
incidentsText(entry.incidents, statusUrl)
|
|
18036
18124
|
];
|
|
18037
18125
|
const listProviders = ({ context, rows }) => {
|
|
@@ -18052,13 +18140,11 @@ const listProviders = ({ context, rows }) => {
|
|
|
18052
18140
|
};
|
|
18053
18141
|
const routedRow = (entry) => listedRow({
|
|
18054
18142
|
entry,
|
|
18055
|
-
shared: entry.health_published,
|
|
18056
18143
|
status: statusText(entry.status),
|
|
18057
18144
|
statusUrl: entry.status_url
|
|
18058
18145
|
});
|
|
18059
18146
|
const catalogRow = (entry) => listedRow({
|
|
18060
18147
|
entry,
|
|
18061
|
-
shared: entry.measurement !== "not_published",
|
|
18062
18148
|
status: entry.routed ? statusText(entry.status) : COMING_SOON,
|
|
18063
18149
|
statusUrl: entry.links.status_url
|
|
18064
18150
|
});
|
|
@@ -19317,6 +19403,8 @@ const HANDLERS = /* @__PURE__ */ new Map([
|
|
|
19317
19403
|
["activity list", activityList],
|
|
19318
19404
|
["billing buy-credits", billingBuyCredits],
|
|
19319
19405
|
["billing inspect", billingInspect],
|
|
19406
|
+
["billing set-auto-top-up", billingSetAutoTopUp],
|
|
19407
|
+
["billing stop-auto-top-up", billingStopAutoTopUp],
|
|
19320
19408
|
["ci installations list", ciInstallationsList],
|
|
19321
19409
|
["ci installations unlink", ciInstallationsUnlink],
|
|
19322
19410
|
["ci jobs inspect", ciJobsInspect],
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { $ as FileList, $t as SandboxList, An as XPostRequest, B as DetachedExec, C as CiJob, Ct as Pricing, Dt as Process, Et as ProblemReportRequest, I as CredentialFields, It as ProviderCredential, J as ExecEvent, K as EstimateList, L as CreditCheckout, Lt as ProviderCredentialList, M as CreateSandboxRequest, Mt as ProviderBoard, N as CreateUsageShareRequest, Nt as ProviderBoardEntry, On as XAccountLink, Ot as ProcessRequest, P as CreatedKey, Pt as ProviderCatalog, R as CreditPurchaseRequest, S as CiInstallationList, Sn as UsageShareList, St as PortPreview, T as CiJobList, V as DetachedExecRequest, X as ExecResult, Xt as Sandbox, Y as ExecRequest, Z as FileEntry, _n as Usage, bn as UsageShare, c as AutoTopUpRequest, dn as Stats, en as SandboxStatus, gn as UpdateKeyRequest, ht as MonthlyCostList, i as ActivityList, j as CreateKeyRequest, jt as Provider, kn as XAccountStatus, o as AutoTopUp, on as Snapshot, pt as LiveUsage, q as EstimateRequest, rn as SharedUsage, s as AutoTopUpChange, st as Key, u as Billing, ut as KeyList, vt as Offer, wn as UsageTotals } from "./types-C7lGEXT5.mjs";
|
|
2
2
|
interface ProcessExit {
|
|
3
3
|
readonly code: number;
|
|
4
4
|
readonly signal: string | null;
|
|
@@ -82,6 +82,8 @@ interface ActivityApi {
|
|
|
82
82
|
interface BillingApi {
|
|
83
83
|
readonly buyCredits: (request: CreditPurchaseRequest, options?: RequestOptions) => Promise<CreditCheckout>;
|
|
84
84
|
readonly get: (options?: RequestOptions) => Promise<Billing>;
|
|
85
|
+
readonly setAutoTopUp: (request: AutoTopUpRequest, options?: RequestOptions) => Promise<AutoTopUpChange>;
|
|
86
|
+
readonly stopAutoTopUp: (options?: RequestOptions) => Promise<AutoTopUp>;
|
|
85
87
|
}
|
|
86
88
|
interface CiApi {
|
|
87
89
|
readonly getJob: (jobId: string, options?: RequestOptions) => Promise<CiJob>;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as Sandcovery } from "./src-
|
|
1
|
+
export { t as Sandcovery } from "./src-lrpT0LG_.mjs";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Bn as TaggedError, Br as isString, Ct as fail, E as decodeUnknownSync, En as ClockRef, Hn as seconds, Ir as hasProperty, Jn as isSuccess, O as fromJsonString, Qt as tapError, Tt as flatMap, Un as toMillis, Ut as retry, Vn as millis, Xt as sync, Yn as try_, Yt as suspend, _ as String$1, an as void_, ar as getOrThrowWith, cr as isSome, g as Record, gt as catchDefect, h as Number$1, kn as currentTimeMillis$1, ln as spaced, lt as acquireUseRelease, m as NullOr, n as Boolean, rr as getOrElse, sr as isNone, t as ArraySchema, u as Literals, un as upTo, ur as map, v as Struct, vt as catchTag, w as decodeUnknownOption, xt as die } from "./Schema-CoX0a2_o.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { A as NO_MARKUP_TERMS, B as DEFAULT_SLUG, C as AUTO_TOP_UP_THRESHOLD_MIN_MICRO_USD, E as CREDIT_PURCHASE_MIN_MICRO_USD, F as Unauthorized, H as Forbidden, I as NotFound, P as Unsupported, S as AUTO_TOP_UP_THRESHOLD_MAX_MICRO_USD, T as CREDIT_PURCHASE_MAX_MICRO_USD, U as Conflict, V as ProviderSort, _ as KeyKind, h as SANDCOVERY_X_HANDLE, k as MICRO_USD_PER_DOLLAR, l as MONTH_TEXT, t as Sandcovery, v as SpendLimit, w as CARD_FEE_TERMS, z as SandboxStatus } from "./src-lrpT0LG_.mjs";
|
|
3
3
|
import { WebSocket } from "node:http";
|
|
4
4
|
import net from "node:net";
|
|
5
5
|
import readline from "node:readline";
|
|
@@ -1123,7 +1123,7 @@ const withFileLock = ({ bin, file, work }) => {
|
|
|
1123
1123
|
}), () => work, (own) => removeIf(lock, sameAs(own)));
|
|
1124
1124
|
};
|
|
1125
1125
|
// package.json
|
|
1126
|
-
var version = "0.
|
|
1126
|
+
var version = "0.6.0";
|
|
1127
1127
|
// ../format/src/display.ts
|
|
1128
1128
|
const LOCALE = "en-US";
|
|
1129
1129
|
const UTC = "UTC";
|
|
@@ -1155,6 +1155,11 @@ new Intl.DateTimeFormat(LOCALE, {
|
|
|
1155
1155
|
month: "short",
|
|
1156
1156
|
timeZone: UTC
|
|
1157
1157
|
});
|
|
1158
|
+
new Intl.DateTimeFormat(LOCALE, {
|
|
1159
|
+
day: "numeric",
|
|
1160
|
+
month: "long",
|
|
1161
|
+
timeZone: UTC
|
|
1162
|
+
});
|
|
1158
1163
|
const monthName = new Intl.DateTimeFormat(LOCALE, {
|
|
1159
1164
|
month: "long",
|
|
1160
1165
|
timeZone: UTC
|
|
@@ -1231,6 +1236,11 @@ const percentFormats = {
|
|
|
1231
1236
|
minimumFractionDigits: 2,
|
|
1232
1237
|
style: "percent"
|
|
1233
1238
|
}),
|
|
1239
|
+
share: new Intl.NumberFormat(LOCALE, {
|
|
1240
|
+
maximumFractionDigits: 1,
|
|
1241
|
+
minimumFractionDigits: 1,
|
|
1242
|
+
style: "percent"
|
|
1243
|
+
}),
|
|
1234
1244
|
whole: new Intl.NumberFormat(LOCALE, {
|
|
1235
1245
|
maximumFractionDigits: 0,
|
|
1236
1246
|
style: "percent"
|
|
@@ -2710,7 +2720,7 @@ const providers = {
|
|
|
2710
2720
|
notes: [
|
|
2711
2721
|
"Lists each provider with its status, 2x4 price per hour, and median create latency.",
|
|
2712
2722
|
"A provider Sandcovery does not route to yet shows as Coming Soon.",
|
|
2713
|
-
"Coming Soon also marks each figure
|
|
2723
|
+
"Coming Soon also marks each figure no probe has measured and each fact Sandcovery has not read, and --json adds every fact with the page it was read from.",
|
|
2714
2724
|
"With --routed, it lists only the providers on the provider board, and --json prints their board entries."
|
|
2715
2725
|
],
|
|
2716
2726
|
options: [
|
|
@@ -3203,78 +3213,173 @@ const activity = {
|
|
|
3203
3213
|
summary: "Read what happened to your sandboxes"
|
|
3204
3214
|
};
|
|
3205
3215
|
const billing = {
|
|
3206
|
-
children: [
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
argv: [
|
|
3247
|
-
"billing",
|
|
3248
|
-
"buy-credits",
|
|
3249
|
-
"--amount",
|
|
3250
|
-
"100"
|
|
3216
|
+
children: [
|
|
3217
|
+
{
|
|
3218
|
+
arguments: [],
|
|
3219
|
+
examples: [{
|
|
3220
|
+
argv: ["billing", "inspect"],
|
|
3221
|
+
summary: "Show the plan and the credit balance"
|
|
3222
|
+
}],
|
|
3223
|
+
kind: "leaf",
|
|
3224
|
+
name: "inspect",
|
|
3225
|
+
notes: [`Shows the plan, the credit balance, the Pro and Enterprise prices, and auto top-up with the reason a failed charge turned it off. It fails as not found while billing is not set up. ${NEEDS_MANAGEMENT}`],
|
|
3226
|
+
options: [baseUrl, json],
|
|
3227
|
+
result: [
|
|
3228
|
+
{
|
|
3229
|
+
name: "billing.auto_top_up",
|
|
3230
|
+
type: "object"
|
|
3231
|
+
},
|
|
3232
|
+
{
|
|
3233
|
+
name: "billing.plan",
|
|
3234
|
+
type: "\"free\" | \"pro\" | \"enterprise\""
|
|
3235
|
+
},
|
|
3236
|
+
{
|
|
3237
|
+
name: "billing.credit_balance_micro_usd",
|
|
3238
|
+
type: "number"
|
|
3239
|
+
},
|
|
3240
|
+
{
|
|
3241
|
+
name: "billing.credits_on_sale",
|
|
3242
|
+
type: "boolean"
|
|
3243
|
+
},
|
|
3244
|
+
{
|
|
3245
|
+
name: "billing.pro_price",
|
|
3246
|
+
type: NULLABLE_OBJECT
|
|
3247
|
+
},
|
|
3248
|
+
{
|
|
3249
|
+
name: "billing.enterprise_price",
|
|
3250
|
+
type: NULLABLE_OBJECT
|
|
3251
|
+
},
|
|
3252
|
+
{
|
|
3253
|
+
name: "billing.github_enterprise",
|
|
3254
|
+
type: "boolean"
|
|
3255
|
+
}
|
|
3251
3256
|
],
|
|
3252
|
-
summary: "
|
|
3253
|
-
}
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
summary:
|
|
3264
|
-
},
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3257
|
+
summary: "Show the plan and credits"
|
|
3258
|
+
},
|
|
3259
|
+
{
|
|
3260
|
+
arguments: [],
|
|
3261
|
+
examples: [{
|
|
3262
|
+
argv: [
|
|
3263
|
+
"billing",
|
|
3264
|
+
"buy-credits",
|
|
3265
|
+
"--amount",
|
|
3266
|
+
"100"
|
|
3267
|
+
],
|
|
3268
|
+
summary: "Start a 100 USD credit purchase"
|
|
3269
|
+
}],
|
|
3270
|
+
kind: "leaf",
|
|
3271
|
+
name: "buy-credits",
|
|
3272
|
+
notes: [`Prints the Stripe Checkout page that takes the payment. The credits are the amount less the processing fee of ${CARD_FEE_TERMS}, and arrive once Stripe confirms the payment. ${NEEDS_MANAGEMENT}`],
|
|
3273
|
+
options: [
|
|
3274
|
+
{
|
|
3275
|
+
hint: "<USD>",
|
|
3276
|
+
kind: "value",
|
|
3277
|
+
name: "amount",
|
|
3278
|
+
required: true,
|
|
3279
|
+
summary: `Whole US dollars to pay, from ${String(CREDIT_PURCHASE_MIN_MICRO_USD / MICRO_USD_PER_DOLLAR)} to ${String(CREDIT_PURCHASE_MAX_MICRO_USD / MICRO_USD_PER_DOLLAR)}`
|
|
3280
|
+
},
|
|
3281
|
+
baseUrl,
|
|
3282
|
+
json
|
|
3283
|
+
],
|
|
3284
|
+
result: [{
|
|
3285
|
+
name: "checkout.url",
|
|
3286
|
+
type: "string"
|
|
3287
|
+
}],
|
|
3288
|
+
summary: "Buy credits through Stripe Checkout"
|
|
3289
|
+
},
|
|
3290
|
+
{
|
|
3291
|
+
arguments: [],
|
|
3292
|
+
examples: [{
|
|
3293
|
+
argv: [
|
|
3294
|
+
"billing",
|
|
3295
|
+
"set-auto-top-up",
|
|
3296
|
+
"--amount",
|
|
3297
|
+
"25",
|
|
3298
|
+
"--threshold",
|
|
3299
|
+
"10"
|
|
3300
|
+
],
|
|
3301
|
+
summary: "Charge 25 USD each time the credit balance falls below 10 USD"
|
|
3302
|
+
}],
|
|
3303
|
+
kind: "leaf",
|
|
3304
|
+
name: "set-auto-top-up",
|
|
3305
|
+
notes: [`While auto top-up is off, prints the Stripe Checkout page that saves a card and then turns auto top-up on with this threshold and amount, starting a fresh run of charges. While it is on, the threshold and amount apply at once. Each time the credit balance falls below the threshold, or a create is refused for credits one top-up covers, the saved card is charged the amount once, and the credit, the amount less the processing fee of ${CARD_FEE_TERMS}, arrives once Stripe confirms the charge. A declined card, a card that asks its holder to authenticate, or any other failed charge turns auto top-up off, and \`billing inspect\` shows why. ${NEEDS_MANAGEMENT}`],
|
|
3306
|
+
options: [
|
|
3307
|
+
{
|
|
3308
|
+
hint: "<USD>",
|
|
3309
|
+
kind: "value",
|
|
3310
|
+
name: "amount",
|
|
3311
|
+
required: true,
|
|
3312
|
+
summary: `Whole US dollars each top-up charges, from ${String(CREDIT_PURCHASE_MIN_MICRO_USD / MICRO_USD_PER_DOLLAR)} to ${String(CREDIT_PURCHASE_MAX_MICRO_USD / MICRO_USD_PER_DOLLAR)}`
|
|
3313
|
+
},
|
|
3314
|
+
{
|
|
3315
|
+
hint: "<USD>",
|
|
3316
|
+
kind: "value",
|
|
3317
|
+
name: "threshold",
|
|
3318
|
+
required: true,
|
|
3319
|
+
summary: `Whole US dollars of credit balance below which a top-up is charged, from ${String(AUTO_TOP_UP_THRESHOLD_MIN_MICRO_USD / MICRO_USD_PER_DOLLAR)} to ${String(AUTO_TOP_UP_THRESHOLD_MAX_MICRO_USD / MICRO_USD_PER_DOLLAR)}, and below the credit one top-up adds`
|
|
3320
|
+
},
|
|
3321
|
+
baseUrl,
|
|
3322
|
+
json
|
|
3323
|
+
],
|
|
3324
|
+
result: [
|
|
3325
|
+
{
|
|
3326
|
+
name: "auto_top_up.enabled",
|
|
3327
|
+
type: "boolean"
|
|
3328
|
+
},
|
|
3329
|
+
{
|
|
3330
|
+
name: "auto_top_up.amount_micro_usd",
|
|
3331
|
+
type: NULLABLE_NUMBER
|
|
3332
|
+
},
|
|
3333
|
+
{
|
|
3334
|
+
name: "auto_top_up.threshold_micro_usd",
|
|
3335
|
+
type: NULLABLE_NUMBER
|
|
3336
|
+
},
|
|
3337
|
+
{
|
|
3338
|
+
name: "auto_top_up.failure",
|
|
3339
|
+
type: NULLABLE_TEXT
|
|
3340
|
+
},
|
|
3341
|
+
{
|
|
3342
|
+
name: "auto_top_up.failed_at",
|
|
3343
|
+
type: NULLABLE_TEXT
|
|
3344
|
+
},
|
|
3345
|
+
{
|
|
3346
|
+
name: "url",
|
|
3347
|
+
type: NULLABLE_TEXT
|
|
3348
|
+
}
|
|
3349
|
+
],
|
|
3350
|
+
summary: "Set the auto top-up threshold and amount"
|
|
3351
|
+
},
|
|
3352
|
+
{
|
|
3353
|
+
arguments: [],
|
|
3354
|
+
examples: [{
|
|
3355
|
+
argv: ["billing", "stop-auto-top-up"],
|
|
3356
|
+
summary: "Stop charging the saved card"
|
|
3357
|
+
}],
|
|
3358
|
+
kind: "leaf",
|
|
3359
|
+
name: "stop-auto-top-up",
|
|
3360
|
+
notes: [`Turns auto top-up off, so the saved card is charged no more. A charge Stripe is still processing adds its credit once it succeeds. ${NEEDS_MANAGEMENT}`],
|
|
3361
|
+
options: [baseUrl, json],
|
|
3362
|
+
result: [
|
|
3363
|
+
{
|
|
3364
|
+
name: "auto_top_up.enabled",
|
|
3365
|
+
type: "boolean"
|
|
3366
|
+
},
|
|
3367
|
+
{
|
|
3368
|
+
name: "auto_top_up.amount_micro_usd",
|
|
3369
|
+
type: NULLABLE_NUMBER
|
|
3370
|
+
},
|
|
3371
|
+
{
|
|
3372
|
+
name: "auto_top_up.threshold_micro_usd",
|
|
3373
|
+
type: NULLABLE_NUMBER
|
|
3374
|
+
}
|
|
3375
|
+
],
|
|
3376
|
+
summary: "Turn auto top-up off"
|
|
3377
|
+
}
|
|
3378
|
+
],
|
|
3274
3379
|
defaultChild: "inspect",
|
|
3275
3380
|
kind: "group",
|
|
3276
3381
|
name: "billing",
|
|
3277
|
-
summary: "Show the plan and
|
|
3382
|
+
summary: "Show the plan, buy credits, and set auto top-up"
|
|
3278
3383
|
};
|
|
3279
3384
|
const pricing = {
|
|
3280
3385
|
children: [{
|