Movatterモバイル変換


[0]ホーム

URL:


HomeReference

Reference

Automation

All actions possible through the Coder dashboard can also be automated. Thereare several ways to extend/automate Coder:

Quickstart

Generate a token on your Coder deployment by visiting:

https://coder.example.com/settings/tokens

List your workspaces

# CLIcoder ls \ --url https://coder.example.com \ --token <your-token> \ --output json# REST API (with curl)curl https://coder.example.com/api/v2/workspaces?q=owner:me \ -H "Coder-Session-Token: <your-token>"

Documentation

We publish anAPI reference in our documentation.You can also enable aSwagger endpoint on your Coderdeployment.

Use cases

We strive to keep the following use cases up to date, but please note thatchanges to API queries and routes can occur. For the most recent queries andpayloads, we recommend checking the relevant documentation.

Users & Groups

Templates

Workspace agents

Workspace agents have a special token that can send logs, metrics, and workspaceactivity.

  • Custom workspace logs:Expose messages prior to the Coder init script running (e.g. pulling image, VMstarting, restoring snapshot).coder-logstream-kube usesthis to show Kubernetes events, such as image pulls or ResourceQuotarestrictions.

    curl -X PATCH https://coder.example.com/api/v2/workspaceagents/me/logs \-H "Coder-Session-Token: $CODER_AGENT_TOKEN" \-d "{\"logs\": [ { \"created_at\": \"$(date -u +'%Y-%m-%dT%H:%M:%SZ')\", \"level\": \"info\", \"output\": \"Restoring workspace from snapshot: 05%...\" }]}"
  • Manually send workspace activity:Keep a workspace "active," even if there is not an open connection (e.g. for along-running machine learning job).

    #!/bin/bash# Send workspace activity as long as the job is still runningwhile truedoif pgrep -f "my_training_script.py" > /dev/nullthen curl -X PUT "https://coder.example.com/api/v2/workspaces/$WORKSPACE_ID/extend" \ -H "Coder-Session-Token: $CODER_AGENT_TOKEN" \ -d '{ "deadline": "2019-08-24T14:15:22Z" }' # Sleep for 30 minutes (1800 seconds) if the job is running sleep 1800else # Sleep for 1 minute (60 seconds) if the job is not running sleep 60fidone
On this page

[8]ページ先頭

©2009-2025 Movatter.jp