- Notifications
You must be signed in to change notification settings - Fork928
docs: add custom API use cases#8445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,86 @@ | ||
#Automation | ||
All actions possible through theCoderdashboard can also be automated as it utilizesthesame public REST API. There are several ways to extend/automate Coder: | ||
-[CLI](../cli.md) | ||
-[REST API](../api/) | ||
-[Coder SDK](https://pkg.go.dev/github.com/coder/coder/codersdk) | ||
##Quickstart | ||
Generate a token on your Coder deployment by visiting: | ||
```sh | ||
https://coder.example.com/settings/tokens | ||
``` | ||
List your workspaces | ||
```sh | ||
# CLI | ||
coder 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 an[API reference](../api/index.md) in our documentation. You can also enable a[Swagger endpoint](../cli/server#--swagger-enable) on your Coder deployment. | ||
##Use cases | ||
We strive to keep the following use cases up to date, but please note that changes to API queries and routes can occur. For the most recent queries and payloads, we recommend checking the CLI and API documentation. | ||
###Templates | ||
-[Update templates in CI](../templates/change-management.md): Store all templates and git and update templates in CI/CD pipelines. | ||
###Workspace agents | ||
Workspace agents have a special token that can send logs, metrics, and workspace activity. | ||
-[Custom workspace logs](../api/agents.md#patch-workspace-agent-startup-logs): Expose messages prior to the Coder init script running (e.g. pulling image, VM starting, restoring snapshot).[coder-logstream-kube](https://github.com/coder/coder-logstream-kube) uses this to show Kubernetes events, such as image pulls or ResourceQuota restrictions. | ||
```sh | ||
curl -X PATCH https://coder.example.com/api/v2/workspaceagents/me/startup-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](../api/agents.md#submit-workspace-agent-stats): Keep a workspace "active," even if there is not an open connection (e.g. for a long-running machine learning job). | ||
```sh | ||
#!/bin/bash | ||
# Send workspace activity as long as the job is still running | ||
whiletrue | ||
do | ||
if pgrep -f"my_training_script.py"> /dev/null | ||
then | ||
curl -X POST"https://coder.example.com/api/v2/workspaceagents/me/report-stats" \ | ||
-H"Coder-Session-Token:$CODER_AGENT_TOKEN" \ | ||
-d'{ | ||
"connection_count": 1 | ||
}' | ||
# Sleep for 30 minutes (1800 seconds) if the job is running | ||
sleep 1800 | ||
else | ||
# Sleep for 1 minute (60 seconds) if the job is not running | ||
sleep 60 | ||
fi | ||
done | ||
``` |