Skip to content

vast-ai/vast-cli / vastai

vastai

Flagged

Vast.ai CLI to manage GPU instances, volumes, serverless endpoints, and billing.

FileKindSize
SKILL.mdskill md18.6 KB
__init__.pyscript1.8 KB
_base.pyscript1.6 KB
api/__init__.pyscript31 B
api/auth.pyscript15.3 KB
api/billing.pyscript10.4 KB
api/client.pyscript9.1 KB
api/clusters.pyscript4.5 KB
api/deployments.pyscript1.4 KB
api/endpoints.pyscript12.0 KB
api/instances.pyscript17.1 KB
api/keys.pyscript4.3 KB
api/machines.pyscript7.4 KB
api/metrics.pyscript2.6 KB
api/offers.pyscript21.2 KB
api/price_increase.pyscript4.0 KB
api/query.pyscript12.2 KB
api/storage.pyscript14.5 KB
api/teams.pyscript4.4 KB
async_/__init__.pyscript79 B
async_/client.pyscript9.6 KB
async_/results.pyscript1.3 KB
cli/__init__.pyscript25 B
cli/commands/__init__.pyscript757 B
cli/commands/auth.pyscript42.8 KB
cli/commands/benchmarks.pyscript42.0 KB
cli/commands/billing.pyscript30.4 KB
cli/commands/clusters.pyscript7.8 KB
cli/commands/deployments.pyscript7.8 KB
cli/commands/endpoints.pyscript17.3 KB
cli/commands/instances.pyscript55.4 KB
cli/commands/keys.pyscript7.9 KB
cli/commands/machines.pyscript78.4 KB
cli/commands/metrics.pyscript12.7 KB
cli/commands/misc.pyscript11.0 KB
cli/commands/offers.pyscript30.0 KB
cli/commands/price_increase.pyscript14.5 KB
cli/commands/repl.pyscript719 B
cli/commands/storage.pyscript38.9 KB
cli/commands/teams.pyscript6.4 KB
cli/commands/uninstall.pyscript2.4 KB
cli/commands/update.pyscript3.1 KB
cli/display.pyscript20.1 KB
cli/main.pyscript11.5 KB
cli/parser.pyscript18.1 KB
cli/repl/__init__.pyscript318 B
cli/repl/bridge.pyscript7.3 KB
cli/repl/catalog.pyscript6.3 KB
cli/repl/completion.pyscript8.2 KB
cli/repl/session.pyscript7.3 KB
cli/self_test/__init__.pyscript46 B
cli/self_test/machine_diagnostics.pyscript21.0 KB
cli/self_test/runtime_diagnostics.pyscript18.6 KB
cli/self_test/support_bundle.pyscript11.0 KB
cli/selfupdate.pyscript14.0 KB
cli/util.pyscript26.3 KB
cli/utils.pyscript577 B
data/__init__.pyscript303 B
data/deployment.pyscript3.5 KB
data/endpoint.pyscript2.1 KB
data/instance.pyscript3.6 KB
data/offer.pyscript4.4 KB
data/query.pyscript12.8 KB
data/workergroup.pyscript1.4 KB
pdf/__init__.pyscript0 B
pdf/vast.ai-logo-50pct.pngbinary7.4 KB
pdf/vast.ai-logo.pngbinary10.1 KB
pdf/vast_pdf.pyscript19.4 KB
pdf/watcher.shexecutablescript390 B
sdk.pyscript52.2 KB
serverless/__init__.pyscript193 B
serverless/client/__init__.pyscript346 B
serverless/client/client.pyscript36.7 KB
serverless/client/connection.pyscript11.5 KB
serverless/client/endpoint.pyscript6.9 KB
serverless/client/managed.pyscript7.3 KB
serverless/client/request_status.pyscript371 B
serverless/client/session.pyscript2.8 KB
serverless/client/worker.pyscript1.3 KB
serverless/remote/__init__.pyscript245 B
serverless/remote/base.pyscript6.3 KB
serverless/remote/deploy.pyscript12.6 KB
serverless/remote/serialization.pyscript3.7 KB
serverless/remote/serve.pyscript8.6 KB
serverless/remote/serve_deployment.pyscript6.3 KB
serverless/remote/utils.pyscript9.7 KB
serverless/server/__init__.pyscript0 B
serverless/server/lib/__init__.pyscript0 B
serverless/server/lib/backend.pyscript43.3 KB
serverless/server/lib/data_types.pyscript10.6 KB
serverless/server/lib/metrics.pyscript12.2 KB
serverless/server/lib/server.pyscript3.2 KB
serverless/server/worker.pyscript17.1 KB
sync/__init__.pyscript76 B
sync/client.pyscript4.9 KB
sync/results.pyscript1.2 KB
utils.pyscript12.2 KB

serverless/remote/serve_deployment.py

View on GitHub
#!/usr/bin/python
"""
Deployment bootstrap script invoked by start_server.sh when IS_DEPLOYMENT=true.

Downloads and extracts the deployment tarball, applies config.json
(env vars, apt packages, pip packages, run scripts), then starts the
deployment worker.
"""

import json
import os
import subprocess
import sys
import tarfile
import tempfile
import urllib.request


VAST_API_URL = os.environ.get("VAST_API_URL", "https://console.vast.ai")


def get_api_key() -> str:
    """Resolve an API key from the container environment.

    Inside a Vast instance, Kaalia sets CONTAINER_API_KEY with the
    instance-level API key that has permissions to fetch deployment blobs.
    """
    key = os.environ.get("CONTAINER_API_KEY") or os.environ.get("VAST_API_KEY")
    if not key:
        raise RuntimeError(
            "No API key found in environment (CONTAINER_API_KEY or VAST_API_KEY)"
        )
    return key


def get_download_url(deployment_id: str, api_key: str) -> str:
    """Fetch the presigned S3 download URL for the deployment blob."""
    url = f"{VAST_API_URL}/api/v0/deployment/{deployment_id}/download_url/"
    req = urllib.request.Request(url, headers={"Authorization": f"Bearer {api_key}"})
    with urllib.request.urlopen(req) as resp:
        data = json.loads(resp.read())
    if not data.get("success"):
        raise RuntimeError(f"Failed to get download URL: {data}")
    return data["download_url"]


def download_tarball(download_url: str) -> str:
    """Download the deployment tarball to a temp file, returning its path."""
    fd, path = tempfile.mkstemp(suffix=".tar.gz")
    try:
        with urllib.request.urlopen(download_url) as resp, os.fdopen(fd, "wb") as f:
            while True:
                chunk = resp.read(1 << 20)  # 1 MB
                if not chunk:
                    break
                f.write(chunk)
    except Exception:
        os.unlink(path)
        raise
    return path


def extract_tarball(tarball_path: str):
    cwd = os.getcwd()
    with tarfile.open(tarball_path, "r:gz") as tf:
        for member in tf.getmembers():
            tf.extract(
                member, filter="fully_trusted"
            )  # preserve absolute paths; deployment .tar files are created by client via deployments SDK and are trusted inside the container.


def get_config(path: str):
    """Load and return config.json as a Config dataclass."""
    from vastai.serverless.remote.base import Config

    with open(path) as f:
        raw = json.load(f)
    return Config(
        name=raw["name"],
        pip_installs=raw.get("pip_installs", []),
        apt_gets=raw.get("apt_gets", []),
        envs=raw.get("envs", []),
        runs=raw.get("runs", []),
    )


def export_envs(envs: list):
    """Export environment variables and append to /etc/environment."""
    etc_lines = []
    for entry in envs:
        key, value = entry[0], entry[1]
        os.environ[key] = value
        etc_lines.append(f'{key}="{value}"\n')
    if etc_lines:
        with open("/etc/environment", "a") as f:
            f.writelines(etc_lines)


def run_apt_gets(packages: list[str]):
    """Install apt packages."""
    if not packages:
        return
    subprocess.run(
        ["apt-get", "update", "-qq"],
        check=True,
    )
    subprocess.run(
        ["apt-get", "install", "-y", "-qq"] + packages,
        check=True,
    )


def run_pip_installs(packages: list[str]):
    """Install pip packages using uv."""
    if not packages:
        return
    subprocess.run(
        ["uv", "pip", "install"] + packages,
        check=True,
    )


def run_scripts(runs: list):
    """Run scripts from config.

    Each entry is either a string (passed to sh -c) or a list of args (execvp style).
    """
    for entry in runs:
        if isinstance(entry, str):
            subprocess.run(["sh", "-c", entry], check=True)
        elif isinstance(entry, (list, tuple)):
            subprocess.run(list(entry), check=True)
        else:
            raise ValueError(f"Invalid run entry: {entry!r}")


def main():
    deployment_id = os.environ.get("DEPLOYMENT_ID")
    if not deployment_id:
        raise RuntimeError("DEPLOYMENT_ID environment variable not set")

    debug_deployment_tar = os.environ.get("DEBUG_DEPLOYMENT_TAR")
    if debug_deployment_tar:
        tarball_path = debug_deployment_tar
    else:
        api_key = get_api_key()

        # Download deployment tarball
        print(f"Fetching download URL for deployment {deployment_id}")
        download_url = get_download_url(deployment_id, api_key)

        print("Downloading deployment tarball")
        tarball_path = download_tarball(download_url)

    # Extract preserving absolute paths — the deployment runs in a
    # container owned by the client, and we trust their path choices.
    print("Extracting deployment tarball")
    try:
        extract_tarball(tarball_path)
    finally:
        os.unlink(tarball_path)

    # Load config
    config = get_config("config.json")
    print(f"Loaded config for deployment: {config.name}")

    # (1) Export envs
    if config.envs:
        print(f"Exporting {len(config.envs)} environment variables")
        export_envs(config.envs)

    # (2) Install packages
    if config.apt_gets:
        print(f"Installing {len(config.apt_gets)} apt packages")
        run_apt_gets(config.apt_gets)

    if config.pip_installs:
        print(f"Installing {len(config.pip_installs)} pip packages")
        run_pip_installs(config.pip_installs)

    # (3) Run scripts
    if config.runs:
        print(f"Running {len(config.runs)} setup scripts")
        run_scripts(config.runs)

    # Look up and start deployment
    from vastai.serverless.remote.serve import Deployment

    # ensure deployment import time code is run in serve mode.
    os.environ["IS_DEPLOYMENT"] = "1"
    # deployment module/package is guaranteed from tarball
    sys.path.insert(0, os.getcwd())
    import deployment  # running this import has the side effect of registering deployments and remote functions with vastai.serverless.remote.serve.Deployment

    our_deployment = Deployment.lookup(config.name)
    if our_deployment is None:
        raise RuntimeError(f"Failed to lookup registered deployment: {config.name}")

    print(f"Starting deployment worker: {config.name}")
    worker = our_deployment.into_worker()
    worker.run()


if __name__ == "__main__":
    main()
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 198kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 194kUpdated Claude CodeCodexVerifiedInstall