feat: add support for coder_script (#9584)

* Add basic migrations

* Improve schema

* Refactor agent scripts into it's own package

* Support legacy start and stop script format

* Pipe the scripts!

* Finish the piping

* Fix context usage

* It works!

* Fix sql query

* Fix SQL query

* Rename `LogSourceID` -> `SourceID`

* Fix the FE

* fmt

* Rename migrations

* Fix log tests

* Fix lint err

* Fix gen

* Fix story type

* Rename source to script

* Fix schema jank

* Uncomment test

* Rename proto to TimeoutSeconds

* Fix comments

* Fix comments

* Fix legacy endpoint without specified log_source

* Fix non-blocking by default in agent

* Fix resources tests

* Fix dbfake

* Fix resources

* Fix linting I think

* Add fixtures

* fmt

* Fix startup script behavior

* Fix comments

* Fix context

* Fix cancel

* Fix SQL tests

* Fix e2e tests

* Interrupt on Windows

* Fix agent leaking script process

* Fix migrations

* Fix stories

* Fix duplicate logs appearing

* Gen

* Fix log location

* Fix tests

* Fix tests

* Fix log output

* Show display name in output

* Fix print

* Return timeout on start context

* Gen

* Fix fixture

* Fix the agent status

* Fix startup timeout msg

* Fix command using shared context

* Fix timeout draining

* Change signal type

* Add deterministic colors to startup script logs

---------

Co-authored-by: Muhammad Atif Ali <atif@coder.com>
This commit is contained in:
Kyle Carberry
2023-09-25 16:47:17 -05:00
committed by GitHub
parent dac1375880
commit 1262eef2c0
61 changed files with 3820 additions and 2117 deletions

126
coderd/apidoc/docs.go generated
View File

@ -6398,9 +6398,6 @@ const docTemplate = `{
},
"output": {
"type": "string"
},
"source": {
"$ref": "#/definitions/codersdk.WorkspaceAgentLogSource"
}
}
},
@ -6447,17 +6444,11 @@ const docTemplate = `{
"motd_file": {
"type": "string"
},
"shutdown_script": {
"type": "string"
},
"shutdown_script_timeout": {
"type": "integer"
},
"startup_script": {
"type": "string"
},
"startup_script_timeout": {
"type": "integer"
"scripts": {
"type": "array",
"items": {
"$ref": "#/definitions/codersdk.WorkspaceAgentScript"
}
},
"vscode_port_proxy_uri": {
"type": "string"
@ -6467,6 +6458,9 @@ const docTemplate = `{
"agentsdk.PatchLogs": {
"type": "object",
"properties": {
"log_source_id": {
"type": "string"
},
"logs": {
"type": "array",
"items": {
@ -10694,9 +10688,11 @@ const docTemplate = `{
"lifecycle_state": {
"$ref": "#/definitions/codersdk.WorkspaceAgentLifecycle"
},
"login_before_ready": {
"description": "Deprecated: Use StartupScriptBehavior instead.",
"type": "boolean"
"log_sources": {
"type": "array",
"items": {
"$ref": "#/definitions/codersdk.WorkspaceAgentLogSource"
}
},
"logs_length": {
"type": "integer"
@ -10718,25 +10714,23 @@ const docTemplate = `{
"type": "string",
"format": "uuid"
},
"shutdown_script": {
"type": "string"
},
"shutdown_script_timeout_seconds": {
"type": "integer"
"scripts": {
"type": "array",
"items": {
"$ref": "#/definitions/codersdk.WorkspaceAgentScript"
}
},
"started_at": {
"type": "string",
"format": "date-time"
},
"startup_script": {
"type": "string"
},
"startup_script_behavior": {
"$ref": "#/definitions/codersdk.WorkspaceAgentStartupScriptBehavior"
},
"startup_script_timeout_seconds": {
"description": "StartupScriptTimeoutSeconds is the number of seconds to wait for the startup script to complete. If the script does not complete within this time, the agent lifecycle will be marked as start_timeout.",
"type": "integer"
"description": "StartupScriptBehavior is a legacy field that is deprecated in favor\nof the ` + "`" + `coder_script` + "`" + ` resource. It's only referenced by old clients.\nDeprecated: Remove in the future!",
"allOf": [
{
"$ref": "#/definitions/codersdk.WorkspaceAgentStartupScriptBehavior"
}
]
},
"status": {
"$ref": "#/definitions/codersdk.WorkspaceAgentStatus"
@ -10856,27 +10850,35 @@ const docTemplate = `{
},
"output": {
"type": "string"
},
"source_id": {
"type": "string",
"format": "uuid"
}
}
},
"codersdk.WorkspaceAgentLogSource": {
"type": "string",
"enum": [
"startup_script",
"shutdown_script",
"kubernetes",
"envbox",
"envbuilder",
"external"
],
"x-enum-varnames": [
"WorkspaceAgentLogSourceStartupScript",
"WorkspaceAgentLogSourceShutdownScript",
"WorkspaceAgentLogSourceKubernetes",
"WorkspaceAgentLogSourceEnvbox",
"WorkspaceAgentLogSourceEnvbuilder",
"WorkspaceAgentLogSourceExternal"
]
"type": "object",
"properties": {
"created_at": {
"type": "string",
"format": "date-time"
},
"display_name": {
"type": "string"
},
"icon": {
"type": "string"
},
"id": {
"type": "string",
"format": "uuid"
},
"workspace_agent_id": {
"type": "string",
"format": "uuid"
}
}
},
"codersdk.WorkspaceAgentMetadataDescription": {
"type": "object",
@ -10898,6 +10900,36 @@ const docTemplate = `{
}
}
},
"codersdk.WorkspaceAgentScript": {
"type": "object",
"properties": {
"cron": {
"type": "string"
},
"log_path": {
"type": "string"
},
"log_source_id": {
"type": "string",
"format": "uuid"
},
"run_on_start": {
"type": "boolean"
},
"run_on_stop": {
"type": "boolean"
},
"script": {
"type": "string"
},
"start_blocks_login": {
"type": "boolean"
},
"timeout": {
"type": "integer"
}
}
},
"codersdk.WorkspaceAgentStartupScriptBehavior": {
"type": "string",
"enum": [