From dae7967bd16df9a137c3895fc82876493bd06953 Mon Sep 17 00:00:00 2001 From: Bobby Ho Date: Mon, 12 Oct 2026 20:43:55 -0700 Subject: [PATCH] feat: persist script resource addresses and dependencies (#30625) feat(coderd): persist workspace agent script dependencies Persist Terraform resource addresses and script dependencies supplied by the provisioner (#30451, #30491), and expose them through the SDK and REST API. - Add migration 000618 with `resource_address` and `dependencies` columns, empty defaults, and a JSON-array constraint. API responses always include the address and omit empty dependency lists. - Preserve `success` and `completion` requirements, including scripts on devcontainer subagents. Legacy scripts and older provisioners remain compatible through empty defaults. - Reject empty prerequisite addresses and unsupported requirements, rolling back the entire job. Invalid stored dependencies return HTTP 500 rather than silently dropping ordering. - Add persistence, validation, rollback, devcontainer, API, and migration coverage; regenerate API docs and TypeScript types. Unordered templates retain their existing execution behavior. Dependency lists remain empty until #30556. Agent manifest wiring and the agent API version bump are deferred to a follow-up. Refs PLAT-548. --- coderd/apidoc/docs.go | 33 + coderd/apidoc/swagger.json | 30 + coderd/database/check_constraint.go | 1 + coderd/database/db2sdk/db2sdk.go | 30 +- .../database/db2sdk/db2sdk_internal_test.go | 74 ++ coderd/database/dbgen/dbgen.go | 8 + coderd/database/dump.sql | 5 +- ...rkspace_agent_script_dependencies.down.sql | 3 + ...workspace_agent_script_dependencies.up.sql | 5 + ...workspace_agent_script_dependencies.up.sql | 29 + coderd/database/models.go | 26 +- coderd/database/queries.sql.go | 22 +- coderd/database/queries/workspacescripts.sql | 8 +- .../provisionerdserver/provisionerdserver.go | 116 +++- .../provisionerdserver_test.go | 255 ++++++- .../script_dependencies_internal_test.go | 84 +++ coderd/provisionerjobs.go | 11 +- coderd/workspaceagents.go | 25 +- coderd/workspaceagents_test.go | 42 ++ coderd/workspacebuilds.go | 6 +- codersdk/workspaceagents.go | 58 +- docs/reference/api/agents.md | 7 + docs/reference/api/builds.md | 632 ++++++++++-------- docs/reference/api/schemas.md | 97 ++- docs/reference/api/templates.md | 484 +++++++------- docs/reference/api/workspaces.md | 37 + site/src/api/typesGenerated.ts | 29 + site/src/testHelpers/entities.ts | 1 + 28 files changed, 1556 insertions(+), 602 deletions(-) create mode 100644 coderd/database/migrations/000618_workspace_agent_script_dependencies.down.sql create mode 100644 coderd/database/migrations/000618_workspace_agent_script_dependencies.up.sql create mode 100644 coderd/database/migrations/testdata/fixtures/000618_workspace_agent_script_dependencies.up.sql create mode 100644 coderd/provisionerdserver/script_dependencies_internal_test.go diff --git a/coderd/apidoc/docs.go b/coderd/apidoc/docs.go index a372be96f3c..748955ca898 100644 --- a/coderd/apidoc/docs.go +++ b/coderd/apidoc/docs.go @@ -33284,6 +33284,13 @@ const docTemplate = `{ "cron": { "type": "string" }, + "dependencies": { + "description": "Dependencies lists the scripts this one waits for, as the\nprovisioner resolved them. It is omitted when empty.", + "type": "array", + "items": { + "$ref": "#/definitions/codersdk.WorkspaceAgentScriptDependency" + } + }, "display_name": { "type": "string" }, @@ -33301,6 +33308,10 @@ const docTemplate = `{ "type": "string", "format": "uuid" }, + "resource_address": { + "description": "ResourceAddress is the full Terraform address of the coder_script\nresource, for example \"module.git_clone.coder_script.clone\". It is\nempty for scripts that are not coder_script resources.", + "type": "string" + }, "run_on_start": { "type": "boolean" }, @@ -33321,6 +33332,28 @@ const docTemplate = `{ } } }, + "codersdk.WorkspaceAgentScriptDependency": { + "type": "object", + "properties": { + "prerequisite_resource_address": { + "type": "string" + }, + "requirement": { + "$ref": "#/definitions/codersdk.WorkspaceAgentScriptDependencyRequirement" + } + } + }, + "codersdk.WorkspaceAgentScriptDependencyRequirement": { + "type": "string", + "enum": [ + "success", + "completion" + ], + "x-enum-varnames": [ + "WorkspaceAgentScriptDependencyRequirementSuccess", + "WorkspaceAgentScriptDependencyRequirementCompletion" + ] + }, "codersdk.WorkspaceAgentScriptStatus": { "type": "string", "enum": [ diff --git a/coderd/apidoc/swagger.json b/coderd/apidoc/swagger.json index e1324ac12f9..a64282b6f1f 100644 --- a/coderd/apidoc/swagger.json +++ b/coderd/apidoc/swagger.json @@ -30751,6 +30751,13 @@ "cron": { "type": "string" }, + "dependencies": { + "description": "Dependencies lists the scripts this one waits for, as the\nprovisioner resolved them. It is omitted when empty.", + "type": "array", + "items": { + "$ref": "#/definitions/codersdk.WorkspaceAgentScriptDependency" + } + }, "display_name": { "type": "string" }, @@ -30768,6 +30775,10 @@ "type": "string", "format": "uuid" }, + "resource_address": { + "description": "ResourceAddress is the full Terraform address of the coder_script\nresource, for example \"module.git_clone.coder_script.clone\". It is\nempty for scripts that are not coder_script resources.", + "type": "string" + }, "run_on_start": { "type": "boolean" }, @@ -30788,6 +30799,25 @@ } } }, + "codersdk.WorkspaceAgentScriptDependency": { + "type": "object", + "properties": { + "prerequisite_resource_address": { + "type": "string" + }, + "requirement": { + "$ref": "#/definitions/codersdk.WorkspaceAgentScriptDependencyRequirement" + } + } + }, + "codersdk.WorkspaceAgentScriptDependencyRequirement": { + "type": "string", + "enum": ["success", "completion"], + "x-enum-varnames": [ + "WorkspaceAgentScriptDependencyRequirementSuccess", + "WorkspaceAgentScriptDependencyRequirementCompletion" + ] + }, "codersdk.WorkspaceAgentScriptStatus": { "type": "string", "enum": ["ok", "exit_failure", "timed_out", "pipes_left_open"], diff --git a/coderd/database/check_constraint.go b/coderd/database/check_constraint.go index be8be706106..a19fed27507 100644 --- a/coderd/database/check_constraint.go +++ b/coderd/database/check_constraint.go @@ -76,6 +76,7 @@ const ( CheckUserSkillsDescriptionSize CheckConstraint = "user_skills_description_size" // user_skills CheckUserSkillsNameFormat CheckConstraint = "user_skills_name_format" // user_skills CheckUserSkillsNameSize CheckConstraint = "user_skills_name_size" // user_skills + CheckWorkspaceAgentScriptsDependenciesIsArray CheckConstraint = "workspace_agent_scripts_dependencies_is_array" // workspace_agent_scripts CheckMaxLogsLength CheckConstraint = "max_logs_length" // workspace_agents CheckSubsystemsNotNone CheckConstraint = "subsystems_not_none" // workspace_agents CheckWorkspaceBuildOrchestrationsAttemptCountCheck CheckConstraint = "workspace_build_orchestrations_attempt_count_check" // workspace_build_orchestrations diff --git a/coderd/database/db2sdk/db2sdk.go b/coderd/database/db2sdk/db2sdk.go index d63331e5fc0..91ad6a08d08 100644 --- a/coderd/database/db2sdk/db2sdk.go +++ b/coderd/database/db2sdk/db2sdk.go @@ -768,7 +768,31 @@ func WorkspaceAgentLog(log database.WorkspaceAgentLog) codersdk.WorkspaceAgentLo } } -func WorkspaceAgentScript(dbScript database.GetWorkspaceAgentScriptsByAgentIDsRow) codersdk.WorkspaceAgentScript { +// WorkspaceAgentScript converts a script row to the SDK type. It fails on a +// dependencies column that cannot be decoded or that holds an entry the SDK +// cannot represent, so a caller never receives a partial list. The write +// path already rejects such rows, so one here means a bug or a manual edit +// of the database. +func WorkspaceAgentScript(dbScript database.GetWorkspaceAgentScriptsByAgentIDsRow) (codersdk.WorkspaceAgentScript, error) { + var dependencies []codersdk.WorkspaceAgentScriptDependency + if len(dbScript.Dependencies) > 0 { + if err := json.Unmarshal(dbScript.Dependencies, &dependencies); err != nil { + return codersdk.WorkspaceAgentScript{}, xerrors.Errorf("decode dependencies: %w", err) + } + } + if len(dependencies) == 0 { + // nil rather than an empty slice so omitempty leaves the key out. + dependencies = nil + } + for i, dependency := range dependencies { + if dependency.PrerequisiteResourceAddress == "" { + return codersdk.WorkspaceAgentScript{}, xerrors.Errorf("dependency %d has an empty prerequisite resource address", i) + } + if !dependency.Requirement.Valid() { + return codersdk.WorkspaceAgentScript{}, xerrors.Errorf("dependency %d has unsupported requirement %q", i, dependency.Requirement) + } + } + script := codersdk.WorkspaceAgentScript{ ID: dbScript.ID, LogPath: dbScript.LogPath, @@ -780,13 +804,15 @@ func WorkspaceAgentScript(dbScript database.GetWorkspaceAgentScriptsByAgentIDsRo StartBlocksLogin: dbScript.StartBlocksLogin, Timeout: time.Duration(dbScript.TimeoutSeconds) * time.Second, DisplayName: dbScript.DisplayName, + ResourceAddress: dbScript.ResourceAddress, + Dependencies: dependencies, ExitCode: nullInt32Ptr(dbScript.ExitCode), } if dbScript.Status.Valid { status := codersdk.WorkspaceAgentScriptStatus(dbScript.Status.WorkspaceAgentScriptTimingStatus) script.Status = &status } - return script + return script, nil } func ProvisionerDaemon(dbDaemon database.ProvisionerDaemon) codersdk.ProvisionerDaemon { diff --git a/coderd/database/db2sdk/db2sdk_internal_test.go b/coderd/database/db2sdk/db2sdk_internal_test.go index 068e1f47747..a977de3c6c2 100644 --- a/coderd/database/db2sdk/db2sdk_internal_test.go +++ b/coderd/database/db2sdk/db2sdk_internal_test.go @@ -12,6 +12,80 @@ import ( "github.com/coder/coder/v2/codersdk" ) +func TestWorkspaceAgentScriptDependencies(t *testing.T) { + t.Parallel() + + cases := []struct { + name string + dependencies string + want []codersdk.WorkspaceAgentScriptDependency + wantErr string + }{ + { + name: "EmptyArrayIsNil", + dependencies: `[]`, + want: nil, + }, + { + name: "EmptyColumnIsNil", + dependencies: ``, + want: nil, + }, + { + // A hand-written literal, so the column format is a tested + // contract rather than whatever the encoder produces. + name: "DecodesLiteral", + dependencies: `[{"prerequisite_resource_address":"coder_script.clone_repo","requirement":"success"},` + + `{"prerequisite_resource_address":"coder_script.warm_cache","requirement":"completion"}]`, + want: []codersdk.WorkspaceAgentScriptDependency{ + { + PrerequisiteResourceAddress: "coder_script.clone_repo", + Requirement: codersdk.WorkspaceAgentScriptDependencyRequirementSuccess, + }, + { + PrerequisiteResourceAddress: "coder_script.warm_cache", + Requirement: codersdk.WorkspaceAgentScriptDependencyRequirementCompletion, + }, + }, + }, + { + name: "MalformedJSON", + dependencies: `[`, + wantErr: "decode dependencies", + }, + { + name: "EmptyAddress", + dependencies: `[{"requirement":"success"}]`, + wantErr: "dependency 0 has an empty prerequisite resource address", + }, + { + name: "UnknownRequirement", + dependencies: `[{"prerequisite_resource_address":"coder_script.clone_repo","requirement":"eventually"}]`, + wantErr: `dependency 0 has unsupported requirement "eventually"`, + }, + } + + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + + got, err := WorkspaceAgentScript(database.GetWorkspaceAgentScriptsByAgentIDsRow{ + ID: uuid.New(), + DisplayName: "Install tools", + ResourceAddress: "coder_script.install_tools", + Dependencies: json.RawMessage(tc.dependencies), + }) + if tc.wantErr != "" { + require.ErrorContains(t, err, tc.wantErr) + return + } + require.NoError(t, err) + require.Equal(t, "coder_script.install_tools", got.ResourceAddress) + require.Equal(t, tc.want, got.Dependencies) + }) + } +} + func TestAggregateTokenMetadata(t *testing.T) { t.Parallel() diff --git a/coderd/database/dbgen/dbgen.go b/coderd/database/dbgen/dbgen.go index 5547e02e1c0..d9d3373dc86 100644 --- a/coderd/database/dbgen/dbgen.go +++ b/coderd/database/dbgen/dbgen.go @@ -828,6 +828,12 @@ func WorkspaceSubAgent(t testing.TB, db database.Store, parentAgent database.Wor } func WorkspaceAgentScript(t testing.TB, db database.Store, orig database.WorkspaceAgentScript) database.WorkspaceAgentScript { + // Casting an empty string to jsonb is a Postgres error, not an empty + // list, so the default has to be written out. + dependencies := orig.Dependencies + if len(dependencies) == 0 { + dependencies = json.RawMessage(`[]`) + } scripts, err := db.InsertWorkspaceAgentScripts(genCtx, database.InsertWorkspaceAgentScriptsParams{ WorkspaceAgentID: takeFirst(orig.WorkspaceAgentID, uuid.New()), CreatedAt: takeFirst(orig.CreatedAt, dbtime.Now()), @@ -841,6 +847,8 @@ func WorkspaceAgentScript(t testing.TB, db database.Store, orig database.Workspa TimeoutSeconds: []int32{takeFirst(orig.TimeoutSeconds, 0)}, DisplayName: []string{takeFirst(orig.DisplayName, "")}, ID: []uuid.UUID{takeFirst(orig.ID, uuid.New())}, + ResourceAddress: []string{takeFirst(orig.ResourceAddress, "")}, + Dependencies: []string{string(dependencies)}, }) require.NoError(t, err, "insert workspace agent script") require.NotEmpty(t, scripts, "insert workspace agent script returned no scripts") diff --git a/coderd/database/dump.sql b/coderd/database/dump.sql index 948fe34b471..cd5c4ec8196 100644 --- a/coderd/database/dump.sql +++ b/coderd/database/dump.sql @@ -3777,7 +3777,10 @@ CREATE TABLE workspace_agent_scripts ( run_on_stop boolean NOT NULL, timeout_seconds integer NOT NULL, display_name text NOT NULL, - id uuid DEFAULT gen_random_uuid() NOT NULL + id uuid DEFAULT gen_random_uuid() NOT NULL, + resource_address text DEFAULT ''::text NOT NULL, + dependencies jsonb DEFAULT '[]'::jsonb NOT NULL, + CONSTRAINT workspace_agent_scripts_dependencies_is_array CHECK ((jsonb_typeof(dependencies) = 'array'::text)) ); CREATE SEQUENCE workspace_agent_startup_logs_id_seq diff --git a/coderd/database/migrations/000618_workspace_agent_script_dependencies.down.sql b/coderd/database/migrations/000618_workspace_agent_script_dependencies.down.sql new file mode 100644 index 00000000000..d0181939ae5 --- /dev/null +++ b/coderd/database/migrations/000618_workspace_agent_script_dependencies.down.sql @@ -0,0 +1,3 @@ +ALTER TABLE workspace_agent_scripts + DROP COLUMN dependencies, + DROP COLUMN resource_address; diff --git a/coderd/database/migrations/000618_workspace_agent_script_dependencies.up.sql b/coderd/database/migrations/000618_workspace_agent_script_dependencies.up.sql new file mode 100644 index 00000000000..1955d9e61ff --- /dev/null +++ b/coderd/database/migrations/000618_workspace_agent_script_dependencies.up.sql @@ -0,0 +1,5 @@ +ALTER TABLE workspace_agent_scripts + ADD COLUMN resource_address TEXT NOT NULL DEFAULT '', + ADD COLUMN dependencies JSONB NOT NULL DEFAULT '[]'::jsonb, + ADD CONSTRAINT workspace_agent_scripts_dependencies_is_array + CHECK (jsonb_typeof(dependencies) = 'array'); diff --git a/coderd/database/migrations/testdata/fixtures/000618_workspace_agent_script_dependencies.up.sql b/coderd/database/migrations/testdata/fixtures/000618_workspace_agent_script_dependencies.up.sql new file mode 100644 index 00000000000..8373fe3e494 --- /dev/null +++ b/coderd/database/migrations/testdata/fixtures/000618_workspace_agent_script_dependencies.up.sql @@ -0,0 +1,29 @@ +INSERT INTO workspace_agent_scripts ( + workspace_agent_id, + created_at, + log_source_id, + log_path, + script, + cron, + start_blocks_login, + run_on_start, + run_on_stop, + timeout_seconds, + display_name, + resource_address, + dependencies +) VALUES ( + '45e89705-e09d-4850-bcec-f9a937f5d78d', + '2022-11-02 13:03:45.046432+02', + '0ff953c0-92a6-4fe6-a415-eb0139a36ad1', + '/tmp/install.log', + 'npm install', + '', + FALSE, + TRUE, + FALSE, + 0, + 'Install tools', + 'coder_script.install_tools', + '[{"prerequisite_resource_address":"coder_script.clone_repo","requirement":"success"}]' +) ON CONFLICT DO NOTHING; diff --git a/coderd/database/models.go b/coderd/database/models.go index f4924765897..77ca6f5f710 100644 --- a/coderd/database/models.go +++ b/coderd/database/models.go @@ -6705,18 +6705,20 @@ type WorkspaceAgentPortShare struct { } type WorkspaceAgentScript struct { - WorkspaceAgentID uuid.UUID `db:"workspace_agent_id" json:"workspace_agent_id"` - LogSourceID uuid.UUID `db:"log_source_id" json:"log_source_id"` - LogPath string `db:"log_path" json:"log_path"` - CreatedAt time.Time `db:"created_at" json:"created_at"` - Script string `db:"script" json:"script"` - Cron string `db:"cron" json:"cron"` - StartBlocksLogin bool `db:"start_blocks_login" json:"start_blocks_login"` - RunOnStart bool `db:"run_on_start" json:"run_on_start"` - RunOnStop bool `db:"run_on_stop" json:"run_on_stop"` - TimeoutSeconds int32 `db:"timeout_seconds" json:"timeout_seconds"` - DisplayName string `db:"display_name" json:"display_name"` - ID uuid.UUID `db:"id" json:"id"` + WorkspaceAgentID uuid.UUID `db:"workspace_agent_id" json:"workspace_agent_id"` + LogSourceID uuid.UUID `db:"log_source_id" json:"log_source_id"` + LogPath string `db:"log_path" json:"log_path"` + CreatedAt time.Time `db:"created_at" json:"created_at"` + Script string `db:"script" json:"script"` + Cron string `db:"cron" json:"cron"` + StartBlocksLogin bool `db:"start_blocks_login" json:"start_blocks_login"` + RunOnStart bool `db:"run_on_start" json:"run_on_start"` + RunOnStop bool `db:"run_on_stop" json:"run_on_stop"` + TimeoutSeconds int32 `db:"timeout_seconds" json:"timeout_seconds"` + DisplayName string `db:"display_name" json:"display_name"` + ID uuid.UUID `db:"id" json:"id"` + ResourceAddress string `db:"resource_address" json:"resource_address"` + Dependencies json.RawMessage `db:"dependencies" json:"dependencies"` } type WorkspaceAgentScriptTiming struct { diff --git a/coderd/database/queries.sql.go b/coderd/database/queries.sql.go index 4ba5434a314..8d32c418a3a 100644 --- a/coderd/database/queries.sql.go +++ b/coderd/database/queries.sql.go @@ -42231,7 +42231,7 @@ func (q *sqlQuerier) UpdateWorkspacesTTLByTemplateID(ctx context.Context, arg Up const getWorkspaceAgentScriptsByAgentIDs = `-- name: GetWorkspaceAgentScriptsByAgentIDs :many SELECT - DISTINCT ON (workspace_agent_scripts.id) workspace_agent_scripts.workspace_agent_id, workspace_agent_scripts.log_source_id, workspace_agent_scripts.log_path, workspace_agent_scripts.created_at, workspace_agent_scripts.script, workspace_agent_scripts.cron, workspace_agent_scripts.start_blocks_login, workspace_agent_scripts.run_on_start, workspace_agent_scripts.run_on_stop, workspace_agent_scripts.timeout_seconds, workspace_agent_scripts.display_name, workspace_agent_scripts.id, + DISTINCT ON (workspace_agent_scripts.id) workspace_agent_scripts.workspace_agent_id, workspace_agent_scripts.log_source_id, workspace_agent_scripts.log_path, workspace_agent_scripts.created_at, workspace_agent_scripts.script, workspace_agent_scripts.cron, workspace_agent_scripts.start_blocks_login, workspace_agent_scripts.run_on_start, workspace_agent_scripts.run_on_stop, workspace_agent_scripts.timeout_seconds, workspace_agent_scripts.display_name, workspace_agent_scripts.id, workspace_agent_scripts.resource_address, workspace_agent_scripts.dependencies, workspace_agent_script_timings.exit_code, workspace_agent_script_timings.status FROM workspace_agent_scripts @@ -42255,6 +42255,8 @@ type GetWorkspaceAgentScriptsByAgentIDsRow struct { TimeoutSeconds int32 `db:"timeout_seconds" json:"timeout_seconds"` DisplayName string `db:"display_name" json:"display_name"` ID uuid.UUID `db:"id" json:"id"` + ResourceAddress string `db:"resource_address" json:"resource_address"` + Dependencies json.RawMessage `db:"dependencies" json:"dependencies"` ExitCode sql.NullInt32 `db:"exit_code" json:"exit_code"` Status NullWorkspaceAgentScriptTimingStatus `db:"status" json:"status"` } @@ -42281,6 +42283,8 @@ func (q *sqlQuerier) GetWorkspaceAgentScriptsByAgentIDs(ctx context.Context, ids &i.TimeoutSeconds, &i.DisplayName, &i.ID, + &i.ResourceAddress, + &i.Dependencies, &i.ExitCode, &i.Status, ); err != nil { @@ -42299,7 +42303,7 @@ func (q *sqlQuerier) GetWorkspaceAgentScriptsByAgentIDs(ctx context.Context, ids const insertWorkspaceAgentScripts = `-- name: InsertWorkspaceAgentScripts :many INSERT INTO - workspace_agent_scripts (workspace_agent_id, created_at, log_source_id, log_path, script, cron, start_blocks_login, run_on_start, run_on_stop, timeout_seconds, display_name, id) + workspace_agent_scripts (workspace_agent_id, created_at, log_source_id, log_path, script, cron, start_blocks_login, run_on_start, run_on_stop, timeout_seconds, display_name, id, resource_address, dependencies) SELECT $1 :: uuid AS workspace_agent_id, $2 :: timestamptz AS created_at, @@ -42312,8 +42316,12 @@ SELECT unnest($9 :: boolean [ ]) AS run_on_stop, unnest($10 :: integer [ ]) AS timeout_seconds, unnest($11 :: text [ ]) AS display_name, - unnest($12 :: uuid [ ]) AS id -RETURNING workspace_agent_scripts.workspace_agent_id, workspace_agent_scripts.log_source_id, workspace_agent_scripts.log_path, workspace_agent_scripts.created_at, workspace_agent_scripts.script, workspace_agent_scripts.cron, workspace_agent_scripts.start_blocks_login, workspace_agent_scripts.run_on_start, workspace_agent_scripts.run_on_stop, workspace_agent_scripts.timeout_seconds, workspace_agent_scripts.display_name, workspace_agent_scripts.id + unnest($12 :: uuid [ ]) AS id, + unnest($13 :: text [ ]) AS resource_address, + -- The driver accepts a text array more reliably than a jsonb array, + -- so each element is cast to jsonb inside the query. + unnest($14 :: text [ ]) :: jsonb AS dependencies +RETURNING workspace_agent_scripts.workspace_agent_id, workspace_agent_scripts.log_source_id, workspace_agent_scripts.log_path, workspace_agent_scripts.created_at, workspace_agent_scripts.script, workspace_agent_scripts.cron, workspace_agent_scripts.start_blocks_login, workspace_agent_scripts.run_on_start, workspace_agent_scripts.run_on_stop, workspace_agent_scripts.timeout_seconds, workspace_agent_scripts.display_name, workspace_agent_scripts.id, workspace_agent_scripts.resource_address, workspace_agent_scripts.dependencies ` type InsertWorkspaceAgentScriptsParams struct { @@ -42329,6 +42337,8 @@ type InsertWorkspaceAgentScriptsParams struct { TimeoutSeconds []int32 `db:"timeout_seconds" json:"timeout_seconds"` DisplayName []string `db:"display_name" json:"display_name"` ID []uuid.UUID `db:"id" json:"id"` + ResourceAddress []string `db:"resource_address" json:"resource_address"` + Dependencies []string `db:"dependencies" json:"dependencies"` } func (q *sqlQuerier) InsertWorkspaceAgentScripts(ctx context.Context, arg InsertWorkspaceAgentScriptsParams) ([]WorkspaceAgentScript, error) { @@ -42345,6 +42355,8 @@ func (q *sqlQuerier) InsertWorkspaceAgentScripts(ctx context.Context, arg Insert pq.Array(arg.TimeoutSeconds), pq.Array(arg.DisplayName), pq.Array(arg.ID), + pq.Array(arg.ResourceAddress), + pq.Array(arg.Dependencies), ) if err != nil { return nil, err @@ -42366,6 +42378,8 @@ func (q *sqlQuerier) InsertWorkspaceAgentScripts(ctx context.Context, arg Insert &i.TimeoutSeconds, &i.DisplayName, &i.ID, + &i.ResourceAddress, + &i.Dependencies, ); err != nil { return nil, err } diff --git a/coderd/database/queries/workspacescripts.sql b/coderd/database/queries/workspacescripts.sql index fcf90a78326..9eec90edca4 100644 --- a/coderd/database/queries/workspacescripts.sql +++ b/coderd/database/queries/workspacescripts.sql @@ -1,6 +1,6 @@ -- name: InsertWorkspaceAgentScripts :many INSERT INTO - workspace_agent_scripts (workspace_agent_id, created_at, log_source_id, log_path, script, cron, start_blocks_login, run_on_start, run_on_stop, timeout_seconds, display_name, id) + workspace_agent_scripts (workspace_agent_id, created_at, log_source_id, log_path, script, cron, start_blocks_login, run_on_start, run_on_stop, timeout_seconds, display_name, id, resource_address, dependencies) SELECT @workspace_agent_id :: uuid AS workspace_agent_id, @created_at :: timestamptz AS created_at, @@ -13,7 +13,11 @@ SELECT unnest(@run_on_stop :: boolean [ ]) AS run_on_stop, unnest(@timeout_seconds :: integer [ ]) AS timeout_seconds, unnest(@display_name :: text [ ]) AS display_name, - unnest(@id :: uuid [ ]) AS id + unnest(@id :: uuid [ ]) AS id, + unnest(@resource_address :: text [ ]) AS resource_address, + -- The driver accepts a text array more reliably than a jsonb array, + -- so each element is cast to jsonb inside the query. + unnest(@dependencies :: text [ ]) :: jsonb AS dependencies RETURNING workspace_agent_scripts.*; -- name: GetWorkspaceAgentScriptsByAgentIDs :many diff --git a/coderd/provisionerdserver/provisionerdserver.go b/coderd/provisionerdserver/provisionerdserver.go index 3846562a19e..95c7c5b35d8 100644 --- a/coderd/provisionerdserver/provisionerdserver.go +++ b/coderd/provisionerdserver/provisionerdserver.go @@ -3037,7 +3037,10 @@ func InsertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid. } } - scriptsParams := agentScriptsFromProto(prAgent.Scripts) + scriptsParams, err := agentScriptsFromProto(prAgent.Scripts) + if err != nil { + return xerrors.Errorf("convert agent scripts: %w", err) + } // Dev Containers require a script and log/source, so we do this before // the logs insert below. @@ -3084,6 +3087,10 @@ func InsertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid. scriptsParams.ScriptStartBlocksLogin = append(scriptsParams.ScriptStartBlocksLogin, false) scriptsParams.ScriptRunOnStart = append(scriptsParams.ScriptRunOnStart, false) scriptsParams.ScriptRunOnStop = append(scriptsParams.ScriptRunOnStop, false) + // Every slice must stay the same length: unnest pads a short + // array with NULL and the NOT NULL columns reject the insert. + scriptsParams.ScriptResourceAddresses = append(scriptsParams.ScriptResourceAddresses, "") + scriptsParams.ScriptDependencies = append(scriptsParams.ScriptDependencies, "[]") } _, err = db.InsertWorkspaceAgentDevcontainers(ctx, database.InsertWorkspaceAgentDevcontainersParams{ @@ -3533,7 +3540,11 @@ func insertDevcontainerSubagent( } } - if err := insertAgentScriptsAndLogSources(ctx, db, subAgentID, agentScriptsFromProto(dc.GetScripts())); err != nil { + dcScriptsParams, err := agentScriptsFromProto(dc.GetScripts()) + if err != nil { + return uuid.UUID{}, xerrors.Errorf("convert devcontainer agent scripts: %w", err) + } + if err := insertAgentScriptsAndLogSources(ctx, db, subAgentID, dcScriptsParams); err != nil { return uuid.UUID{}, xerrors.Errorf("insert agent scripts and log sources: %w", err) } @@ -3604,34 +3615,41 @@ type agentScriptsParams struct { LogSourceDisplayNames []string LogSourceIcons []string - ScriptIDs []uuid.UUID - ScriptDisplayNames []string - ScriptLogPaths []string - ScriptSources []string - ScriptCron []string - ScriptTimeout []int32 - ScriptStartBlocksLogin []bool - ScriptRunOnStart []bool - ScriptRunOnStop []bool + ScriptIDs []uuid.UUID + ScriptDisplayNames []string + ScriptLogPaths []string + ScriptSources []string + ScriptCron []string + ScriptTimeout []int32 + ScriptStartBlocksLogin []bool + ScriptRunOnStart []bool + ScriptRunOnStop []bool + ScriptResourceAddresses []string + // ScriptDependencies holds one JSON array per script, "[]" when none. + ScriptDependencies []string } // agentScriptsFromProto converts a slice of proto scripts into the -// agentScriptsParams struct needed for database insertion. -func agentScriptsFromProto(scripts []*sdkproto.Script) agentScriptsParams { +// agentScriptsParams struct needed for database insertion. It fails on a +// dependency entry coderd cannot store, so the job fails before any row +// is written. +func agentScriptsFromProto(scripts []*sdkproto.Script) (agentScriptsParams, error) { params := agentScriptsParams{ LogSourceIDs: make([]uuid.UUID, 0, len(scripts)), LogSourceDisplayNames: make([]string, 0, len(scripts)), LogSourceIcons: make([]string, 0, len(scripts)), - ScriptIDs: make([]uuid.UUID, 0, len(scripts)), - ScriptDisplayNames: make([]string, 0, len(scripts)), - ScriptLogPaths: make([]string, 0, len(scripts)), - ScriptSources: make([]string, 0, len(scripts)), - ScriptCron: make([]string, 0, len(scripts)), - ScriptTimeout: make([]int32, 0, len(scripts)), - ScriptStartBlocksLogin: make([]bool, 0, len(scripts)), - ScriptRunOnStart: make([]bool, 0, len(scripts)), - ScriptRunOnStop: make([]bool, 0, len(scripts)), + ScriptIDs: make([]uuid.UUID, 0, len(scripts)), + ScriptDisplayNames: make([]string, 0, len(scripts)), + ScriptLogPaths: make([]string, 0, len(scripts)), + ScriptSources: make([]string, 0, len(scripts)), + ScriptCron: make([]string, 0, len(scripts)), + ScriptTimeout: make([]int32, 0, len(scripts)), + ScriptStartBlocksLogin: make([]bool, 0, len(scripts)), + ScriptRunOnStart: make([]bool, 0, len(scripts)), + ScriptRunOnStop: make([]bool, 0, len(scripts)), + ScriptResourceAddresses: make([]string, 0, len(scripts)), + ScriptDependencies: make([]string, 0, len(scripts)), } for _, script := range scripts { @@ -3648,9 +3666,59 @@ func agentScriptsFromProto(scripts []*sdkproto.Script) agentScriptsParams { params.ScriptStartBlocksLogin = append(params.ScriptStartBlocksLogin, script.GetStartBlocksLogin()) params.ScriptRunOnStart = append(params.ScriptRunOnStart, script.GetRunOnStart()) params.ScriptRunOnStop = append(params.ScriptRunOnStop, script.GetRunOnStop()) + params.ScriptResourceAddresses = append(params.ScriptResourceAddresses, script.GetResourceAddress()) + + dependencies, err := scriptDependenciesJSON(script.GetDependencies()) + if err != nil { + return agentScriptsParams{}, xerrors.Errorf("script %q dependencies: %w", script.GetResourceAddress(), err) + } + params.ScriptDependencies = append(params.ScriptDependencies, dependencies) } - return params + return params, nil +} + +// scriptDependenciesJSON encodes the provisioner's dependency list as the +// JSON stored in workspace_agent_scripts.dependencies. The document is +// []codersdk.WorkspaceAgentScriptDependency encoded with encoding/json, so +// the row, the REST API and the manifest spell the list one way. +func scriptDependenciesJSON(dependencies []*sdkproto.ScriptDependency) (string, error) { + encoded := make([]codersdk.WorkspaceAgentScriptDependency, 0, len(dependencies)) + for i, dependency := range dependencies { + requirement, err := scriptDependencyRequirementFromProto(dependency.GetRequirement()) + if err != nil { + return "", xerrors.Errorf("dependency %d: %w", i, err) + } + if dependency.GetPrerequisiteResourceAddress() == "" { + return "", xerrors.Errorf("dependency %d has an empty prerequisite resource address", i) + } + encoded = append(encoded, codersdk.WorkspaceAgentScriptDependency{ + PrerequisiteResourceAddress: dependency.GetPrerequisiteResourceAddress(), + Requirement: requirement, + }) + } + + // An empty slice encodes as `[]`, never `null`, which the column's + // array check would reject. + data, err := json.Marshal(encoded) + if err != nil { + return "", xerrors.Errorf("marshal dependencies: %w", err) + } + return string(data), nil +} + +// scriptDependencyRequirementFromProto maps the wire enum to the stored +// string. UNSPECIFIED is an error: the provisioner never sends it, so +// receiving it is a bug rather than a third kind of requirement. +func scriptDependencyRequirementFromProto(requirement sdkproto.ScriptDependencyRequirement) (codersdk.WorkspaceAgentScriptDependencyRequirement, error) { + switch requirement { + case sdkproto.ScriptDependencyRequirement_SCRIPT_DEPENDENCY_REQUIREMENT_SUCCESS: + return codersdk.WorkspaceAgentScriptDependencyRequirementSuccess, nil + case sdkproto.ScriptDependencyRequirement_SCRIPT_DEPENDENCY_REQUIREMENT_COMPLETION: + return codersdk.WorkspaceAgentScriptDependencyRequirementCompletion, nil + default: + return "", xerrors.Errorf("unsupported requirement %q", requirement) + } } // insertAgentScriptsAndLogSources inserts log sources and scripts for an agent (or @@ -3686,6 +3754,8 @@ func insertAgentScriptsAndLogSources(ctx context.Context, db database.Store, age RunOnStart: params.ScriptRunOnStart, RunOnStop: params.ScriptRunOnStop, DisplayName: params.ScriptDisplayNames, + ResourceAddress: params.ScriptResourceAddresses, + Dependencies: params.ScriptDependencies, }) if err != nil { return xerrors.Errorf("insert scripts: %w", err) diff --git a/coderd/provisionerdserver/provisionerdserver_test.go b/coderd/provisionerdserver/provisionerdserver_test.go index 7951471226b..244c9560ce5 100644 --- a/coderd/provisionerdserver/provisionerdserver_test.go +++ b/coderd/provisionerdserver/provisionerdserver_test.go @@ -3265,6 +3265,112 @@ func TestCompleteJob(t *testing.T) { } }) + t.Run("WorkspaceBuildRejectsBadScriptDependency", func(t *testing.T) { + t.Parallel() + + ctx := testutil.Context(t, testutil.WaitLong) + srv, db, ps, pd := setup(t, false, &overrides{}) + + user := dbgen.User(t, db, database.User{}) + template := dbgen.Template(t, db, database.Template{ + CreatedBy: user.ID, + Name: "template", + Provisioner: database.ProvisionerTypeEcho, + OrganizationID: pd.OrganizationID, + }) + file := dbgen.File(t, db, database.File{CreatedBy: user.ID}) + workspaceTable := dbgen.Workspace(t, db, database.WorkspaceTable{ + TemplateID: template.ID, + OwnerID: user.ID, + OrganizationID: pd.OrganizationID, + }) + version := dbgen.TemplateVersion(t, db, database.TemplateVersion{ + CreatedBy: user.ID, + OrganizationID: pd.OrganizationID, + TemplateID: uuid.NullUUID{ + UUID: template.ID, + Valid: true, + }, + JobID: uuid.New(), + }) + buildID := uuid.New() + job := dbgen.ProvisionerJob(t, db, ps, database.ProvisionerJob{ + FileID: file.ID, + InitiatorID: user.ID, + Type: database.ProvisionerJobTypeWorkspaceBuild, + Input: must(json.Marshal(provisionerdserver.WorkspaceProvisionJob{ + WorkspaceBuildID: buildID, + })), + OrganizationID: pd.OrganizationID, + }) + _ = dbgen.WorkspaceBuild(t, db, database.WorkspaceBuild{ + ID: buildID, + JobID: job.ID, + WorkspaceID: workspaceTable.ID, + InitiatorID: user.ID, + TemplateVersionID: version.ID, + Transition: database.WorkspaceTransitionStart, + Reason: database.BuildReasonInitiator, + }) + _, err := db.AcquireProvisionerJob(ctx, database.AcquireProvisionerJobParams{ + OrganizationID: pd.OrganizationID, + WorkerID: uuid.NullUUID{ + UUID: pd.ID, + Valid: true, + }, + Types: []database.ProvisionerType{database.ProvisionerTypeEcho}, + ProvisionerTags: must(json.Marshal(job.Tags)), + StartedAt: sql.NullTime{Time: job.CreatedAt, Valid: true}, + }) + require.NoError(t, err) + + _, err = srv.CompleteJob(ctx, &proto.CompletedJob{ + JobId: job.ID.String(), + Type: &proto.CompletedJob_WorkspaceBuild_{ + WorkspaceBuild: &proto.CompletedJob_WorkspaceBuild{ + State: []byte{}, + Resources: []*sdkproto.Resource{ + { + Name: "vm-ok", + Type: "aws_instance", + Agents: []*sdkproto.Agent{{ + Name: "main", + Auth: &sdkproto.Agent_Token{Token: uuid.NewString()}, + Scripts: []*sdkproto.Script{ + {DisplayName: "Clone repo", ResourceAddress: "coder_script.clone_repo"}, + }, + }}, + }, + { + Name: "vm-bad", + Type: "aws_instance", + Agents: []*sdkproto.Agent{{ + Name: "other", + Auth: &sdkproto.Agent_Token{Token: uuid.NewString()}, + Scripts: []*sdkproto.Script{ + { + DisplayName: "Install tools", + ResourceAddress: "coder_script.install_tools", + Dependencies: []*sdkproto.ScriptDependency{{ + PrerequisiteResourceAddress: "coder_script.clone_repo", + // Requirement is left at UNSPECIFIED on purpose. + }}, + }, + }, + }}, + }, + }, + }, + }, + }) + require.ErrorContains(t, err, `script "coder_script.install_tools" dependencies: dependency 0: unsupported requirement`) + + // The first resource was valid, but the whole job rolls back. + resources, err := db.GetWorkspaceResourcesByJobID(ctx, job.ID) + require.NoError(t, err) + require.Empty(t, resources, "the transaction must roll back every row of the job") + }) + t.Run("PrebuiltWorkspaceClaimWithResourceReplacements", func(t *testing.T) { t.Parallel() @@ -3851,10 +3957,26 @@ func TestInsertWorkspaceResource(t *testing.T) { Value: "I laugh in the face of danger.", }, }, - Scripts: []*sdkproto.Script{{ - DisplayName: "Startup", - Icon: "/test.png", - }}, + Scripts: []*sdkproto.Script{ + { + // A legacy inline startup_script has no Terraform + // address of its own. + DisplayName: "Startup", + Icon: "/test.png", + }, + { + DisplayName: "Clone repo", + ResourceAddress: "coder_script.clone_repo", + }, + { + DisplayName: "Install tools", + ResourceAddress: "coder_script.install_tools", + Dependencies: []*sdkproto.ScriptDependency{{ + PrerequisiteResourceAddress: "coder_script.clone_repo", + Requirement: sdkproto.ScriptDependencyRequirement_SCRIPT_DEPENDENCY_REQUIREMENT_SUCCESS, + }}, + }, + }, DisplayApps: &sdkproto.DisplayApps{ Vscode: true, PortForwardingHelper: true, @@ -3887,6 +4009,48 @@ func TestInsertWorkspaceResource(t *testing.T) { database.DisplayAppSSHHelper, database.DisplayAppVscode, }, agent.DisplayApps) + + scripts, err := db.GetWorkspaceAgentScriptsByAgentIDs(ctx, []uuid.UUID{agent.ID}) + require.NoError(t, err) + require.Len(t, scripts, 3) + byName := make(map[string]database.GetWorkspaceAgentScriptsByAgentIDsRow, len(scripts)) + for _, script := range scripts { + byName[script.DisplayName] = script + } + require.Equal(t, "", byName["Startup"].ResourceAddress) + require.JSONEq(t, `[]`, string(byName["Startup"].Dependencies)) + require.Equal(t, "coder_script.clone_repo", byName["Clone repo"].ResourceAddress) + require.JSONEq(t, `[]`, string(byName["Clone repo"].Dependencies)) + require.Equal(t, "coder_script.install_tools", byName["Install tools"].ResourceAddress) + require.JSONEq(t, + `[{"prerequisite_resource_address":"coder_script.clone_repo","requirement":"success"}]`, + string(byName["Install tools"].Dependencies), + ) + }) + + t.Run("RejectsBadDependency", func(t *testing.T) { + t.Parallel() + db, _ := dbtestutil.NewDB(t) + job := dbgen.ProvisionerJob(t, db, nil, database.ProvisionerJob{}) + err := insert(db, job.ID, &sdkproto.Resource{ + Name: "something", + Type: "aws_instance", + Agents: []*sdkproto.Agent{{ + Name: "dev", + Scripts: []*sdkproto.Script{ + {DisplayName: "Clone repo", ResourceAddress: "coder_script.clone_repo"}, + { + DisplayName: "Install tools", + ResourceAddress: "coder_script.install_tools", + Dependencies: []*sdkproto.ScriptDependency{{ + PrerequisiteResourceAddress: "coder_script.clone_repo", + // Requirement is left at UNSPECIFIED on purpose. + }}, + }, + }, + }}, + }) + require.ErrorContains(t, err, `script "coder_script.install_tools" dependencies: dependency 0: unsupported requirement`) }) t.Run("AllDisplayApps", func(t *testing.T) { @@ -4119,6 +4283,89 @@ func TestInsertWorkspaceResource(t *testing.T) { } }, }, + { + name: "SubAgentWithOrderedScripts", + resource: &sdkproto.Resource{ + Name: "something", + Type: "aws_instance", + Agents: []*sdkproto.Agent{{ + Id: agentID.String(), + Name: "dev", + Devcontainers: []*sdkproto.Devcontainer{{ + Id: devcontainerID.String(), + Name: "repo", + WorkspaceFolder: "/workspace", + SubagentId: subAgentID.String(), + Scripts: []*sdkproto.Script{ + {DisplayName: "a", ResourceAddress: "coder_script.a", RunOnStart: true}, + { + DisplayName: "b", + ResourceAddress: "coder_script.b", + RunOnStart: true, + Dependencies: []*sdkproto.ScriptDependency{{ + PrerequisiteResourceAddress: "coder_script.a", + Requirement: sdkproto.ScriptDependencyRequirement_SCRIPT_DEPENDENCY_REQUIREMENT_COMPLETION, + }}, + }, + }, + }}, + }}, + }, + expectSubAgentCount: 1, + check: func(t *testing.T, db database.Store, parentAgent database.WorkspaceAgent, subAgents []database.WorkspaceAgent, _ bool) { + require.Len(t, subAgents, 1) + + // The devcontainer's own scripts live under the subagent. + scripts, err := db.GetWorkspaceAgentScriptsByAgentIDs(ctx, []uuid.UUID{subAgents[0].ID}) + require.NoError(t, err) + require.Len(t, scripts, 2) + byName := make(map[string]database.GetWorkspaceAgentScriptsByAgentIDsRow, len(scripts)) + for _, script := range scripts { + byName[script.DisplayName] = script + } + assert.Equal(t, "coder_script.a", byName["a"].ResourceAddress) + assert.JSONEq(t, `[]`, string(byName["a"].Dependencies)) + assert.Equal(t, "coder_script.b", byName["b"].ResourceAddress) + assert.JSONEq(t, + `[{"prerequisite_resource_address":"coder_script.a","requirement":"completion"}]`, + string(byName["b"].Dependencies), + ) + + // The start script coderd adds to the parent has no + // address and nothing can order it. + parentScripts, err := db.GetWorkspaceAgentScriptsByAgentIDs(ctx, []uuid.UUID{parentAgent.ID}) + require.NoError(t, err) + require.Len(t, parentScripts, 1) + assert.Equal(t, "Dev Container (repo)", parentScripts[0].DisplayName) + assert.Equal(t, "", parentScripts[0].ResourceAddress) + assert.JSONEq(t, `[]`, string(parentScripts[0].Dependencies)) + }, + }, + { + name: "SubAgentRejectsBadDependency", + wantErr: `script "coder_script.b" dependencies: dependency 0: unsupported requirement`, + resource: &sdkproto.Resource{ + Name: "something", + Type: "aws_instance", + Agents: []*sdkproto.Agent{{ + Id: agentID.String(), + Name: "dev", + Devcontainers: []*sdkproto.Devcontainer{{ + Id: devcontainerID.String(), + Name: "repo", + WorkspaceFolder: "/workspace", + SubagentId: subAgentID.String(), + Scripts: []*sdkproto.Script{{ + DisplayName: "b", + ResourceAddress: "coder_script.b", + Dependencies: []*sdkproto.ScriptDependency{{ + PrerequisiteResourceAddress: "coder_script.a", + }}, + }}, + }}, + }}, + }, + }, { name: "MultipleDevcontainersWithSubagents", resource: &sdkproto.Resource{ diff --git a/coderd/provisionerdserver/script_dependencies_internal_test.go b/coderd/provisionerdserver/script_dependencies_internal_test.go new file mode 100644 index 00000000000..d8a91914d2e --- /dev/null +++ b/coderd/provisionerdserver/script_dependencies_internal_test.go @@ -0,0 +1,84 @@ +package provisionerdserver + +import ( + "testing" + + "github.com/stretchr/testify/require" + + sdkproto "github.com/coder/coder/v2/provisionersdk/proto" +) + +func TestScriptDependenciesJSON(t *testing.T) { + t.Parallel() + + cases := []struct { + name string + dependencies []*sdkproto.ScriptDependency + want string + wantErr string + }{ + { + name: "NilIsEmptyArray", + want: `[]`, + }, + { + name: "TwoEntriesKeepOrder", + dependencies: []*sdkproto.ScriptDependency{ + { + PrerequisiteResourceAddress: "coder_script.clone_repo", + Requirement: sdkproto.ScriptDependencyRequirement_SCRIPT_DEPENDENCY_REQUIREMENT_SUCCESS, + }, + { + PrerequisiteResourceAddress: "coder_script.warm_cache", + Requirement: sdkproto.ScriptDependencyRequirement_SCRIPT_DEPENDENCY_REQUIREMENT_COMPLETION, + }, + }, + want: `[{"prerequisite_resource_address":"coder_script.clone_repo","requirement":"success"},` + + `{"prerequisite_resource_address":"coder_script.warm_cache","requirement":"completion"}]`, + }, + { + name: "UnspecifiedRequirement", + dependencies: []*sdkproto.ScriptDependency{{ + PrerequisiteResourceAddress: "coder_script.clone_repo", + Requirement: sdkproto.ScriptDependencyRequirement_SCRIPT_DEPENDENCY_REQUIREMENT_UNSPECIFIED, + }}, + wantErr: "dependency 0: unsupported requirement", + }, + { + name: "UnknownRequirement", + dependencies: []*sdkproto.ScriptDependency{{ + PrerequisiteResourceAddress: "coder_script.clone_repo", + Requirement: sdkproto.ScriptDependencyRequirement(99), + }}, + wantErr: "dependency 0: unsupported requirement", + }, + { + name: "EmptyAddress", + dependencies: []*sdkproto.ScriptDependency{ + { + PrerequisiteResourceAddress: "coder_script.clone_repo", + Requirement: sdkproto.ScriptDependencyRequirement_SCRIPT_DEPENDENCY_REQUIREMENT_SUCCESS, + }, + { + PrerequisiteResourceAddress: "", + Requirement: sdkproto.ScriptDependencyRequirement_SCRIPT_DEPENDENCY_REQUIREMENT_SUCCESS, + }, + }, + wantErr: "dependency 1 has an empty prerequisite resource address", + }, + } + + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + + got, err := scriptDependenciesJSON(tc.dependencies) + if tc.wantErr != "" { + require.ErrorContains(t, err, tc.wantErr) + return + } + require.NoError(t, err) + require.JSONEq(t, tc.want, got) + }) + } +} diff --git a/coderd/provisionerjobs.go b/coderd/provisionerjobs.go index 6d7cb08b2ed..0ad2f9b62ee 100644 --- a/coderd/provisionerjobs.go +++ b/coderd/provisionerjobs.go @@ -328,8 +328,17 @@ func (api *API) provisionerJobResources(rw http.ResponseWriter, r *http.Request, } } + apiScripts, err := convertScripts(dbScripts) + if err != nil { + httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ + Message: "Internal error reading workspace agent scripts.", + Detail: err.Error(), + }) + return + } + apiAgent, err := db2sdk.WorkspaceAgent( - api.DERPMap(), *api.TailnetCoordinator.Load(), agent, convertProvisionedApps(dbApps), convertScripts(dbScripts), convertLogSources(dbLogSources), api.AgentInactiveDisconnectTimeout, + api.DERPMap(), *api.TailnetCoordinator.Load(), agent, convertProvisionedApps(dbApps), apiScripts, convertLogSources(dbLogSources), api.AgentInactiveDisconnectTimeout, api.DeploymentValues.AgentFallbackTroubleshootingURL.String(), ) if err != nil { diff --git a/coderd/workspaceagents.go b/coderd/workspaceagents.go index ed9ef17ef26..0eded90fbb1 100644 --- a/coderd/workspaceagents.go +++ b/coderd/workspaceagents.go @@ -112,8 +112,17 @@ func (api *API) workspaceAgent(rw http.ResponseWriter, r *http.Request) { return } + apiScripts, err := convertScripts(scripts) + if err != nil { + httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ + Message: "Internal error reading workspace agent scripts.", + Detail: err.Error(), + }) + return + } + apiAgent, err := db2sdk.WorkspaceAgent( - api.DERPMap(), *api.TailnetCoordinator.Load(), waws.WorkspaceAgent, db2sdk.Apps(dbApps, statuses, waws.WorkspaceAgent, waws.OwnerUsername, waws.WorkspaceTable), convertScripts(scripts), convertLogSources(logSources), api.AgentInactiveDisconnectTimeout, + api.DERPMap(), *api.TailnetCoordinator.Load(), waws.WorkspaceAgent, db2sdk.Apps(dbApps, statuses, waws.WorkspaceAgent, waws.OwnerUsername, waws.WorkspaceTable), apiScripts, convertLogSources(logSources), api.AgentInactiveDisconnectTimeout, api.DeploymentValues.AgentFallbackTroubleshootingURL.String(), ) if err != nil { @@ -1802,12 +1811,16 @@ func convertLogSources(dbLogSources []database.WorkspaceAgentLogSource) []coders return logSources } -func convertScripts(dbScripts []database.GetWorkspaceAgentScriptsByAgentIDsRow) []codersdk.WorkspaceAgentScript { - scripts := make([]codersdk.WorkspaceAgentScript, 0) - for _, dbScript := range dbScripts { - scripts = append(scripts, db2sdk.WorkspaceAgentScript(dbScript)) +func convertScripts(dbScripts []database.GetWorkspaceAgentScriptsByAgentIDsRow) ([]codersdk.WorkspaceAgentScript, error) { + scripts := make([]codersdk.WorkspaceAgentScript, 0, len(dbScripts)) + for i, dbScript := range dbScripts { + script, err := db2sdk.WorkspaceAgentScript(dbScript) + if err != nil { + return nil, xerrors.Errorf("convert script %d: %w", i, err) + } + scripts = append(scripts, script) } - return scripts + return scripts, nil } // @Summary Watch for workspace agent metadata updates diff --git a/coderd/workspaceagents_test.go b/coderd/workspaceagents_test.go index 3374ce58da4..f2fc7448769 100644 --- a/coderd/workspaceagents_test.go +++ b/coderd/workspaceagents_test.go @@ -97,6 +97,48 @@ func TestWorkspaceAgent(t *testing.T) { require.NoError(t, err) require.False(t, workspace.LatestBuild.Resources[0].Agents[0].Health.Healthy) }) + t.Run("ScriptDependencies", func(t *testing.T) { + t.Parallel() + client, db := coderdtest.NewWithDatabase(t, nil) + user := coderdtest.CreateFirstUser(t, client) + + r := dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{ + OrganizationID: user.OrganizationID, + OwnerID: user.UserID, + }).WithAgent(func(agents []*proto.Agent) []*proto.Agent { + agents[0].Scripts = []*proto.Script{ + {DisplayName: "Clone repo", ResourceAddress: "coder_script.clone_repo"}, + { + DisplayName: "Install tools", + ResourceAddress: "coder_script.install_tools", + Dependencies: []*proto.ScriptDependency{{ + PrerequisiteResourceAddress: "coder_script.clone_repo", + Requirement: proto.ScriptDependencyRequirement_SCRIPT_DEPENDENCY_REQUIREMENT_SUCCESS, + }}, + }, + } + return agents + }).Do() + + ctx := testutil.Context(t, testutil.WaitLong) + workspace, err := client.Workspace(ctx, r.Workspace.ID) + require.NoError(t, err) + agent, err := client.WorkspaceAgent(ctx, workspace.LatestBuild.Resources[0].Agents[0].ID) + require.NoError(t, err) + + require.Len(t, agent.Scripts, 2) + byName := make(map[string]codersdk.WorkspaceAgentScript, len(agent.Scripts)) + for _, script := range agent.Scripts { + byName[script.DisplayName] = script + } + require.Equal(t, "coder_script.clone_repo", byName["Clone repo"].ResourceAddress) + require.Empty(t, byName["Clone repo"].Dependencies) + require.Equal(t, "coder_script.install_tools", byName["Install tools"].ResourceAddress) + require.Equal(t, []codersdk.WorkspaceAgentScriptDependency{{ + PrerequisiteResourceAddress: "coder_script.clone_repo", + Requirement: codersdk.WorkspaceAgentScriptDependencyRequirementSuccess, + }}, byName["Install tools"].Dependencies) + }) t.Run("HasFallbackTroubleshootingURL", func(t *testing.T) { t.Parallel() client, db := coderdtest.NewWithDatabase(t, nil) diff --git a/coderd/workspacebuilds.go b/coderd/workspacebuilds.go index 68212232139..5ee34d1e6de 100644 --- a/coderd/workspacebuilds.go +++ b/coderd/workspacebuilds.go @@ -1551,8 +1551,12 @@ func (api *API) convertWorkspaceBuild( scripts := index.scriptsByAgentID[agent.ID] statuses := index.statusesByAgentID[agent.ID] logSources := index.logSourcesByAgentID[agent.ID] + apiScripts, err := convertScripts(scripts) + if err != nil { + return codersdk.WorkspaceBuild{}, xerrors.Errorf("converting workspace agent scripts: %w", err) + } apiAgent, err := db2sdk.WorkspaceAgent( - api.DERPMap(), *api.TailnetCoordinator.Load(), agent, db2sdk.Apps(apps, statuses, agent, workspace.OwnerUsername, workspace.WorkspaceTable()), convertScripts(scripts), convertLogSources(logSources), api.AgentInactiveDisconnectTimeout, + api.DERPMap(), *api.TailnetCoordinator.Load(), agent, db2sdk.Apps(apps, statuses, agent, workspace.OwnerUsername, workspace.WorkspaceTable()), apiScripts, convertLogSources(logSources), api.AgentInactiveDisconnectTimeout, api.DeploymentValues.AgentFallbackTroubleshootingURL.String(), ) if err != nil { diff --git a/codersdk/workspaceagents.go b/codersdk/workspaceagents.go index 653919c2fc5..d6ed2ae5fdb 100644 --- a/codersdk/workspaceagents.go +++ b/codersdk/workspaceagents.go @@ -201,18 +201,52 @@ const ( ) type WorkspaceAgentScript struct { - ID uuid.UUID `json:"id" format:"uuid"` - LogSourceID uuid.UUID `json:"log_source_id" format:"uuid"` - LogPath string `json:"log_path"` - Script string `json:"script"` - Cron string `json:"cron"` - RunOnStart bool `json:"run_on_start"` - RunOnStop bool `json:"run_on_stop"` - StartBlocksLogin bool `json:"start_blocks_login"` - Timeout time.Duration `json:"timeout"` - DisplayName string `json:"display_name"` - ExitCode *int32 `json:"exit_code,omitempty"` - Status *WorkspaceAgentScriptStatus `json:"status,omitempty"` + ID uuid.UUID `json:"id" format:"uuid"` + LogSourceID uuid.UUID `json:"log_source_id" format:"uuid"` + LogPath string `json:"log_path"` + Script string `json:"script"` + Cron string `json:"cron"` + RunOnStart bool `json:"run_on_start"` + RunOnStop bool `json:"run_on_stop"` + StartBlocksLogin bool `json:"start_blocks_login"` + Timeout time.Duration `json:"timeout"` + DisplayName string `json:"display_name"` + // ResourceAddress is the full Terraform address of the coder_script + // resource, for example "module.git_clone.coder_script.clone". It is + // empty for scripts that are not coder_script resources. + ResourceAddress string `json:"resource_address"` + // Dependencies lists the scripts this one waits for, as the + // provisioner resolved them. It is omitted when empty. + Dependencies []WorkspaceAgentScriptDependency `json:"dependencies,omitempty"` + ExitCode *int32 `json:"exit_code,omitempty"` + Status *WorkspaceAgentScriptStatus `json:"status,omitempty"` +} + +// WorkspaceAgentScriptDependencyRequirement is the outcome a prerequisite +// must reach before the dependent script may run. +type WorkspaceAgentScriptDependencyRequirement string + +const ( + WorkspaceAgentScriptDependencyRequirementSuccess WorkspaceAgentScriptDependencyRequirement = "success" + WorkspaceAgentScriptDependencyRequirementCompletion WorkspaceAgentScriptDependencyRequirement = "completion" +) + +// Valid reports whether the requirement is one of the two supported values. +func (r WorkspaceAgentScriptDependencyRequirement) Valid() bool { + switch r { + case WorkspaceAgentScriptDependencyRequirementSuccess, + WorkspaceAgentScriptDependencyRequirementCompletion: + return true + default: + return false + } +} + +// WorkspaceAgentScriptDependency names a prerequisite script and the +// outcome it must reach. +type WorkspaceAgentScriptDependency struct { + PrerequisiteResourceAddress string `json:"prerequisite_resource_address"` + Requirement WorkspaceAgentScriptDependencyRequirement `json:"requirement"` } type WorkspaceAgentHealth struct { diff --git a/docs/reference/api/agents.md b/docs/reference/api/agents.md index cd6ec5704da..ca8c5f96888 100644 --- a/docs/reference/api/agents.md +++ b/docs/reference/api/agents.md @@ -656,11 +656,18 @@ curl -X GET http://coder-server:8080/api/v2/workspaceagents/{workspaceagent} \ "scripts": [ { "cron": "string", + "dependencies": [ + { + "prerequisite_resource_address": "string", + "requirement": "success" + } + ], "display_name": "string", "exit_code": 0, "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "log_path": "string", "log_source_id": "4197ab25-95cf-4b91-9c78-f7f2af5d353a", + "resource_address": "string", "run_on_start": true, "run_on_stop": true, "script": "string", diff --git a/docs/reference/api/builds.md b/docs/reference/api/builds.md index 9ef98144118..93970fd7427 100644 --- a/docs/reference/api/builds.md +++ b/docs/reference/api/builds.md @@ -199,11 +199,18 @@ curl -X GET http://coder-server:8080/api/v2/users/{user}/workspace/{workspacenam "scripts": [ { "cron": "string", + "dependencies": [ + { + "prerequisite_resource_address": "string", + "requirement": "success" + } + ], "display_name": "string", "exit_code": 0, "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "log_path": "string", "log_source_id": "4197ab25-95cf-4b91-9c78-f7f2af5d353a", + "resource_address": "string", "run_on_start": true, "run_on_stop": true, "script": "string", @@ -455,11 +462,18 @@ curl -X GET http://coder-server:8080/api/v2/workspacebuilds/{workspacebuild} \ "scripts": [ { "cron": "string", + "dependencies": [ + { + "prerequisite_resource_address": "string", + "requirement": "success" + } + ], "display_name": "string", "exit_code": 0, "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "log_path": "string", "log_source_id": "4197ab25-95cf-4b91-9c78-f7f2af5d353a", + "resource_address": "string", "run_on_start": true, "run_on_stop": true, "script": "string", @@ -830,11 +844,18 @@ curl -X GET http://coder-server:8080/api/v2/workspacebuilds/{workspacebuild}/res "scripts": [ { "cron": "string", + "dependencies": [ + { + "prerequisite_resource_address": "string", + "requirement": "success" + } + ], "display_name": "string", "exit_code": 0, "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "log_path": "string", "log_source_id": "4197ab25-95cf-4b91-9c78-f7f2af5d353a", + "resource_address": "string", "run_on_start": true, "run_on_stop": true, "script": "string", @@ -884,121 +905,125 @@ curl -X GET http://coder-server:8080/api/v2/workspacebuilds/{workspacebuild}/res Status Code **200** -| Name | Type | Required | Restrictions | Description | -|---------------------------------|--------------------------------------------------------------------------------------------------------|----------|--------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `[array item]` | array | false | | | -| `» agents` | array | false | | | -| `»» api_version` | string | false | | | -| `»» apps` | array | false | | | -| `»»» command` | string | false | | | -| `»»» display_name` | string | false | | Display name is a friendly name for the app. | -| `»»» external` | boolean | false | | External specifies whether the URL should be opened externally on the client or not. | -| `»»» group` | string | false | | | -| `»»» health` | [codersdk.WorkspaceAppHealth](schemas.md#codersdkworkspaceapphealth) | false | | | -| `»»» healthcheck` | [codersdk.Healthcheck](schemas.md#codersdkhealthcheck) | false | | Healthcheck specifies the configuration for checking app health. | -| `»»»» interval` | integer | false | | Interval specifies the seconds between each health check. | -| `»»»» threshold` | integer | false | | Threshold specifies the number of consecutive failed health checks before returning "unhealthy". | -| `»»»» url` | string | false | | URL specifies the endpoint to check for the app health. | -| `»»» hidden` | boolean | false | | | -| `»»» icon` | string | false | | Icon is a relative path or external URL that specifies an icon to be displayed in the dashboard. | -| `»»» id` | string(uuid) | false | | | -| `»»» open_in` | [codersdk.WorkspaceAppOpenIn](schemas.md#codersdkworkspaceappopenin) | false | | | -| `»»» sharing_level` | [codersdk.WorkspaceAppSharingLevel](schemas.md#codersdkworkspaceappsharinglevel) | false | | | -| `»»» slug` | string | false | | Slug is a unique identifier within the agent. | -| `»»» statuses` | array | false | | Statuses is a list of statuses for the app. | -| `»»»» agent_id` | string(uuid) | false | | | -| `»»»» app_id` | string(uuid) | false | | | -| `»»»» created_at` | string(date-time) | false | | | -| `»»»» icon` | string | false | | Deprecated: This field is unused and will be removed in a future version. Icon is an external URL to an icon that will be rendered in the UI. | -| `»»»» id` | string(uuid) | false | | | -| `»»»» message` | string | false | | | -| `»»»» needs_user_attention` | boolean | false | | Deprecated: This field is unused and will be removed in a future version. NeedsUserAttention specifies whether the status needs user attention. | -| `»»»» state` | [codersdk.WorkspaceAppStatusState](schemas.md#codersdkworkspaceappstatusstate) | false | | | -| `»»»» uri` | string | false | | Uri is the URI of the resource that the status is for. e.g. https://github.com/org/repo/pull/123 e.g. file:///path/to/file | -| `»»»» workspace_id` | string(uuid) | false | | | -| `»»» subdomain` | boolean | false | | Subdomain denotes whether the app should be accessed via a path on the `coder server` or via a hostname-based dev URL. If this is set to true and there is no app wildcard configured on the server, the app will not be accessible in the UI. | -| `»»» subdomain_name` | string | false | | Subdomain name is the application domain exposed on the `coder server`. | -| `»»» tooltip` | string | false | | Tooltip is an optional markdown supported field that is displayed when hovering over workspace apps in the UI. | -| `»»» url` | string | false | | URL is the address being proxied to inside the workspace. If external is specified, this will be opened on the client. | -| `»» architecture` | string | false | | | -| `»» connection_timeout_seconds` | integer | false | | | -| `»» created_at` | string(date-time) | false | | | -| `»» directory` | string | false | | | -| `»» disconnected_at` | string(date-time) | false | | | -| `»» display_apps` | array | false | | | -| `»» environment_variables` | object | false | | | -| `»»» [any property]` | string | false | | | -| `»» expanded_directory` | string | false | | | -| `»» first_connected_at` | string(date-time) | false | | | -| `»» health` | [codersdk.WorkspaceAgentHealth](schemas.md#codersdkworkspaceagenthealth) | false | | Health reports the health of the agent. | -| `»»» healthy` | boolean | false | | Healthy is true if the agent is healthy. | -| `»»» reason` | string | false | | Reason is a human-readable explanation of the agent's health. It is empty if Healthy is true. | -| `»» id` | string(uuid) | false | | | -| `»» instance_id` | string | false | | | -| `»» last_connected_at` | string(date-time) | false | | | -| `»» latency` | object | false | | Latency is mapped by region name (e.g. "New York City", "Seattle"). | -| `»»» [any property]` | [codersdk.DERPRegion](schemas.md#codersdkderpregion) | false | | | -| `»»»» latency_ms` | number | false | | | -| `»»»» preferred` | boolean | false | | | -| `»» lifecycle_state` | [codersdk.WorkspaceAgentLifecycle](schemas.md#codersdkworkspaceagentlifecycle) | false | | | -| `»» log_sources` | array | false | | | -| `»»» created_at` | string(date-time) | false | | | -| `»»» display_name` | string | false | | | -| `»»» icon` | string | false | | | -| `»»» id` | string(uuid) | false | | | -| `»»» workspace_agent_id` | string(uuid) | false | | | -| `»» logs_length` | integer | false | | | -| `»» logs_overflowed` | boolean | false | | | -| `»» metadata` | array | false | | Metadata is only populated on the workspaces list endpoint when the request opts in with the include_agent_metadata search key, and it only carries the requested keys. The description's script is always empty here: it can be long, and list consumers want values. | -| `»»» description` | [codersdk.WorkspaceAgentMetadataDescription](schemas.md#codersdkworkspaceagentmetadatadescription) | false | | | -| `»»»» display_name` | string | false | | | -| `»»»» interval` | integer | false | | | -| `»»»» key` | string | false | | | -| `»»»» script` | string | false | | | -| `»»»» timeout` | integer | false | | | -| `»»» result` | [codersdk.WorkspaceAgentMetadataResult](schemas.md#codersdkworkspaceagentmetadataresult) | false | | | -| `»»»» age` | integer | false | | Age is the number of seconds since the metadata was collected. It is provided in addition to CollectedAt to protect against clock skew. | -| `»»»» collected_at` | string(date-time) | false | | | -| `»»»» error` | string | false | | | -| `»»»» value` | string | false | | | -| `»» name` | string | false | | | -| `»» operating_system` | string | false | | | -| `»» parent_id` | string(uuid) | false | | | -| `»» ready_at` | string(date-time) | false | | | -| `»» resource_id` | string(uuid) | false | | | -| `»» scripts` | array | false | | | -| `»»» cron` | string | false | | | -| `»»» display_name` | string | false | | | -| `»»» exit_code` | integer | false | | | -| `»»» id` | string(uuid) | false | | | -| `»»» log_path` | string | false | | | -| `»»» log_source_id` | string(uuid) | false | | | -| `»»» run_on_start` | boolean | false | | | -| `»»» run_on_stop` | boolean | false | | | -| `»»» script` | string | false | | | -| `»»» start_blocks_login` | boolean | false | | | -| `»»» status` | [codersdk.WorkspaceAgentScriptStatus](schemas.md#codersdkworkspaceagentscriptstatus) | false | | | -| `»»» timeout` | integer | false | | | -| `»» started_at` | string(date-time) | false | | | -| `»» startup_script_behavior` | [codersdk.WorkspaceAgentStartupScriptBehavior](schemas.md#codersdkworkspaceagentstartupscriptbehavior) | false | | Startup script behavior is a legacy field that is deprecated in favor of the `coder_script` resource. It's only referenced by old clients. Deprecated: Remove in the future! | -| `»» status` | [codersdk.WorkspaceAgentStatus](schemas.md#codersdkworkspaceagentstatus) | false | | | -| `»» subsystems` | array | false | | | -| `»» troubleshooting_url` | string | false | | | -| `»» updated_at` | string(date-time) | false | | | -| `»» version` | string | false | | | -| `» created_at` | string(date-time) | false | | | -| `» daily_cost` | integer | false | | | -| `» hide` | boolean | false | | | -| `» icon` | string | false | | | -| `» id` | string(uuid) | false | | | -| `» job_id` | string(uuid) | false | | | -| `» metadata` | array | false | | | -| `»» key` | string | false | | | -| `»» sensitive` | boolean | false | | | -| `»» value` | string | false | | | -| `» name` | string | false | | | -| `» type` | string | false | | | -| `» workspace_transition` | [codersdk.WorkspaceTransition](schemas.md#codersdkworkspacetransition) | false | | | +| Name | Type | Required | Restrictions | Description | +|--------------------------------------|--------------------------------------------------------------------------------------------------------------------|----------|--------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `[array item]` | array | false | | | +| `» agents` | array | false | | | +| `»» api_version` | string | false | | | +| `»» apps` | array | false | | | +| `»»» command` | string | false | | | +| `»»» display_name` | string | false | | Display name is a friendly name for the app. | +| `»»» external` | boolean | false | | External specifies whether the URL should be opened externally on the client or not. | +| `»»» group` | string | false | | | +| `»»» health` | [codersdk.WorkspaceAppHealth](schemas.md#codersdkworkspaceapphealth) | false | | | +| `»»» healthcheck` | [codersdk.Healthcheck](schemas.md#codersdkhealthcheck) | false | | Healthcheck specifies the configuration for checking app health. | +| `»»»» interval` | integer | false | | Interval specifies the seconds between each health check. | +| `»»»» threshold` | integer | false | | Threshold specifies the number of consecutive failed health checks before returning "unhealthy". | +| `»»»» url` | string | false | | URL specifies the endpoint to check for the app health. | +| `»»» hidden` | boolean | false | | | +| `»»» icon` | string | false | | Icon is a relative path or external URL that specifies an icon to be displayed in the dashboard. | +| `»»» id` | string(uuid) | false | | | +| `»»» open_in` | [codersdk.WorkspaceAppOpenIn](schemas.md#codersdkworkspaceappopenin) | false | | | +| `»»» sharing_level` | [codersdk.WorkspaceAppSharingLevel](schemas.md#codersdkworkspaceappsharinglevel) | false | | | +| `»»» slug` | string | false | | Slug is a unique identifier within the agent. | +| `»»» statuses` | array | false | | Statuses is a list of statuses for the app. | +| `»»»» agent_id` | string(uuid) | false | | | +| `»»»» app_id` | string(uuid) | false | | | +| `»»»» created_at` | string(date-time) | false | | | +| `»»»» icon` | string | false | | Deprecated: This field is unused and will be removed in a future version. Icon is an external URL to an icon that will be rendered in the UI. | +| `»»»» id` | string(uuid) | false | | | +| `»»»» message` | string | false | | | +| `»»»» needs_user_attention` | boolean | false | | Deprecated: This field is unused and will be removed in a future version. NeedsUserAttention specifies whether the status needs user attention. | +| `»»»» state` | [codersdk.WorkspaceAppStatusState](schemas.md#codersdkworkspaceappstatusstate) | false | | | +| `»»»» uri` | string | false | | Uri is the URI of the resource that the status is for. e.g. https://github.com/org/repo/pull/123 e.g. file:///path/to/file | +| `»»»» workspace_id` | string(uuid) | false | | | +| `»»» subdomain` | boolean | false | | Subdomain denotes whether the app should be accessed via a path on the `coder server` or via a hostname-based dev URL. If this is set to true and there is no app wildcard configured on the server, the app will not be accessible in the UI. | +| `»»» subdomain_name` | string | false | | Subdomain name is the application domain exposed on the `coder server`. | +| `»»» tooltip` | string | false | | Tooltip is an optional markdown supported field that is displayed when hovering over workspace apps in the UI. | +| `»»» url` | string | false | | URL is the address being proxied to inside the workspace. If external is specified, this will be opened on the client. | +| `»» architecture` | string | false | | | +| `»» connection_timeout_seconds` | integer | false | | | +| `»» created_at` | string(date-time) | false | | | +| `»» directory` | string | false | | | +| `»» disconnected_at` | string(date-time) | false | | | +| `»» display_apps` | array | false | | | +| `»» environment_variables` | object | false | | | +| `»»» [any property]` | string | false | | | +| `»» expanded_directory` | string | false | | | +| `»» first_connected_at` | string(date-time) | false | | | +| `»» health` | [codersdk.WorkspaceAgentHealth](schemas.md#codersdkworkspaceagenthealth) | false | | Health reports the health of the agent. | +| `»»» healthy` | boolean | false | | Healthy is true if the agent is healthy. | +| `»»» reason` | string | false | | Reason is a human-readable explanation of the agent's health. It is empty if Healthy is true. | +| `»» id` | string(uuid) | false | | | +| `»» instance_id` | string | false | | | +| `»» last_connected_at` | string(date-time) | false | | | +| `»» latency` | object | false | | Latency is mapped by region name (e.g. "New York City", "Seattle"). | +| `»»» [any property]` | [codersdk.DERPRegion](schemas.md#codersdkderpregion) | false | | | +| `»»»» latency_ms` | number | false | | | +| `»»»» preferred` | boolean | false | | | +| `»» lifecycle_state` | [codersdk.WorkspaceAgentLifecycle](schemas.md#codersdkworkspaceagentlifecycle) | false | | | +| `»» log_sources` | array | false | | | +| `»»» created_at` | string(date-time) | false | | | +| `»»» display_name` | string | false | | | +| `»»» icon` | string | false | | | +| `»»» id` | string(uuid) | false | | | +| `»»» workspace_agent_id` | string(uuid) | false | | | +| `»» logs_length` | integer | false | | | +| `»» logs_overflowed` | boolean | false | | | +| `»» metadata` | array | false | | Metadata is only populated on the workspaces list endpoint when the request opts in with the include_agent_metadata search key, and it only carries the requested keys. The description's script is always empty here: it can be long, and list consumers want values. | +| `»»» description` | [codersdk.WorkspaceAgentMetadataDescription](schemas.md#codersdkworkspaceagentmetadatadescription) | false | | | +| `»»»» display_name` | string | false | | | +| `»»»» interval` | integer | false | | | +| `»»»» key` | string | false | | | +| `»»»» script` | string | false | | | +| `»»»» timeout` | integer | false | | | +| `»»» result` | [codersdk.WorkspaceAgentMetadataResult](schemas.md#codersdkworkspaceagentmetadataresult) | false | | | +| `»»»» age` | integer | false | | Age is the number of seconds since the metadata was collected. It is provided in addition to CollectedAt to protect against clock skew. | +| `»»»» collected_at` | string(date-time) | false | | | +| `»»»» error` | string | false | | | +| `»»»» value` | string | false | | | +| `»» name` | string | false | | | +| `»» operating_system` | string | false | | | +| `»» parent_id` | string(uuid) | false | | | +| `»» ready_at` | string(date-time) | false | | | +| `»» resource_id` | string(uuid) | false | | | +| `»» scripts` | array | false | | | +| `»»» cron` | string | false | | | +| `»»» dependencies` | array | false | | Dependencies lists the scripts this one waits for, as the provisioner resolved them. It is omitted when empty. | +| `»»»» prerequisite_resource_address` | string | false | | | +| `»»»» requirement` | [codersdk.WorkspaceAgentScriptDependencyRequirement](schemas.md#codersdkworkspaceagentscriptdependencyrequirement) | false | | | +| `»»» display_name` | string | false | | | +| `»»» exit_code` | integer | false | | | +| `»»» id` | string(uuid) | false | | | +| `»»» log_path` | string | false | | | +| `»»» log_source_id` | string(uuid) | false | | | +| `»»» resource_address` | string | false | | Resource address is the full Terraform address of the coder_script resource, for example "module.git_clone.coder_script.clone". It is empty for scripts that are not coder_script resources. | +| `»»» run_on_start` | boolean | false | | | +| `»»» run_on_stop` | boolean | false | | | +| `»»» script` | string | false | | | +| `»»» start_blocks_login` | boolean | false | | | +| `»»» status` | [codersdk.WorkspaceAgentScriptStatus](schemas.md#codersdkworkspaceagentscriptstatus) | false | | | +| `»»» timeout` | integer | false | | | +| `»» started_at` | string(date-time) | false | | | +| `»» startup_script_behavior` | [codersdk.WorkspaceAgentStartupScriptBehavior](schemas.md#codersdkworkspaceagentstartupscriptbehavior) | false | | Startup script behavior is a legacy field that is deprecated in favor of the `coder_script` resource. It's only referenced by old clients. Deprecated: Remove in the future! | +| `»» status` | [codersdk.WorkspaceAgentStatus](schemas.md#codersdkworkspaceagentstatus) | false | | | +| `»» subsystems` | array | false | | | +| `»» troubleshooting_url` | string | false | | | +| `»» updated_at` | string(date-time) | false | | | +| `»» version` | string | false | | | +| `» created_at` | string(date-time) | false | | | +| `» daily_cost` | integer | false | | | +| `» hide` | boolean | false | | | +| `» icon` | string | false | | | +| `» id` | string(uuid) | false | | | +| `» job_id` | string(uuid) | false | | | +| `» metadata` | array | false | | | +| `»» key` | string | false | | | +| `»» sensitive` | boolean | false | | | +| `»» value` | string | false | | | +| `» name` | string | false | | | +| `» type` | string | false | | | +| `» workspace_transition` | [codersdk.WorkspaceTransition](schemas.md#codersdkworkspacetransition) | false | | | #### Enumerated Values @@ -1009,6 +1034,7 @@ Status Code **200** | `sharing_level` | `authenticated`, `organization`, `owner`, `public` | | `state` | `complete`, `failure`, `idle`, `working` | | `lifecycle_state` | `created`, `off`, `ready`, `shutdown_error`, `shutdown_timeout`, `shutting_down`, `start_error`, `start_timeout`, `starting` | +| `requirement` | `completion`, `success` | | `status` | `connected`, `connecting`, `disconnected`, `exit_failure`, `ok`, `pipes_left_open`, `timed_out`, `timeout` | | `startup_script_behavior` | `blocking`, `non-blocking` | | `workspace_transition` | `delete`, `start`, `stop` | @@ -1207,11 +1233,18 @@ curl -X GET http://coder-server:8080/api/v2/workspacebuilds/{workspacebuild}/sta "scripts": [ { "cron": "string", + "dependencies": [ + { + "prerequisite_resource_address": "string", + "requirement": "success" + } + ], "display_name": "string", "exit_code": 0, "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "log_path": "string", "log_source_id": "4197ab25-95cf-4b91-9c78-f7f2af5d353a", + "resource_address": "string", "run_on_start": true, "run_on_stop": true, "script": "string", @@ -1574,11 +1607,18 @@ curl -X GET http://coder-server:8080/api/v2/workspaces/{workspace}/builds \ "scripts": [ { "cron": "string", + "dependencies": [ + { + "prerequisite_resource_address": "string", + "requirement": "success" + } + ], "display_name": "string", "exit_code": 0, "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "log_path": "string", "log_source_id": "4197ab25-95cf-4b91-9c78-f7f2af5d353a", + "resource_address": "string", "run_on_start": true, "run_on_stop": true, "script": "string", @@ -1641,181 +1681,185 @@ curl -X GET http://coder-server:8080/api/v2/workspaces/{workspace}/builds \ Status Code **200** -| Name | Type | Required | Restrictions | Description | -|----------------------------------|--------------------------------------------------------------------------------------------------------|----------|--------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `[array item]` | array | false | | | -| `» build_number` | integer | false | | | -| `» created_at` | string(date-time) | false | | | -| `» daily_cost` | integer | false | | | -| `» deadline` | string(date-time) | false | | | -| `» has_external_agent` | boolean | false | | | -| `» id` | string(uuid) | false | | | -| `» initiator_id` | string(uuid) | false | | | -| `» initiator_name` | string | false | | | -| `» job` | [codersdk.ProvisionerJob](schemas.md#codersdkprovisionerjob) | false | | | -| `»» available_workers` | array | false | | | -| `»» canceled_at` | string(date-time) | false | | | -| `»» completed_at` | string(date-time) | false | | | -| `»» created_at` | string(date-time) | false | | | -| `»» error` | string | false | | | -| `»» error_code` | [codersdk.JobErrorCode](schemas.md#codersdkjoberrorcode) | false | | | -| `»» file_id` | string(uuid) | false | | | -| `»» id` | string(uuid) | false | | | -| `»» initiator_id` | string(uuid) | false | | | -| `»» input` | [codersdk.ProvisionerJobInput](schemas.md#codersdkprovisionerjobinput) | false | | | -| `»»» error` | string | false | | | -| `»»» template_version_id` | string(uuid) | false | | | -| `»»» workspace_build_id` | string(uuid) | false | | | -| `»» logs_overflowed` | boolean | false | | | -| `»» metadata` | [codersdk.ProvisionerJobMetadata](schemas.md#codersdkprovisionerjobmetadata) | false | | | -| `»»» template_display_name` | string | false | | | -| `»»» template_icon` | string | false | | | -| `»»» template_id` | string(uuid) | false | | | -| `»»» template_name` | string | false | | | -| `»»» template_version_name` | string | false | | | -| `»»» workspace_build_transition` | [codersdk.WorkspaceTransition](schemas.md#codersdkworkspacetransition) | false | | | -| `»»» workspace_id` | string(uuid) | false | | | -| `»»» workspace_name` | string | false | | | -| `»» organization_id` | string(uuid) | false | | | -| `»» queue_position` | integer | false | | | -| `»» queue_size` | integer | false | | | -| `»» started_at` | string(date-time) | false | | | -| `»» status` | [codersdk.ProvisionerJobStatus](schemas.md#codersdkprovisionerjobstatus) | false | | | -| `»» tags` | object | false | | | -| `»»» [any property]` | string | false | | | -| `»» type` | [codersdk.ProvisionerJobType](schemas.md#codersdkprovisionerjobtype) | false | | | -| `»» worker_id` | string(uuid) | false | | | -| `»» worker_name` | string | false | | | -| `» matched_provisioners` | [codersdk.MatchedProvisioners](schemas.md#codersdkmatchedprovisioners) | false | | | -| `»» available` | integer | false | | Available is the number of provisioner daemons that are available to take jobs. This may be less than the count if some provisioners are busy or have been stopped. | -| `»» count` | integer | false | | Count is the number of provisioner daemons that matched the given tags. If the count is 0, it means no provisioner daemons matched the requested tags. | -| `»» most_recently_seen` | string(date-time) | false | | Most recently seen is the most recently seen time of the set of matched provisioners. If no provisioners matched, this field will be null. | -| `» max_deadline` | string(date-time) | false | | | -| `» reason` | [codersdk.BuildReason](schemas.md#codersdkbuildreason) | false | | | -| `» resources` | array | false | | | -| `»» agents` | array | false | | | -| `»»» api_version` | string | false | | | -| `»»» apps` | array | false | | | -| `»»»» command` | string | false | | | -| `»»»» display_name` | string | false | | Display name is a friendly name for the app. | -| `»»»» external` | boolean | false | | External specifies whether the URL should be opened externally on the client or not. | -| `»»»» group` | string | false | | | -| `»»»» health` | [codersdk.WorkspaceAppHealth](schemas.md#codersdkworkspaceapphealth) | false | | | -| `»»»» healthcheck` | [codersdk.Healthcheck](schemas.md#codersdkhealthcheck) | false | | Healthcheck specifies the configuration for checking app health. | -| `»»»»» interval` | integer | false | | Interval specifies the seconds between each health check. | -| `»»»»» threshold` | integer | false | | Threshold specifies the number of consecutive failed health checks before returning "unhealthy". | -| `»»»»» url` | string | false | | URL specifies the endpoint to check for the app health. | -| `»»»» hidden` | boolean | false | | | -| `»»»» icon` | string | false | | Icon is a relative path or external URL that specifies an icon to be displayed in the dashboard. | -| `»»»» id` | string(uuid) | false | | | -| `»»»» open_in` | [codersdk.WorkspaceAppOpenIn](schemas.md#codersdkworkspaceappopenin) | false | | | -| `»»»» sharing_level` | [codersdk.WorkspaceAppSharingLevel](schemas.md#codersdkworkspaceappsharinglevel) | false | | | -| `»»»» slug` | string | false | | Slug is a unique identifier within the agent. | -| `»»»» statuses` | array | false | | Statuses is a list of statuses for the app. | -| `»»»»» agent_id` | string(uuid) | false | | | -| `»»»»» app_id` | string(uuid) | false | | | -| `»»»»» created_at` | string(date-time) | false | | | -| `»»»»» icon` | string | false | | Deprecated: This field is unused and will be removed in a future version. Icon is an external URL to an icon that will be rendered in the UI. | -| `»»»»» id` | string(uuid) | false | | | -| `»»»»» message` | string | false | | | -| `»»»»» needs_user_attention` | boolean | false | | Deprecated: This field is unused and will be removed in a future version. NeedsUserAttention specifies whether the status needs user attention. | -| `»»»»» state` | [codersdk.WorkspaceAppStatusState](schemas.md#codersdkworkspaceappstatusstate) | false | | | -| `»»»»» uri` | string | false | | Uri is the URI of the resource that the status is for. e.g. https://github.com/org/repo/pull/123 e.g. file:///path/to/file | -| `»»»»» workspace_id` | string(uuid) | false | | | -| `»»»» subdomain` | boolean | false | | Subdomain denotes whether the app should be accessed via a path on the `coder server` or via a hostname-based dev URL. If this is set to true and there is no app wildcard configured on the server, the app will not be accessible in the UI. | -| `»»»» subdomain_name` | string | false | | Subdomain name is the application domain exposed on the `coder server`. | -| `»»»» tooltip` | string | false | | Tooltip is an optional markdown supported field that is displayed when hovering over workspace apps in the UI. | -| `»»»» url` | string | false | | URL is the address being proxied to inside the workspace. If external is specified, this will be opened on the client. | -| `»»» architecture` | string | false | | | -| `»»» connection_timeout_seconds` | integer | false | | | -| `»»» created_at` | string(date-time) | false | | | -| `»»» directory` | string | false | | | -| `»»» disconnected_at` | string(date-time) | false | | | -| `»»» display_apps` | array | false | | | -| `»»» environment_variables` | object | false | | | -| `»»»» [any property]` | string | false | | | -| `»»» expanded_directory` | string | false | | | -| `»»» first_connected_at` | string(date-time) | false | | | -| `»»» health` | [codersdk.WorkspaceAgentHealth](schemas.md#codersdkworkspaceagenthealth) | false | | Health reports the health of the agent. | -| `»»»» healthy` | boolean | false | | Healthy is true if the agent is healthy. | -| `»»»» reason` | string | false | | Reason is a human-readable explanation of the agent's health. It is empty if Healthy is true. | -| `»»» id` | string(uuid) | false | | | -| `»»» instance_id` | string | false | | | -| `»»» last_connected_at` | string(date-time) | false | | | -| `»»» latency` | object | false | | Latency is mapped by region name (e.g. "New York City", "Seattle"). | -| `»»»» [any property]` | [codersdk.DERPRegion](schemas.md#codersdkderpregion) | false | | | -| `»»»»» latency_ms` | number | false | | | -| `»»»»» preferred` | boolean | false | | | -| `»»» lifecycle_state` | [codersdk.WorkspaceAgentLifecycle](schemas.md#codersdkworkspaceagentlifecycle) | false | | | -| `»»» log_sources` | array | false | | | -| `»»»» created_at` | string(date-time) | false | | | -| `»»»» display_name` | string | false | | | -| `»»»» icon` | string | false | | | -| `»»»» id` | string(uuid) | false | | | -| `»»»» workspace_agent_id` | string(uuid) | false | | | -| `»»» logs_length` | integer | false | | | -| `»»» logs_overflowed` | boolean | false | | | -| `»»» metadata` | array | false | | Metadata is only populated on the workspaces list endpoint when the request opts in with the include_agent_metadata search key, and it only carries the requested keys. The description's script is always empty here: it can be long, and list consumers want values. | -| `»»»» description` | [codersdk.WorkspaceAgentMetadataDescription](schemas.md#codersdkworkspaceagentmetadatadescription) | false | | | -| `»»»»» display_name` | string | false | | | -| `»»»»» interval` | integer | false | | | -| `»»»»» key` | string | false | | | -| `»»»»» script` | string | false | | | -| `»»»»» timeout` | integer | false | | | -| `»»»» result` | [codersdk.WorkspaceAgentMetadataResult](schemas.md#codersdkworkspaceagentmetadataresult) | false | | | -| `»»»»» age` | integer | false | | Age is the number of seconds since the metadata was collected. It is provided in addition to CollectedAt to protect against clock skew. | -| `»»»»» collected_at` | string(date-time) | false | | | -| `»»»»» error` | string | false | | | -| `»»»»» value` | string | false | | | -| `»»» name` | string | false | | | -| `»»» operating_system` | string | false | | | -| `»»» parent_id` | string(uuid) | false | | | -| `»»» ready_at` | string(date-time) | false | | | -| `»»» resource_id` | string(uuid) | false | | | -| `»»» scripts` | array | false | | | -| `»»»» cron` | string | false | | | -| `»»»» display_name` | string | false | | | -| `»»»» exit_code` | integer | false | | | -| `»»»» id` | string(uuid) | false | | | -| `»»»» log_path` | string | false | | | -| `»»»» log_source_id` | string(uuid) | false | | | -| `»»»» run_on_start` | boolean | false | | | -| `»»»» run_on_stop` | boolean | false | | | -| `»»»» script` | string | false | | | -| `»»»» start_blocks_login` | boolean | false | | | -| `»»»» status` | [codersdk.WorkspaceAgentScriptStatus](schemas.md#codersdkworkspaceagentscriptstatus) | false | | | -| `»»»» timeout` | integer | false | | | -| `»»» started_at` | string(date-time) | false | | | -| `»»» startup_script_behavior` | [codersdk.WorkspaceAgentStartupScriptBehavior](schemas.md#codersdkworkspaceagentstartupscriptbehavior) | false | | Startup script behavior is a legacy field that is deprecated in favor of the `coder_script` resource. It's only referenced by old clients. Deprecated: Remove in the future! | -| `»»» status` | [codersdk.WorkspaceAgentStatus](schemas.md#codersdkworkspaceagentstatus) | false | | | -| `»»» subsystems` | array | false | | | -| `»»» troubleshooting_url` | string | false | | | -| `»»» updated_at` | string(date-time) | false | | | -| `»»» version` | string | false | | | -| `»» created_at` | string(date-time) | false | | | -| `»» daily_cost` | integer | false | | | -| `»» hide` | boolean | false | | | -| `»» icon` | string | false | | | -| `»» id` | string(uuid) | false | | | -| `»» job_id` | string(uuid) | false | | | -| `»» metadata` | array | false | | | -| `»»» key` | string | false | | | -| `»»» sensitive` | boolean | false | | | -| `»»» value` | string | false | | | -| `»» name` | string | false | | | -| `»» type` | string | false | | | -| `»» workspace_transition` | [codersdk.WorkspaceTransition](schemas.md#codersdkworkspacetransition) | false | | | -| `» status` | [codersdk.WorkspaceStatus](schemas.md#codersdkworkspacestatus) | false | | | -| `» template_version_id` | string(uuid) | false | | | -| `» template_version_name` | string | false | | | -| `» template_version_preset_id` | string(uuid) | false | | | -| `» transition` | [codersdk.WorkspaceTransition](schemas.md#codersdkworkspacetransition) | false | | | -| `» updated_at` | string(date-time) | false | | | -| `» workspace_id` | string(uuid) | false | | | -| `» workspace_name` | string | false | | | -| `» workspace_owner_avatar_url` | string | false | | | -| `» workspace_owner_id` | string(uuid) | false | | | -| `» workspace_owner_name` | string | false | | Workspace owner name is the username of the owner of the workspace. | +| Name | Type | Required | Restrictions | Description | +|---------------------------------------|--------------------------------------------------------------------------------------------------------------------|----------|--------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `[array item]` | array | false | | | +| `» build_number` | integer | false | | | +| `» created_at` | string(date-time) | false | | | +| `» daily_cost` | integer | false | | | +| `» deadline` | string(date-time) | false | | | +| `» has_external_agent` | boolean | false | | | +| `» id` | string(uuid) | false | | | +| `» initiator_id` | string(uuid) | false | | | +| `» initiator_name` | string | false | | | +| `» job` | [codersdk.ProvisionerJob](schemas.md#codersdkprovisionerjob) | false | | | +| `»» available_workers` | array | false | | | +| `»» canceled_at` | string(date-time) | false | | | +| `»» completed_at` | string(date-time) | false | | | +| `»» created_at` | string(date-time) | false | | | +| `»» error` | string | false | | | +| `»» error_code` | [codersdk.JobErrorCode](schemas.md#codersdkjoberrorcode) | false | | | +| `»» file_id` | string(uuid) | false | | | +| `»» id` | string(uuid) | false | | | +| `»» initiator_id` | string(uuid) | false | | | +| `»» input` | [codersdk.ProvisionerJobInput](schemas.md#codersdkprovisionerjobinput) | false | | | +| `»»» error` | string | false | | | +| `»»» template_version_id` | string(uuid) | false | | | +| `»»» workspace_build_id` | string(uuid) | false | | | +| `»» logs_overflowed` | boolean | false | | | +| `»» metadata` | [codersdk.ProvisionerJobMetadata](schemas.md#codersdkprovisionerjobmetadata) | false | | | +| `»»» template_display_name` | string | false | | | +| `»»» template_icon` | string | false | | | +| `»»» template_id` | string(uuid) | false | | | +| `»»» template_name` | string | false | | | +| `»»» template_version_name` | string | false | | | +| `»»» workspace_build_transition` | [codersdk.WorkspaceTransition](schemas.md#codersdkworkspacetransition) | false | | | +| `»»» workspace_id` | string(uuid) | false | | | +| `»»» workspace_name` | string | false | | | +| `»» organization_id` | string(uuid) | false | | | +| `»» queue_position` | integer | false | | | +| `»» queue_size` | integer | false | | | +| `»» started_at` | string(date-time) | false | | | +| `»» status` | [codersdk.ProvisionerJobStatus](schemas.md#codersdkprovisionerjobstatus) | false | | | +| `»» tags` | object | false | | | +| `»»» [any property]` | string | false | | | +| `»» type` | [codersdk.ProvisionerJobType](schemas.md#codersdkprovisionerjobtype) | false | | | +| `»» worker_id` | string(uuid) | false | | | +| `»» worker_name` | string | false | | | +| `» matched_provisioners` | [codersdk.MatchedProvisioners](schemas.md#codersdkmatchedprovisioners) | false | | | +| `»» available` | integer | false | | Available is the number of provisioner daemons that are available to take jobs. This may be less than the count if some provisioners are busy or have been stopped. | +| `»» count` | integer | false | | Count is the number of provisioner daemons that matched the given tags. If the count is 0, it means no provisioner daemons matched the requested tags. | +| `»» most_recently_seen` | string(date-time) | false | | Most recently seen is the most recently seen time of the set of matched provisioners. If no provisioners matched, this field will be null. | +| `» max_deadline` | string(date-time) | false | | | +| `» reason` | [codersdk.BuildReason](schemas.md#codersdkbuildreason) | false | | | +| `» resources` | array | false | | | +| `»» agents` | array | false | | | +| `»»» api_version` | string | false | | | +| `»»» apps` | array | false | | | +| `»»»» command` | string | false | | | +| `»»»» display_name` | string | false | | Display name is a friendly name for the app. | +| `»»»» external` | boolean | false | | External specifies whether the URL should be opened externally on the client or not. | +| `»»»» group` | string | false | | | +| `»»»» health` | [codersdk.WorkspaceAppHealth](schemas.md#codersdkworkspaceapphealth) | false | | | +| `»»»» healthcheck` | [codersdk.Healthcheck](schemas.md#codersdkhealthcheck) | false | | Healthcheck specifies the configuration for checking app health. | +| `»»»»» interval` | integer | false | | Interval specifies the seconds between each health check. | +| `»»»»» threshold` | integer | false | | Threshold specifies the number of consecutive failed health checks before returning "unhealthy". | +| `»»»»» url` | string | false | | URL specifies the endpoint to check for the app health. | +| `»»»» hidden` | boolean | false | | | +| `»»»» icon` | string | false | | Icon is a relative path or external URL that specifies an icon to be displayed in the dashboard. | +| `»»»» id` | string(uuid) | false | | | +| `»»»» open_in` | [codersdk.WorkspaceAppOpenIn](schemas.md#codersdkworkspaceappopenin) | false | | | +| `»»»» sharing_level` | [codersdk.WorkspaceAppSharingLevel](schemas.md#codersdkworkspaceappsharinglevel) | false | | | +| `»»»» slug` | string | false | | Slug is a unique identifier within the agent. | +| `»»»» statuses` | array | false | | Statuses is a list of statuses for the app. | +| `»»»»» agent_id` | string(uuid) | false | | | +| `»»»»» app_id` | string(uuid) | false | | | +| `»»»»» created_at` | string(date-time) | false | | | +| `»»»»» icon` | string | false | | Deprecated: This field is unused and will be removed in a future version. Icon is an external URL to an icon that will be rendered in the UI. | +| `»»»»» id` | string(uuid) | false | | | +| `»»»»» message` | string | false | | | +| `»»»»» needs_user_attention` | boolean | false | | Deprecated: This field is unused and will be removed in a future version. NeedsUserAttention specifies whether the status needs user attention. | +| `»»»»» state` | [codersdk.WorkspaceAppStatusState](schemas.md#codersdkworkspaceappstatusstate) | false | | | +| `»»»»» uri` | string | false | | Uri is the URI of the resource that the status is for. e.g. https://github.com/org/repo/pull/123 e.g. file:///path/to/file | +| `»»»»» workspace_id` | string(uuid) | false | | | +| `»»»» subdomain` | boolean | false | | Subdomain denotes whether the app should be accessed via a path on the `coder server` or via a hostname-based dev URL. If this is set to true and there is no app wildcard configured on the server, the app will not be accessible in the UI. | +| `»»»» subdomain_name` | string | false | | Subdomain name is the application domain exposed on the `coder server`. | +| `»»»» tooltip` | string | false | | Tooltip is an optional markdown supported field that is displayed when hovering over workspace apps in the UI. | +| `»»»» url` | string | false | | URL is the address being proxied to inside the workspace. If external is specified, this will be opened on the client. | +| `»»» architecture` | string | false | | | +| `»»» connection_timeout_seconds` | integer | false | | | +| `»»» created_at` | string(date-time) | false | | | +| `»»» directory` | string | false | | | +| `»»» disconnected_at` | string(date-time) | false | | | +| `»»» display_apps` | array | false | | | +| `»»» environment_variables` | object | false | | | +| `»»»» [any property]` | string | false | | | +| `»»» expanded_directory` | string | false | | | +| `»»» first_connected_at` | string(date-time) | false | | | +| `»»» health` | [codersdk.WorkspaceAgentHealth](schemas.md#codersdkworkspaceagenthealth) | false | | Health reports the health of the agent. | +| `»»»» healthy` | boolean | false | | Healthy is true if the agent is healthy. | +| `»»»» reason` | string | false | | Reason is a human-readable explanation of the agent's health. It is empty if Healthy is true. | +| `»»» id` | string(uuid) | false | | | +| `»»» instance_id` | string | false | | | +| `»»» last_connected_at` | string(date-time) | false | | | +| `»»» latency` | object | false | | Latency is mapped by region name (e.g. "New York City", "Seattle"). | +| `»»»» [any property]` | [codersdk.DERPRegion](schemas.md#codersdkderpregion) | false | | | +| `»»»»» latency_ms` | number | false | | | +| `»»»»» preferred` | boolean | false | | | +| `»»» lifecycle_state` | [codersdk.WorkspaceAgentLifecycle](schemas.md#codersdkworkspaceagentlifecycle) | false | | | +| `»»» log_sources` | array | false | | | +| `»»»» created_at` | string(date-time) | false | | | +| `»»»» display_name` | string | false | | | +| `»»»» icon` | string | false | | | +| `»»»» id` | string(uuid) | false | | | +| `»»»» workspace_agent_id` | string(uuid) | false | | | +| `»»» logs_length` | integer | false | | | +| `»»» logs_overflowed` | boolean | false | | | +| `»»» metadata` | array | false | | Metadata is only populated on the workspaces list endpoint when the request opts in with the include_agent_metadata search key, and it only carries the requested keys. The description's script is always empty here: it can be long, and list consumers want values. | +| `»»»» description` | [codersdk.WorkspaceAgentMetadataDescription](schemas.md#codersdkworkspaceagentmetadatadescription) | false | | | +| `»»»»» display_name` | string | false | | | +| `»»»»» interval` | integer | false | | | +| `»»»»» key` | string | false | | | +| `»»»»» script` | string | false | | | +| `»»»»» timeout` | integer | false | | | +| `»»»» result` | [codersdk.WorkspaceAgentMetadataResult](schemas.md#codersdkworkspaceagentmetadataresult) | false | | | +| `»»»»» age` | integer | false | | Age is the number of seconds since the metadata was collected. It is provided in addition to CollectedAt to protect against clock skew. | +| `»»»»» collected_at` | string(date-time) | false | | | +| `»»»»» error` | string | false | | | +| `»»»»» value` | string | false | | | +| `»»» name` | string | false | | | +| `»»» operating_system` | string | false | | | +| `»»» parent_id` | string(uuid) | false | | | +| `»»» ready_at` | string(date-time) | false | | | +| `»»» resource_id` | string(uuid) | false | | | +| `»»» scripts` | array | false | | | +| `»»»» cron` | string | false | | | +| `»»»» dependencies` | array | false | | Dependencies lists the scripts this one waits for, as the provisioner resolved them. It is omitted when empty. | +| `»»»»» prerequisite_resource_address` | string | false | | | +| `»»»»» requirement` | [codersdk.WorkspaceAgentScriptDependencyRequirement](schemas.md#codersdkworkspaceagentscriptdependencyrequirement) | false | | | +| `»»»» display_name` | string | false | | | +| `»»»» exit_code` | integer | false | | | +| `»»»» id` | string(uuid) | false | | | +| `»»»» log_path` | string | false | | | +| `»»»» log_source_id` | string(uuid) | false | | | +| `»»»» resource_address` | string | false | | Resource address is the full Terraform address of the coder_script resource, for example "module.git_clone.coder_script.clone". It is empty for scripts that are not coder_script resources. | +| `»»»» run_on_start` | boolean | false | | | +| `»»»» run_on_stop` | boolean | false | | | +| `»»»» script` | string | false | | | +| `»»»» start_blocks_login` | boolean | false | | | +| `»»»» status` | [codersdk.WorkspaceAgentScriptStatus](schemas.md#codersdkworkspaceagentscriptstatus) | false | | | +| `»»»» timeout` | integer | false | | | +| `»»» started_at` | string(date-time) | false | | | +| `»»» startup_script_behavior` | [codersdk.WorkspaceAgentStartupScriptBehavior](schemas.md#codersdkworkspaceagentstartupscriptbehavior) | false | | Startup script behavior is a legacy field that is deprecated in favor of the `coder_script` resource. It's only referenced by old clients. Deprecated: Remove in the future! | +| `»»» status` | [codersdk.WorkspaceAgentStatus](schemas.md#codersdkworkspaceagentstatus) | false | | | +| `»»» subsystems` | array | false | | | +| `»»» troubleshooting_url` | string | false | | | +| `»»» updated_at` | string(date-time) | false | | | +| `»»» version` | string | false | | | +| `»» created_at` | string(date-time) | false | | | +| `»» daily_cost` | integer | false | | | +| `»» hide` | boolean | false | | | +| `»» icon` | string | false | | | +| `»» id` | string(uuid) | false | | | +| `»» job_id` | string(uuid) | false | | | +| `»» metadata` | array | false | | | +| `»»» key` | string | false | | | +| `»»» sensitive` | boolean | false | | | +| `»»» value` | string | false | | | +| `»» name` | string | false | | | +| `»» type` | string | false | | | +| `»» workspace_transition` | [codersdk.WorkspaceTransition](schemas.md#codersdkworkspacetransition) | false | | | +| `» status` | [codersdk.WorkspaceStatus](schemas.md#codersdkworkspacestatus) | false | | | +| `» template_version_id` | string(uuid) | false | | | +| `» template_version_name` | string | false | | | +| `» template_version_preset_id` | string(uuid) | false | | | +| `» transition` | [codersdk.WorkspaceTransition](schemas.md#codersdkworkspacetransition) | false | | | +| `» updated_at` | string(date-time) | false | | | +| `» workspace_id` | string(uuid) | false | | | +| `» workspace_name` | string | false | | | +| `» workspace_owner_avatar_url` | string | false | | | +| `» workspace_owner_id` | string(uuid) | false | | | +| `» workspace_owner_name` | string | false | | Workspace owner name is the username of the owner of the workspace. | #### Enumerated Values @@ -1831,6 +1875,7 @@ Status Code **200** | `sharing_level` | `authenticated`, `organization`, `owner`, `public` | | `state` | `complete`, `failure`, `idle`, `working` | | `lifecycle_state` | `created`, `off`, `ready`, `shutdown_error`, `shutdown_timeout`, `shutting_down`, `start_error`, `start_timeout`, `starting` | +| `requirement` | `completion`, `success` | | `startup_script_behavior` | `blocking`, `non-blocking` | | `workspace_transition` | `delete`, `start`, `stop` | | `transition` | `delete`, `start`, `stop` | @@ -2065,11 +2110,18 @@ curl -X POST http://coder-server:8080/api/v2/workspaces/{workspace}/builds \ "scripts": [ { "cron": "string", + "dependencies": [ + { + "prerequisite_resource_address": "string", + "requirement": "success" + } + ], "display_name": "string", "exit_code": 0, "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "log_path": "string", "log_source_id": "4197ab25-95cf-4b91-9c78-f7f2af5d353a", + "resource_address": "string", "run_on_start": true, "run_on_stop": true, "script": "string", diff --git a/docs/reference/api/schemas.md b/docs/reference/api/schemas.md index 97767c6d2a5..9b19da50a8a 100644 --- a/docs/reference/api/schemas.md +++ b/docs/reference/api/schemas.md @@ -18373,11 +18373,18 @@ If the schedule is empty, the user will be updated to use the default schedule.| "scripts": [ { "cron": "string", + "dependencies": [ + { + "prerequisite_resource_address": "string", + "requirement": "success" + } + ], "display_name": "string", "exit_code": 0, "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "log_path": "string", "log_source_id": "4197ab25-95cf-4b91-9c78-f7f2af5d353a", + "resource_address": "string", "run_on_start": true, "run_on_stop": true, "script": "string", @@ -18667,11 +18674,18 @@ If the schedule is empty, the user will be updated to use the default schedule.| "scripts": [ { "cron": "string", + "dependencies": [ + { + "prerequisite_resource_address": "string", + "requirement": "success" + } + ], "display_name": "string", "exit_code": 0, "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "log_path": "string", "log_source_id": "4197ab25-95cf-4b91-9c78-f7f2af5d353a", + "resource_address": "string", "run_on_start": true, "run_on_stop": true, "script": "string", @@ -19303,11 +19317,18 @@ If the schedule is empty, the user will be updated to use the default schedule.| ```json { "cron": "string", + "dependencies": [ + { + "prerequisite_resource_address": "string", + "requirement": "success" + } + ], "display_name": "string", "exit_code": 0, "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "log_path": "string", "log_source_id": "4197ab25-95cf-4b91-9c78-f7f2af5d353a", + "resource_address": "string", "run_on_start": true, "run_on_stop": true, "script": "string", @@ -19319,20 +19340,52 @@ If the schedule is empty, the user will be updated to use the default schedule.| ### Properties -| Name | Type | Required | Restrictions | Description | -|----------------------|----------------------------------------------------------------------------|----------|--------------|-------------| -| `cron` | string | false | | | -| `display_name` | string | false | | | -| `exit_code` | integer | false | | | -| `id` | string | false | | | -| `log_path` | string | false | | | -| `log_source_id` | string | false | | | -| `run_on_start` | boolean | false | | | -| `run_on_stop` | boolean | false | | | -| `script` | string | false | | | -| `start_blocks_login` | boolean | false | | | -| `status` | [codersdk.WorkspaceAgentScriptStatus](#codersdkworkspaceagentscriptstatus) | false | | | -| `timeout` | integer | false | | | +| Name | Type | Required | Restrictions | Description | +|----------------------|---------------------------------------------------------------------------------------------|----------|--------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `cron` | string | false | | | +| `dependencies` | array of [codersdk.WorkspaceAgentScriptDependency](#codersdkworkspaceagentscriptdependency) | false | | Dependencies lists the scripts this one waits for, as the provisioner resolved them. It is omitted when empty. | +| `display_name` | string | false | | | +| `exit_code` | integer | false | | | +| `id` | string | false | | | +| `log_path` | string | false | | | +| `log_source_id` | string | false | | | +| `resource_address` | string | false | | Resource address is the full Terraform address of the coder_script resource, for example "module.git_clone.coder_script.clone". It is empty for scripts that are not coder_script resources. | +| `run_on_start` | boolean | false | | | +| `run_on_stop` | boolean | false | | | +| `script` | string | false | | | +| `start_blocks_login` | boolean | false | | | +| `status` | [codersdk.WorkspaceAgentScriptStatus](#codersdkworkspaceagentscriptstatus) | false | | | +| `timeout` | integer | false | | | + +## codersdk.WorkspaceAgentScriptDependency + +```json +{ + "prerequisite_resource_address": "string", + "requirement": "success" +} +``` + +### Properties + +| Name | Type | Required | Restrictions | Description | +|---------------------------------|----------------------------------------------------------------------------------------------------------|----------|--------------|-------------| +| `prerequisite_resource_address` | string | false | | | +| `requirement` | [codersdk.WorkspaceAgentScriptDependencyRequirement](#codersdkworkspaceagentscriptdependencyrequirement) | false | | | + +## codersdk.WorkspaceAgentScriptDependencyRequirement + +```json +"success" +``` + +### Properties + +#### Enumerated Values + +| Value(s) | +|-------------------------| +| `completion`, `success` | ## codersdk.WorkspaceAgentScriptStatus @@ -19704,11 +19757,18 @@ If the schedule is empty, the user will be updated to use the default schedule.| "scripts": [ { "cron": "string", + "dependencies": [ + { + "prerequisite_resource_address": "string", + "requirement": "success" + } + ], "display_name": "string", "exit_code": 0, "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "log_path": "string", "log_source_id": "4197ab25-95cf-4b91-9c78-f7f2af5d353a", + "resource_address": "string", "run_on_start": true, "run_on_stop": true, "script": "string", @@ -20201,11 +20261,18 @@ If the schedule is empty, the user will be updated to use the default schedule.| "scripts": [ { "cron": "string", + "dependencies": [ + { + "prerequisite_resource_address": "string", + "requirement": "success" + } + ], "display_name": "string", "exit_code": 0, "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "log_path": "string", "log_source_id": "4197ab25-95cf-4b91-9c78-f7f2af5d353a", + "resource_address": "string", "run_on_start": true, "run_on_stop": true, "script": "string", @@ -20553,11 +20620,13 @@ If the schedule is empty, the user will be updated to use the default schedule.| "scripts": [ { "cron": "string", + "dependencies": [], "display_name": "string", "exit_code": 0, "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "log_path": "string", "log_source_id": "4197ab25-95cf-4b91-9c78-f7f2af5d353a", + "resource_address": "string", "run_on_start": true, "run_on_stop": true, "script": "string", diff --git a/docs/reference/api/templates.md b/docs/reference/api/templates.md index 2adb098fa95..ea10449090c 100644 --- a/docs/reference/api/templates.md +++ b/docs/reference/api/templates.md @@ -2550,11 +2550,18 @@ curl -X GET http://coder-server:8080/api/v2/templateversions/{templateversion}/d "scripts": [ { "cron": "string", + "dependencies": [ + { + "prerequisite_resource_address": "string", + "requirement": "success" + } + ], "display_name": "string", "exit_code": 0, "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "log_path": "string", "log_source_id": "4197ab25-95cf-4b91-9c78-f7f2af5d353a", + "resource_address": "string", "run_on_start": true, "run_on_stop": true, "script": "string", @@ -2604,121 +2611,125 @@ curl -X GET http://coder-server:8080/api/v2/templateversions/{templateversion}/d Status Code **200** -| Name | Type | Required | Restrictions | Description | -|---------------------------------|--------------------------------------------------------------------------------------------------------|----------|--------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `[array item]` | array | false | | | -| `» agents` | array | false | | | -| `»» api_version` | string | false | | | -| `»» apps` | array | false | | | -| `»»» command` | string | false | | | -| `»»» display_name` | string | false | | Display name is a friendly name for the app. | -| `»»» external` | boolean | false | | External specifies whether the URL should be opened externally on the client or not. | -| `»»» group` | string | false | | | -| `»»» health` | [codersdk.WorkspaceAppHealth](schemas.md#codersdkworkspaceapphealth) | false | | | -| `»»» healthcheck` | [codersdk.Healthcheck](schemas.md#codersdkhealthcheck) | false | | Healthcheck specifies the configuration for checking app health. | -| `»»»» interval` | integer | false | | Interval specifies the seconds between each health check. | -| `»»»» threshold` | integer | false | | Threshold specifies the number of consecutive failed health checks before returning "unhealthy". | -| `»»»» url` | string | false | | URL specifies the endpoint to check for the app health. | -| `»»» hidden` | boolean | false | | | -| `»»» icon` | string | false | | Icon is a relative path or external URL that specifies an icon to be displayed in the dashboard. | -| `»»» id` | string(uuid) | false | | | -| `»»» open_in` | [codersdk.WorkspaceAppOpenIn](schemas.md#codersdkworkspaceappopenin) | false | | | -| `»»» sharing_level` | [codersdk.WorkspaceAppSharingLevel](schemas.md#codersdkworkspaceappsharinglevel) | false | | | -| `»»» slug` | string | false | | Slug is a unique identifier within the agent. | -| `»»» statuses` | array | false | | Statuses is a list of statuses for the app. | -| `»»»» agent_id` | string(uuid) | false | | | -| `»»»» app_id` | string(uuid) | false | | | -| `»»»» created_at` | string(date-time) | false | | | -| `»»»» icon` | string | false | | Deprecated: This field is unused and will be removed in a future version. Icon is an external URL to an icon that will be rendered in the UI. | -| `»»»» id` | string(uuid) | false | | | -| `»»»» message` | string | false | | | -| `»»»» needs_user_attention` | boolean | false | | Deprecated: This field is unused and will be removed in a future version. NeedsUserAttention specifies whether the status needs user attention. | -| `»»»» state` | [codersdk.WorkspaceAppStatusState](schemas.md#codersdkworkspaceappstatusstate) | false | | | -| `»»»» uri` | string | false | | Uri is the URI of the resource that the status is for. e.g. https://github.com/org/repo/pull/123 e.g. file:///path/to/file | -| `»»»» workspace_id` | string(uuid) | false | | | -| `»»» subdomain` | boolean | false | | Subdomain denotes whether the app should be accessed via a path on the `coder server` or via a hostname-based dev URL. If this is set to true and there is no app wildcard configured on the server, the app will not be accessible in the UI. | -| `»»» subdomain_name` | string | false | | Subdomain name is the application domain exposed on the `coder server`. | -| `»»» tooltip` | string | false | | Tooltip is an optional markdown supported field that is displayed when hovering over workspace apps in the UI. | -| `»»» url` | string | false | | URL is the address being proxied to inside the workspace. If external is specified, this will be opened on the client. | -| `»» architecture` | string | false | | | -| `»» connection_timeout_seconds` | integer | false | | | -| `»» created_at` | string(date-time) | false | | | -| `»» directory` | string | false | | | -| `»» disconnected_at` | string(date-time) | false | | | -| `»» display_apps` | array | false | | | -| `»» environment_variables` | object | false | | | -| `»»» [any property]` | string | false | | | -| `»» expanded_directory` | string | false | | | -| `»» first_connected_at` | string(date-time) | false | | | -| `»» health` | [codersdk.WorkspaceAgentHealth](schemas.md#codersdkworkspaceagenthealth) | false | | Health reports the health of the agent. | -| `»»» healthy` | boolean | false | | Healthy is true if the agent is healthy. | -| `»»» reason` | string | false | | Reason is a human-readable explanation of the agent's health. It is empty if Healthy is true. | -| `»» id` | string(uuid) | false | | | -| `»» instance_id` | string | false | | | -| `»» last_connected_at` | string(date-time) | false | | | -| `»» latency` | object | false | | Latency is mapped by region name (e.g. "New York City", "Seattle"). | -| `»»» [any property]` | [codersdk.DERPRegion](schemas.md#codersdkderpregion) | false | | | -| `»»»» latency_ms` | number | false | | | -| `»»»» preferred` | boolean | false | | | -| `»» lifecycle_state` | [codersdk.WorkspaceAgentLifecycle](schemas.md#codersdkworkspaceagentlifecycle) | false | | | -| `»» log_sources` | array | false | | | -| `»»» created_at` | string(date-time) | false | | | -| `»»» display_name` | string | false | | | -| `»»» icon` | string | false | | | -| `»»» id` | string(uuid) | false | | | -| `»»» workspace_agent_id` | string(uuid) | false | | | -| `»» logs_length` | integer | false | | | -| `»» logs_overflowed` | boolean | false | | | -| `»» metadata` | array | false | | Metadata is only populated on the workspaces list endpoint when the request opts in with the include_agent_metadata search key, and it only carries the requested keys. The description's script is always empty here: it can be long, and list consumers want values. | -| `»»» description` | [codersdk.WorkspaceAgentMetadataDescription](schemas.md#codersdkworkspaceagentmetadatadescription) | false | | | -| `»»»» display_name` | string | false | | | -| `»»»» interval` | integer | false | | | -| `»»»» key` | string | false | | | -| `»»»» script` | string | false | | | -| `»»»» timeout` | integer | false | | | -| `»»» result` | [codersdk.WorkspaceAgentMetadataResult](schemas.md#codersdkworkspaceagentmetadataresult) | false | | | -| `»»»» age` | integer | false | | Age is the number of seconds since the metadata was collected. It is provided in addition to CollectedAt to protect against clock skew. | -| `»»»» collected_at` | string(date-time) | false | | | -| `»»»» error` | string | false | | | -| `»»»» value` | string | false | | | -| `»» name` | string | false | | | -| `»» operating_system` | string | false | | | -| `»» parent_id` | string(uuid) | false | | | -| `»» ready_at` | string(date-time) | false | | | -| `»» resource_id` | string(uuid) | false | | | -| `»» scripts` | array | false | | | -| `»»» cron` | string | false | | | -| `»»» display_name` | string | false | | | -| `»»» exit_code` | integer | false | | | -| `»»» id` | string(uuid) | false | | | -| `»»» log_path` | string | false | | | -| `»»» log_source_id` | string(uuid) | false | | | -| `»»» run_on_start` | boolean | false | | | -| `»»» run_on_stop` | boolean | false | | | -| `»»» script` | string | false | | | -| `»»» start_blocks_login` | boolean | false | | | -| `»»» status` | [codersdk.WorkspaceAgentScriptStatus](schemas.md#codersdkworkspaceagentscriptstatus) | false | | | -| `»»» timeout` | integer | false | | | -| `»» started_at` | string(date-time) | false | | | -| `»» startup_script_behavior` | [codersdk.WorkspaceAgentStartupScriptBehavior](schemas.md#codersdkworkspaceagentstartupscriptbehavior) | false | | Startup script behavior is a legacy field that is deprecated in favor of the `coder_script` resource. It's only referenced by old clients. Deprecated: Remove in the future! | -| `»» status` | [codersdk.WorkspaceAgentStatus](schemas.md#codersdkworkspaceagentstatus) | false | | | -| `»» subsystems` | array | false | | | -| `»» troubleshooting_url` | string | false | | | -| `»» updated_at` | string(date-time) | false | | | -| `»» version` | string | false | | | -| `» created_at` | string(date-time) | false | | | -| `» daily_cost` | integer | false | | | -| `» hide` | boolean | false | | | -| `» icon` | string | false | | | -| `» id` | string(uuid) | false | | | -| `» job_id` | string(uuid) | false | | | -| `» metadata` | array | false | | | -| `»» key` | string | false | | | -| `»» sensitive` | boolean | false | | | -| `»» value` | string | false | | | -| `» name` | string | false | | | -| `» type` | string | false | | | -| `» workspace_transition` | [codersdk.WorkspaceTransition](schemas.md#codersdkworkspacetransition) | false | | | +| Name | Type | Required | Restrictions | Description | +|--------------------------------------|--------------------------------------------------------------------------------------------------------------------|----------|--------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `[array item]` | array | false | | | +| `» agents` | array | false | | | +| `»» api_version` | string | false | | | +| `»» apps` | array | false | | | +| `»»» command` | string | false | | | +| `»»» display_name` | string | false | | Display name is a friendly name for the app. | +| `»»» external` | boolean | false | | External specifies whether the URL should be opened externally on the client or not. | +| `»»» group` | string | false | | | +| `»»» health` | [codersdk.WorkspaceAppHealth](schemas.md#codersdkworkspaceapphealth) | false | | | +| `»»» healthcheck` | [codersdk.Healthcheck](schemas.md#codersdkhealthcheck) | false | | Healthcheck specifies the configuration for checking app health. | +| `»»»» interval` | integer | false | | Interval specifies the seconds between each health check. | +| `»»»» threshold` | integer | false | | Threshold specifies the number of consecutive failed health checks before returning "unhealthy". | +| `»»»» url` | string | false | | URL specifies the endpoint to check for the app health. | +| `»»» hidden` | boolean | false | | | +| `»»» icon` | string | false | | Icon is a relative path or external URL that specifies an icon to be displayed in the dashboard. | +| `»»» id` | string(uuid) | false | | | +| `»»» open_in` | [codersdk.WorkspaceAppOpenIn](schemas.md#codersdkworkspaceappopenin) | false | | | +| `»»» sharing_level` | [codersdk.WorkspaceAppSharingLevel](schemas.md#codersdkworkspaceappsharinglevel) | false | | | +| `»»» slug` | string | false | | Slug is a unique identifier within the agent. | +| `»»» statuses` | array | false | | Statuses is a list of statuses for the app. | +| `»»»» agent_id` | string(uuid) | false | | | +| `»»»» app_id` | string(uuid) | false | | | +| `»»»» created_at` | string(date-time) | false | | | +| `»»»» icon` | string | false | | Deprecated: This field is unused and will be removed in a future version. Icon is an external URL to an icon that will be rendered in the UI. | +| `»»»» id` | string(uuid) | false | | | +| `»»»» message` | string | false | | | +| `»»»» needs_user_attention` | boolean | false | | Deprecated: This field is unused and will be removed in a future version. NeedsUserAttention specifies whether the status needs user attention. | +| `»»»» state` | [codersdk.WorkspaceAppStatusState](schemas.md#codersdkworkspaceappstatusstate) | false | | | +| `»»»» uri` | string | false | | Uri is the URI of the resource that the status is for. e.g. https://github.com/org/repo/pull/123 e.g. file:///path/to/file | +| `»»»» workspace_id` | string(uuid) | false | | | +| `»»» subdomain` | boolean | false | | Subdomain denotes whether the app should be accessed via a path on the `coder server` or via a hostname-based dev URL. If this is set to true and there is no app wildcard configured on the server, the app will not be accessible in the UI. | +| `»»» subdomain_name` | string | false | | Subdomain name is the application domain exposed on the `coder server`. | +| `»»» tooltip` | string | false | | Tooltip is an optional markdown supported field that is displayed when hovering over workspace apps in the UI. | +| `»»» url` | string | false | | URL is the address being proxied to inside the workspace. If external is specified, this will be opened on the client. | +| `»» architecture` | string | false | | | +| `»» connection_timeout_seconds` | integer | false | | | +| `»» created_at` | string(date-time) | false | | | +| `»» directory` | string | false | | | +| `»» disconnected_at` | string(date-time) | false | | | +| `»» display_apps` | array | false | | | +| `»» environment_variables` | object | false | | | +| `»»» [any property]` | string | false | | | +| `»» expanded_directory` | string | false | | | +| `»» first_connected_at` | string(date-time) | false | | | +| `»» health` | [codersdk.WorkspaceAgentHealth](schemas.md#codersdkworkspaceagenthealth) | false | | Health reports the health of the agent. | +| `»»» healthy` | boolean | false | | Healthy is true if the agent is healthy. | +| `»»» reason` | string | false | | Reason is a human-readable explanation of the agent's health. It is empty if Healthy is true. | +| `»» id` | string(uuid) | false | | | +| `»» instance_id` | string | false | | | +| `»» last_connected_at` | string(date-time) | false | | | +| `»» latency` | object | false | | Latency is mapped by region name (e.g. "New York City", "Seattle"). | +| `»»» [any property]` | [codersdk.DERPRegion](schemas.md#codersdkderpregion) | false | | | +| `»»»» latency_ms` | number | false | | | +| `»»»» preferred` | boolean | false | | | +| `»» lifecycle_state` | [codersdk.WorkspaceAgentLifecycle](schemas.md#codersdkworkspaceagentlifecycle) | false | | | +| `»» log_sources` | array | false | | | +| `»»» created_at` | string(date-time) | false | | | +| `»»» display_name` | string | false | | | +| `»»» icon` | string | false | | | +| `»»» id` | string(uuid) | false | | | +| `»»» workspace_agent_id` | string(uuid) | false | | | +| `»» logs_length` | integer | false | | | +| `»» logs_overflowed` | boolean | false | | | +| `»» metadata` | array | false | | Metadata is only populated on the workspaces list endpoint when the request opts in with the include_agent_metadata search key, and it only carries the requested keys. The description's script is always empty here: it can be long, and list consumers want values. | +| `»»» description` | [codersdk.WorkspaceAgentMetadataDescription](schemas.md#codersdkworkspaceagentmetadatadescription) | false | | | +| `»»»» display_name` | string | false | | | +| `»»»» interval` | integer | false | | | +| `»»»» key` | string | false | | | +| `»»»» script` | string | false | | | +| `»»»» timeout` | integer | false | | | +| `»»» result` | [codersdk.WorkspaceAgentMetadataResult](schemas.md#codersdkworkspaceagentmetadataresult) | false | | | +| `»»»» age` | integer | false | | Age is the number of seconds since the metadata was collected. It is provided in addition to CollectedAt to protect against clock skew. | +| `»»»» collected_at` | string(date-time) | false | | | +| `»»»» error` | string | false | | | +| `»»»» value` | string | false | | | +| `»» name` | string | false | | | +| `»» operating_system` | string | false | | | +| `»» parent_id` | string(uuid) | false | | | +| `»» ready_at` | string(date-time) | false | | | +| `»» resource_id` | string(uuid) | false | | | +| `»» scripts` | array | false | | | +| `»»» cron` | string | false | | | +| `»»» dependencies` | array | false | | Dependencies lists the scripts this one waits for, as the provisioner resolved them. It is omitted when empty. | +| `»»»» prerequisite_resource_address` | string | false | | | +| `»»»» requirement` | [codersdk.WorkspaceAgentScriptDependencyRequirement](schemas.md#codersdkworkspaceagentscriptdependencyrequirement) | false | | | +| `»»» display_name` | string | false | | | +| `»»» exit_code` | integer | false | | | +| `»»» id` | string(uuid) | false | | | +| `»»» log_path` | string | false | | | +| `»»» log_source_id` | string(uuid) | false | | | +| `»»» resource_address` | string | false | | Resource address is the full Terraform address of the coder_script resource, for example "module.git_clone.coder_script.clone". It is empty for scripts that are not coder_script resources. | +| `»»» run_on_start` | boolean | false | | | +| `»»» run_on_stop` | boolean | false | | | +| `»»» script` | string | false | | | +| `»»» start_blocks_login` | boolean | false | | | +| `»»» status` | [codersdk.WorkspaceAgentScriptStatus](schemas.md#codersdkworkspaceagentscriptstatus) | false | | | +| `»»» timeout` | integer | false | | | +| `»» started_at` | string(date-time) | false | | | +| `»» startup_script_behavior` | [codersdk.WorkspaceAgentStartupScriptBehavior](schemas.md#codersdkworkspaceagentstartupscriptbehavior) | false | | Startup script behavior is a legacy field that is deprecated in favor of the `coder_script` resource. It's only referenced by old clients. Deprecated: Remove in the future! | +| `»» status` | [codersdk.WorkspaceAgentStatus](schemas.md#codersdkworkspaceagentstatus) | false | | | +| `»» subsystems` | array | false | | | +| `»» troubleshooting_url` | string | false | | | +| `»» updated_at` | string(date-time) | false | | | +| `»» version` | string | false | | | +| `» created_at` | string(date-time) | false | | | +| `» daily_cost` | integer | false | | | +| `» hide` | boolean | false | | | +| `» icon` | string | false | | | +| `» id` | string(uuid) | false | | | +| `» job_id` | string(uuid) | false | | | +| `» metadata` | array | false | | | +| `»» key` | string | false | | | +| `»» sensitive` | boolean | false | | | +| `»» value` | string | false | | | +| `» name` | string | false | | | +| `» type` | string | false | | | +| `» workspace_transition` | [codersdk.WorkspaceTransition](schemas.md#codersdkworkspacetransition) | false | | | #### Enumerated Values @@ -2729,6 +2740,7 @@ Status Code **200** | `sharing_level` | `authenticated`, `organization`, `owner`, `public` | | `state` | `complete`, `failure`, `idle`, `working` | | `lifecycle_state` | `created`, `off`, `ready`, `shutdown_error`, `shutdown_timeout`, `shutting_down`, `start_error`, `start_timeout`, `starting` | +| `requirement` | `completion`, `success` | | `status` | `connected`, `connecting`, `disconnected`, `exit_failure`, `ok`, `pipes_left_open`, `timed_out`, `timeout` | | `startup_script_behavior` | `blocking`, `non-blocking` | | `workspace_transition` | `delete`, `start`, `stop` | @@ -3245,11 +3257,18 @@ curl -X GET http://coder-server:8080/api/v2/templateversions/{templateversion}/r "scripts": [ { "cron": "string", + "dependencies": [ + { + "prerequisite_resource_address": "string", + "requirement": "success" + } + ], "display_name": "string", "exit_code": 0, "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "log_path": "string", "log_source_id": "4197ab25-95cf-4b91-9c78-f7f2af5d353a", + "resource_address": "string", "run_on_start": true, "run_on_stop": true, "script": "string", @@ -3299,121 +3318,125 @@ curl -X GET http://coder-server:8080/api/v2/templateversions/{templateversion}/r Status Code **200** -| Name | Type | Required | Restrictions | Description | -|---------------------------------|--------------------------------------------------------------------------------------------------------|----------|--------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `[array item]` | array | false | | | -| `» agents` | array | false | | | -| `»» api_version` | string | false | | | -| `»» apps` | array | false | | | -| `»»» command` | string | false | | | -| `»»» display_name` | string | false | | Display name is a friendly name for the app. | -| `»»» external` | boolean | false | | External specifies whether the URL should be opened externally on the client or not. | -| `»»» group` | string | false | | | -| `»»» health` | [codersdk.WorkspaceAppHealth](schemas.md#codersdkworkspaceapphealth) | false | | | -| `»»» healthcheck` | [codersdk.Healthcheck](schemas.md#codersdkhealthcheck) | false | | Healthcheck specifies the configuration for checking app health. | -| `»»»» interval` | integer | false | | Interval specifies the seconds between each health check. | -| `»»»» threshold` | integer | false | | Threshold specifies the number of consecutive failed health checks before returning "unhealthy". | -| `»»»» url` | string | false | | URL specifies the endpoint to check for the app health. | -| `»»» hidden` | boolean | false | | | -| `»»» icon` | string | false | | Icon is a relative path or external URL that specifies an icon to be displayed in the dashboard. | -| `»»» id` | string(uuid) | false | | | -| `»»» open_in` | [codersdk.WorkspaceAppOpenIn](schemas.md#codersdkworkspaceappopenin) | false | | | -| `»»» sharing_level` | [codersdk.WorkspaceAppSharingLevel](schemas.md#codersdkworkspaceappsharinglevel) | false | | | -| `»»» slug` | string | false | | Slug is a unique identifier within the agent. | -| `»»» statuses` | array | false | | Statuses is a list of statuses for the app. | -| `»»»» agent_id` | string(uuid) | false | | | -| `»»»» app_id` | string(uuid) | false | | | -| `»»»» created_at` | string(date-time) | false | | | -| `»»»» icon` | string | false | | Deprecated: This field is unused and will be removed in a future version. Icon is an external URL to an icon that will be rendered in the UI. | -| `»»»» id` | string(uuid) | false | | | -| `»»»» message` | string | false | | | -| `»»»» needs_user_attention` | boolean | false | | Deprecated: This field is unused and will be removed in a future version. NeedsUserAttention specifies whether the status needs user attention. | -| `»»»» state` | [codersdk.WorkspaceAppStatusState](schemas.md#codersdkworkspaceappstatusstate) | false | | | -| `»»»» uri` | string | false | | Uri is the URI of the resource that the status is for. e.g. https://github.com/org/repo/pull/123 e.g. file:///path/to/file | -| `»»»» workspace_id` | string(uuid) | false | | | -| `»»» subdomain` | boolean | false | | Subdomain denotes whether the app should be accessed via a path on the `coder server` or via a hostname-based dev URL. If this is set to true and there is no app wildcard configured on the server, the app will not be accessible in the UI. | -| `»»» subdomain_name` | string | false | | Subdomain name is the application domain exposed on the `coder server`. | -| `»»» tooltip` | string | false | | Tooltip is an optional markdown supported field that is displayed when hovering over workspace apps in the UI. | -| `»»» url` | string | false | | URL is the address being proxied to inside the workspace. If external is specified, this will be opened on the client. | -| `»» architecture` | string | false | | | -| `»» connection_timeout_seconds` | integer | false | | | -| `»» created_at` | string(date-time) | false | | | -| `»» directory` | string | false | | | -| `»» disconnected_at` | string(date-time) | false | | | -| `»» display_apps` | array | false | | | -| `»» environment_variables` | object | false | | | -| `»»» [any property]` | string | false | | | -| `»» expanded_directory` | string | false | | | -| `»» first_connected_at` | string(date-time) | false | | | -| `»» health` | [codersdk.WorkspaceAgentHealth](schemas.md#codersdkworkspaceagenthealth) | false | | Health reports the health of the agent. | -| `»»» healthy` | boolean | false | | Healthy is true if the agent is healthy. | -| `»»» reason` | string | false | | Reason is a human-readable explanation of the agent's health. It is empty if Healthy is true. | -| `»» id` | string(uuid) | false | | | -| `»» instance_id` | string | false | | | -| `»» last_connected_at` | string(date-time) | false | | | -| `»» latency` | object | false | | Latency is mapped by region name (e.g. "New York City", "Seattle"). | -| `»»» [any property]` | [codersdk.DERPRegion](schemas.md#codersdkderpregion) | false | | | -| `»»»» latency_ms` | number | false | | | -| `»»»» preferred` | boolean | false | | | -| `»» lifecycle_state` | [codersdk.WorkspaceAgentLifecycle](schemas.md#codersdkworkspaceagentlifecycle) | false | | | -| `»» log_sources` | array | false | | | -| `»»» created_at` | string(date-time) | false | | | -| `»»» display_name` | string | false | | | -| `»»» icon` | string | false | | | -| `»»» id` | string(uuid) | false | | | -| `»»» workspace_agent_id` | string(uuid) | false | | | -| `»» logs_length` | integer | false | | | -| `»» logs_overflowed` | boolean | false | | | -| `»» metadata` | array | false | | Metadata is only populated on the workspaces list endpoint when the request opts in with the include_agent_metadata search key, and it only carries the requested keys. The description's script is always empty here: it can be long, and list consumers want values. | -| `»»» description` | [codersdk.WorkspaceAgentMetadataDescription](schemas.md#codersdkworkspaceagentmetadatadescription) | false | | | -| `»»»» display_name` | string | false | | | -| `»»»» interval` | integer | false | | | -| `»»»» key` | string | false | | | -| `»»»» script` | string | false | | | -| `»»»» timeout` | integer | false | | | -| `»»» result` | [codersdk.WorkspaceAgentMetadataResult](schemas.md#codersdkworkspaceagentmetadataresult) | false | | | -| `»»»» age` | integer | false | | Age is the number of seconds since the metadata was collected. It is provided in addition to CollectedAt to protect against clock skew. | -| `»»»» collected_at` | string(date-time) | false | | | -| `»»»» error` | string | false | | | -| `»»»» value` | string | false | | | -| `»» name` | string | false | | | -| `»» operating_system` | string | false | | | -| `»» parent_id` | string(uuid) | false | | | -| `»» ready_at` | string(date-time) | false | | | -| `»» resource_id` | string(uuid) | false | | | -| `»» scripts` | array | false | | | -| `»»» cron` | string | false | | | -| `»»» display_name` | string | false | | | -| `»»» exit_code` | integer | false | | | -| `»»» id` | string(uuid) | false | | | -| `»»» log_path` | string | false | | | -| `»»» log_source_id` | string(uuid) | false | | | -| `»»» run_on_start` | boolean | false | | | -| `»»» run_on_stop` | boolean | false | | | -| `»»» script` | string | false | | | -| `»»» start_blocks_login` | boolean | false | | | -| `»»» status` | [codersdk.WorkspaceAgentScriptStatus](schemas.md#codersdkworkspaceagentscriptstatus) | false | | | -| `»»» timeout` | integer | false | | | -| `»» started_at` | string(date-time) | false | | | -| `»» startup_script_behavior` | [codersdk.WorkspaceAgentStartupScriptBehavior](schemas.md#codersdkworkspaceagentstartupscriptbehavior) | false | | Startup script behavior is a legacy field that is deprecated in favor of the `coder_script` resource. It's only referenced by old clients. Deprecated: Remove in the future! | -| `»» status` | [codersdk.WorkspaceAgentStatus](schemas.md#codersdkworkspaceagentstatus) | false | | | -| `»» subsystems` | array | false | | | -| `»» troubleshooting_url` | string | false | | | -| `»» updated_at` | string(date-time) | false | | | -| `»» version` | string | false | | | -| `» created_at` | string(date-time) | false | | | -| `» daily_cost` | integer | false | | | -| `» hide` | boolean | false | | | -| `» icon` | string | false | | | -| `» id` | string(uuid) | false | | | -| `» job_id` | string(uuid) | false | | | -| `» metadata` | array | false | | | -| `»» key` | string | false | | | -| `»» sensitive` | boolean | false | | | -| `»» value` | string | false | | | -| `» name` | string | false | | | -| `» type` | string | false | | | -| `» workspace_transition` | [codersdk.WorkspaceTransition](schemas.md#codersdkworkspacetransition) | false | | | +| Name | Type | Required | Restrictions | Description | +|--------------------------------------|--------------------------------------------------------------------------------------------------------------------|----------|--------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `[array item]` | array | false | | | +| `» agents` | array | false | | | +| `»» api_version` | string | false | | | +| `»» apps` | array | false | | | +| `»»» command` | string | false | | | +| `»»» display_name` | string | false | | Display name is a friendly name for the app. | +| `»»» external` | boolean | false | | External specifies whether the URL should be opened externally on the client or not. | +| `»»» group` | string | false | | | +| `»»» health` | [codersdk.WorkspaceAppHealth](schemas.md#codersdkworkspaceapphealth) | false | | | +| `»»» healthcheck` | [codersdk.Healthcheck](schemas.md#codersdkhealthcheck) | false | | Healthcheck specifies the configuration for checking app health. | +| `»»»» interval` | integer | false | | Interval specifies the seconds between each health check. | +| `»»»» threshold` | integer | false | | Threshold specifies the number of consecutive failed health checks before returning "unhealthy". | +| `»»»» url` | string | false | | URL specifies the endpoint to check for the app health. | +| `»»» hidden` | boolean | false | | | +| `»»» icon` | string | false | | Icon is a relative path or external URL that specifies an icon to be displayed in the dashboard. | +| `»»» id` | string(uuid) | false | | | +| `»»» open_in` | [codersdk.WorkspaceAppOpenIn](schemas.md#codersdkworkspaceappopenin) | false | | | +| `»»» sharing_level` | [codersdk.WorkspaceAppSharingLevel](schemas.md#codersdkworkspaceappsharinglevel) | false | | | +| `»»» slug` | string | false | | Slug is a unique identifier within the agent. | +| `»»» statuses` | array | false | | Statuses is a list of statuses for the app. | +| `»»»» agent_id` | string(uuid) | false | | | +| `»»»» app_id` | string(uuid) | false | | | +| `»»»» created_at` | string(date-time) | false | | | +| `»»»» icon` | string | false | | Deprecated: This field is unused and will be removed in a future version. Icon is an external URL to an icon that will be rendered in the UI. | +| `»»»» id` | string(uuid) | false | | | +| `»»»» message` | string | false | | | +| `»»»» needs_user_attention` | boolean | false | | Deprecated: This field is unused and will be removed in a future version. NeedsUserAttention specifies whether the status needs user attention. | +| `»»»» state` | [codersdk.WorkspaceAppStatusState](schemas.md#codersdkworkspaceappstatusstate) | false | | | +| `»»»» uri` | string | false | | Uri is the URI of the resource that the status is for. e.g. https://github.com/org/repo/pull/123 e.g. file:///path/to/file | +| `»»»» workspace_id` | string(uuid) | false | | | +| `»»» subdomain` | boolean | false | | Subdomain denotes whether the app should be accessed via a path on the `coder server` or via a hostname-based dev URL. If this is set to true and there is no app wildcard configured on the server, the app will not be accessible in the UI. | +| `»»» subdomain_name` | string | false | | Subdomain name is the application domain exposed on the `coder server`. | +| `»»» tooltip` | string | false | | Tooltip is an optional markdown supported field that is displayed when hovering over workspace apps in the UI. | +| `»»» url` | string | false | | URL is the address being proxied to inside the workspace. If external is specified, this will be opened on the client. | +| `»» architecture` | string | false | | | +| `»» connection_timeout_seconds` | integer | false | | | +| `»» created_at` | string(date-time) | false | | | +| `»» directory` | string | false | | | +| `»» disconnected_at` | string(date-time) | false | | | +| `»» display_apps` | array | false | | | +| `»» environment_variables` | object | false | | | +| `»»» [any property]` | string | false | | | +| `»» expanded_directory` | string | false | | | +| `»» first_connected_at` | string(date-time) | false | | | +| `»» health` | [codersdk.WorkspaceAgentHealth](schemas.md#codersdkworkspaceagenthealth) | false | | Health reports the health of the agent. | +| `»»» healthy` | boolean | false | | Healthy is true if the agent is healthy. | +| `»»» reason` | string | false | | Reason is a human-readable explanation of the agent's health. It is empty if Healthy is true. | +| `»» id` | string(uuid) | false | | | +| `»» instance_id` | string | false | | | +| `»» last_connected_at` | string(date-time) | false | | | +| `»» latency` | object | false | | Latency is mapped by region name (e.g. "New York City", "Seattle"). | +| `»»» [any property]` | [codersdk.DERPRegion](schemas.md#codersdkderpregion) | false | | | +| `»»»» latency_ms` | number | false | | | +| `»»»» preferred` | boolean | false | | | +| `»» lifecycle_state` | [codersdk.WorkspaceAgentLifecycle](schemas.md#codersdkworkspaceagentlifecycle) | false | | | +| `»» log_sources` | array | false | | | +| `»»» created_at` | string(date-time) | false | | | +| `»»» display_name` | string | false | | | +| `»»» icon` | string | false | | | +| `»»» id` | string(uuid) | false | | | +| `»»» workspace_agent_id` | string(uuid) | false | | | +| `»» logs_length` | integer | false | | | +| `»» logs_overflowed` | boolean | false | | | +| `»» metadata` | array | false | | Metadata is only populated on the workspaces list endpoint when the request opts in with the include_agent_metadata search key, and it only carries the requested keys. The description's script is always empty here: it can be long, and list consumers want values. | +| `»»» description` | [codersdk.WorkspaceAgentMetadataDescription](schemas.md#codersdkworkspaceagentmetadatadescription) | false | | | +| `»»»» display_name` | string | false | | | +| `»»»» interval` | integer | false | | | +| `»»»» key` | string | false | | | +| `»»»» script` | string | false | | | +| `»»»» timeout` | integer | false | | | +| `»»» result` | [codersdk.WorkspaceAgentMetadataResult](schemas.md#codersdkworkspaceagentmetadataresult) | false | | | +| `»»»» age` | integer | false | | Age is the number of seconds since the metadata was collected. It is provided in addition to CollectedAt to protect against clock skew. | +| `»»»» collected_at` | string(date-time) | false | | | +| `»»»» error` | string | false | | | +| `»»»» value` | string | false | | | +| `»» name` | string | false | | | +| `»» operating_system` | string | false | | | +| `»» parent_id` | string(uuid) | false | | | +| `»» ready_at` | string(date-time) | false | | | +| `»» resource_id` | string(uuid) | false | | | +| `»» scripts` | array | false | | | +| `»»» cron` | string | false | | | +| `»»» dependencies` | array | false | | Dependencies lists the scripts this one waits for, as the provisioner resolved them. It is omitted when empty. | +| `»»»» prerequisite_resource_address` | string | false | | | +| `»»»» requirement` | [codersdk.WorkspaceAgentScriptDependencyRequirement](schemas.md#codersdkworkspaceagentscriptdependencyrequirement) | false | | | +| `»»» display_name` | string | false | | | +| `»»» exit_code` | integer | false | | | +| `»»» id` | string(uuid) | false | | | +| `»»» log_path` | string | false | | | +| `»»» log_source_id` | string(uuid) | false | | | +| `»»» resource_address` | string | false | | Resource address is the full Terraform address of the coder_script resource, for example "module.git_clone.coder_script.clone". It is empty for scripts that are not coder_script resources. | +| `»»» run_on_start` | boolean | false | | | +| `»»» run_on_stop` | boolean | false | | | +| `»»» script` | string | false | | | +| `»»» start_blocks_login` | boolean | false | | | +| `»»» status` | [codersdk.WorkspaceAgentScriptStatus](schemas.md#codersdkworkspaceagentscriptstatus) | false | | | +| `»»» timeout` | integer | false | | | +| `»» started_at` | string(date-time) | false | | | +| `»» startup_script_behavior` | [codersdk.WorkspaceAgentStartupScriptBehavior](schemas.md#codersdkworkspaceagentstartupscriptbehavior) | false | | Startup script behavior is a legacy field that is deprecated in favor of the `coder_script` resource. It's only referenced by old clients. Deprecated: Remove in the future! | +| `»» status` | [codersdk.WorkspaceAgentStatus](schemas.md#codersdkworkspaceagentstatus) | false | | | +| `»» subsystems` | array | false | | | +| `»» troubleshooting_url` | string | false | | | +| `»» updated_at` | string(date-time) | false | | | +| `»» version` | string | false | | | +| `» created_at` | string(date-time) | false | | | +| `» daily_cost` | integer | false | | | +| `» hide` | boolean | false | | | +| `» icon` | string | false | | | +| `» id` | string(uuid) | false | | | +| `» job_id` | string(uuid) | false | | | +| `» metadata` | array | false | | | +| `»» key` | string | false | | | +| `»» sensitive` | boolean | false | | | +| `»» value` | string | false | | | +| `» name` | string | false | | | +| `» type` | string | false | | | +| `» workspace_transition` | [codersdk.WorkspaceTransition](schemas.md#codersdkworkspacetransition) | false | | | #### Enumerated Values @@ -3424,6 +3447,7 @@ Status Code **200** | `sharing_level` | `authenticated`, `organization`, `owner`, `public` | | `state` | `complete`, `failure`, `idle`, `working` | | `lifecycle_state` | `created`, `off`, `ready`, `shutdown_error`, `shutdown_timeout`, `shutting_down`, `start_error`, `start_timeout`, `starting` | +| `requirement` | `completion`, `success` | | `status` | `connected`, `connecting`, `disconnected`, `exit_failure`, `ok`, `pipes_left_open`, `timed_out`, `timeout` | | `startup_script_behavior` | `blocking`, `non-blocking` | | `workspace_transition` | `delete`, `start`, `stop` | diff --git a/docs/reference/api/workspaces.md b/docs/reference/api/workspaces.md index 6c707845c48..906dd650cb3 100644 --- a/docs/reference/api/workspaces.md +++ b/docs/reference/api/workspaces.md @@ -254,11 +254,18 @@ of the template will be used. "scripts": [ { "cron": "string", + "dependencies": [ + { + "prerequisite_resource_address": "string", + "requirement": "success" + } + ], "display_name": "string", "exit_code": 0, "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "log_path": "string", "log_source_id": "4197ab25-95cf-4b91-9c78-f7f2af5d353a", + "resource_address": "string", "run_on_start": true, "run_on_stop": true, "script": "string", @@ -630,11 +637,18 @@ curl -X GET http://coder-server:8080/api/v2/users/{user}/workspace/{workspacenam "scripts": [ { "cron": "string", + "dependencies": [ + { + "prerequisite_resource_address": "string", + "requirement": "success" + } + ], "display_name": "string", "exit_code": 0, "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "log_path": "string", "log_source_id": "4197ab25-95cf-4b91-9c78-f7f2af5d353a", + "resource_address": "string", "run_on_start": true, "run_on_stop": true, "script": "string", @@ -972,11 +986,18 @@ of the template will be used. "scripts": [ { "cron": "string", + "dependencies": [ + { + "prerequisite_resource_address": "string", + "requirement": "success" + } + ], "display_name": "string", "exit_code": 0, "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "log_path": "string", "log_source_id": "4197ab25-95cf-4b91-9c78-f7f2af5d353a", + "resource_address": "string", "run_on_start": true, "run_on_stop": true, "script": "string", @@ -1264,11 +1285,13 @@ curl -X GET http://coder-server:8080/api/v2/workspaces \ "scripts": [ { "cron": "string", + "dependencies": [], "display_name": "string", "exit_code": 0, "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "log_path": "string", "log_source_id": "4197ab25-95cf-4b91-9c78-f7f2af5d353a", + "resource_address": "string", "run_on_start": true, "run_on_stop": true, "script": "string", @@ -1583,11 +1606,18 @@ curl -X GET http://coder-server:8080/api/v2/workspaces/{workspace} \ "scripts": [ { "cron": "string", + "dependencies": [ + { + "prerequisite_resource_address": "string", + "requirement": "success" + } + ], "display_name": "string", "exit_code": 0, "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "log_path": "string", "log_source_id": "4197ab25-95cf-4b91-9c78-f7f2af5d353a", + "resource_address": "string", "run_on_start": true, "run_on_stop": true, "script": "string", @@ -2211,11 +2241,18 @@ curl -X PUT http://coder-server:8080/api/v2/workspaces/{workspace}/dormant \ "scripts": [ { "cron": "string", + "dependencies": [ + { + "prerequisite_resource_address": "string", + "requirement": "success" + } + ], "display_name": "string", "exit_code": 0, "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "log_path": "string", "log_source_id": "4197ab25-95cf-4b91-9c78-f7f2af5d353a", + "resource_address": "string", "run_on_start": true, "run_on_stop": true, "script": "string", diff --git a/site/src/api/typesGenerated.ts b/site/src/api/typesGenerated.ts index 53e930c6008..72cdb519fe3 100644 --- a/site/src/api/typesGenerated.ts +++ b/site/src/api/typesGenerated.ts @@ -12212,10 +12212,39 @@ export interface WorkspaceAgentScript { readonly start_blocks_login: boolean; readonly timeout: number; readonly display_name: string; + /** + * ResourceAddress is the full Terraform address of the coder_script + * resource, for example "module.git_clone.coder_script.clone". It is + * empty for scripts that are not coder_script resources. + */ + readonly resource_address: string; + /** + * Dependencies lists the scripts this one waits for, as the + * provisioner resolved them. It is omitted when empty. + */ + readonly dependencies?: readonly WorkspaceAgentScriptDependency[]; readonly exit_code?: number; readonly status?: WorkspaceAgentScriptStatus; } +// From codersdk/workspaceagents.go +/** + * WorkspaceAgentScriptDependency names a prerequisite script and the + * outcome it must reach. + */ +export interface WorkspaceAgentScriptDependency { + readonly prerequisite_resource_address: string; + readonly requirement: WorkspaceAgentScriptDependencyRequirement; +} + +// From codersdk/workspaceagents.go +export type WorkspaceAgentScriptDependencyRequirement = + | "completion" + | "success"; + +export const WorkspaceAgentScriptDependencyRequirements: WorkspaceAgentScriptDependencyRequirement[] = + ["completion", "success"]; + // From codersdk/workspaceagents.go export type WorkspaceAgentScriptStatus = | "exit_failure" diff --git a/site/src/testHelpers/entities.ts b/site/src/testHelpers/entities.ts index d0d14cad685..f13d7aed447 100644 --- a/site/src/testHelpers/entities.ts +++ b/site/src/testHelpers/entities.ts @@ -1106,6 +1106,7 @@ const MockWorkspaceAgentScript: TypesGen.WorkspaceAgentScript = { start_blocks_login: false, timeout: 0, display_name: "Startup Script", + resource_address: "", }; export const MockWorkspaceAgent: TypesGen.WorkspaceAgent = {