mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add support for coder_script (#9584)
* Add basic migrations * Improve schema * Refactor agent scripts into it's own package * Support legacy start and stop script format * Pipe the scripts! * Finish the piping * Fix context usage * It works! * Fix sql query * Fix SQL query * Rename `LogSourceID` -> `SourceID` * Fix the FE * fmt * Rename migrations * Fix log tests * Fix lint err * Fix gen * Fix story type * Rename source to script * Fix schema jank * Uncomment test * Rename proto to TimeoutSeconds * Fix comments * Fix comments * Fix legacy endpoint without specified log_source * Fix non-blocking by default in agent * Fix resources tests * Fix dbfake * Fix resources * Fix linting I think * Add fixtures * fmt * Fix startup script behavior * Fix comments * Fix context * Fix cancel * Fix SQL tests * Fix e2e tests * Interrupt on Windows * Fix agent leaking script process * Fix migrations * Fix stories * Fix duplicate logs appearing * Gen * Fix log location * Fix tests * Fix tests * Fix log output * Show display name in output * Fix print * Return timeout on start context * Gen * Fix fixture * Fix the agent status * Fix startup timeout msg * Fix command using shared context * Fix timeout draining * Change signal type * Add deterministic colors to startup script logs --------- Co-authored-by: Muhammad Atif Ali <atif@coder.com>
This commit is contained in:
co-authored by
Muhammad Atif Ali
parent
dac1375880
commit
1262eef2c0
@@ -0,0 +1,23 @@
|
||||
BEGIN;
|
||||
|
||||
ALTER TABLE workspace_agent_logs SET LOGGED;
|
||||
|
||||
-- Revert the workspace_agents table to its former state
|
||||
ALTER TABLE workspace_agents ADD COLUMN startup_script text;
|
||||
ALTER TABLE workspace_agents ADD COLUMN startup_script_behavior text;
|
||||
ALTER TABLE workspace_agents ADD COLUMN shutdown_script_timeout_seconds integer;
|
||||
ALTER TABLE workspace_agents ADD COLUMN shutdown_script text;
|
||||
ALTER TABLE workspace_agents ADD COLUMN startup_script_timeout_seconds integer;
|
||||
|
||||
-- Reinstate the dropped type
|
||||
CREATE TYPE workspace_agent_log_source AS ENUM ('startup_script', 'shutdown_script', 'kubernetes_logs', 'envbox', 'envbuilder', 'external');
|
||||
|
||||
-- Add old source column back with enum type and drop log_source_id
|
||||
ALTER TABLE workspace_agent_logs ADD COLUMN source workspace_agent_log_source;
|
||||
ALTER TABLE workspace_agent_logs DROP COLUMN log_source_id;
|
||||
|
||||
-- Drop the newly created tables
|
||||
DROP TABLE workspace_agent_scripts;
|
||||
DROP TABLE workspace_agent_log_sources;
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,36 @@
|
||||
BEGIN;
|
||||
CREATE TABLE workspace_agent_log_sources (
|
||||
workspace_agent_id uuid NOT NULL REFERENCES workspace_agents(id) ON DELETE CASCADE,
|
||||
id uuid NOT NULL,
|
||||
created_at timestamptz NOT NULL,
|
||||
display_name varchar(127) NOT NULL,
|
||||
icon text NOT NULL,
|
||||
PRIMARY KEY (workspace_agent_id, id)
|
||||
);
|
||||
|
||||
CREATE TABLE workspace_agent_scripts (
|
||||
workspace_agent_id uuid NOT NULL REFERENCES workspace_agents(id) ON DELETE CASCADE,
|
||||
log_source_id uuid NOT NULL,
|
||||
log_path text NOT NULL,
|
||||
created_at timestamptz NOT NULL,
|
||||
script text NOT NULL,
|
||||
cron text NOT NULL,
|
||||
start_blocks_login boolean NOT NULL,
|
||||
run_on_start boolean NOT NULL,
|
||||
run_on_stop boolean NOT NULL,
|
||||
timeout_seconds integer NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE workspace_agent_logs ADD COLUMN log_source_id uuid NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000'::uuid;
|
||||
ALTER TABLE workspace_agent_logs DROP COLUMN source;
|
||||
DROP TYPE workspace_agent_log_source;
|
||||
|
||||
ALTER TABLE workspace_agents DROP COLUMN startup_script_timeout_seconds;
|
||||
ALTER TABLE workspace_agents DROP COLUMN shutdown_script;
|
||||
ALTER TABLE workspace_agents DROP COLUMN shutdown_script_timeout_seconds;
|
||||
ALTER TABLE workspace_agents DROP COLUMN startup_script_behavior;
|
||||
ALTER TABLE workspace_agents DROP COLUMN startup_script;
|
||||
|
||||
-- Set the table to unlogged to speed up the inserts
|
||||
ALTER TABLE workspace_agent_logs SET UNLOGGED;
|
||||
COMMIT;
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
-- INSERT INTO workspace_agents VALUES ('45e89705-e09d-4850-bcec-f9a937f5d78d', '2022-11-02 13:03:45.046432+02', '2022-11-02 13:03:45.046432+02', 'main', NULL, NULL, NULL, '0ff953c0-92a6-4fe6-a415-eb0139a36ad1', 'ffc107ef-7ded-4d80-b1a9-0c1d0bf7ccbf', NULL, 'amd64', '{"GIT_AUTHOR_NAME": "default", "GIT_AUTHOR_EMAIL": "", "GIT_COMMITTER_NAME": "default", "GIT_COMMITTER_EMAIL": ""}', 'linux', 'code-server --auth none', NULL, NULL, '', '') ON CONFLICT DO NOTHING;
|
||||
|
||||
INSERT INTO workspace_agent_log_sources (
|
||||
workspace_agent_id,
|
||||
id,
|
||||
created_at,
|
||||
display_name,
|
||||
icon
|
||||
) VALUES (
|
||||
'45e89705-e09d-4850-bcec-f9a937f5d78d',
|
||||
'0ff953c0-92a6-4fe6-a415-eb0139a36ad1',
|
||||
'2022-11-02 13:03:45.046432+02',
|
||||
'main',
|
||||
'something.png'
|
||||
) ON CONFLICT DO NOTHING;
|
||||
|
||||
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
|
||||
) VALUES (
|
||||
'45e89705-e09d-4850-bcec-f9a937f5d78d',
|
||||
'2022-11-02 13:03:45.046432+02',
|
||||
'0ff953c0-92a6-4fe6-a415-eb0139a36ad1',
|
||||
'/tmp',
|
||||
'echo "hello world"',
|
||||
'@daily',
|
||||
TRUE,
|
||||
TRUE,
|
||||
TRUE,
|
||||
60
|
||||
) ON CONFLICT DO NOTHING;
|
||||
Reference in New Issue
Block a user