- Notifications
You must be signed in to change notification settings - Fork1.1k
feat: persist prebuild definitions on template import#16951
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from17 commits
5ecc277bc5f4f448c5372b16d1262c255428e491d8514fdbf390a1fd07e9613a07c2b2300e80fb7882378122595bfb7c286639167769ae1de7e9c2739360478bdcafb412d19851773ec23773c2bc3ff44baa3076ed14fb33cc74fbfc32154d7b4ec4e8b53f79df6554ccc309eee1f16ad040ddd83a6722cd707100f3bda0a7c7cd297cc4ff4d59039205d6afe489e1b1b2968620470e46fc18897b9c8cee189a0b692c0e5f747db03166a42aa6b490bc4e7d2f167b928fd34ab7a8ec49a64d661865998bc787cd2bd38603097f9c34cfdd6f4a34d528d9cd45f870d7e18ad9314667171a26c094bf4ab53a84b1bb6ed4121e8b15022312f414540a555c41ba9d09b75761e86f61419df06589221b15b97add656a7508b244e1f585d7d4f1b943f82b95d8de71a87933a798cfa1dc87f457c17fcdFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
This file was deleted.
Uh oh!
There was an error while loading.Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| -- Revert prebuild views | ||
| DROP VIEW IF EXISTS workspace_prebuild_builds; | ||
| DROP VIEW IF EXISTS workspace_prebuilds; | ||
| DROP VIEW IF EXISTSworkspace_latest_builds; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| -- workspace_latest_builds contains latest build for every workspace | ||
| CREATE VIEW workspace_latest_builds AS | ||
| SELECT DISTINCT ON (workspace_id) * | ||
| FROM workspace_builds | ||
| ORDER BY workspace_id, build_number DESC; | ||
| -- workspace_prebuilds contains all prebuilt workspaces with corresponding agent information | ||
| -- (including lifecycle_state which indicates is agent ready or not) and corresponding preset_id for prebuild | ||
| CREATE VIEW workspace_prebuilds AS | ||
| WITH | ||
| -- All workspaces owned by the "prebuilds" user. | ||
| all_prebuilds AS ( | ||
| SELECT w.id, w.name, w.template_id, w.created_at | ||
| FROM workspaces w | ||
| WHERE w.owner_id = 'c42fdf75-3097-471c-8c33-fb52454d81c0' -- The system user responsible for prebuilds. | ||
| ), | ||
| -- We can't rely on the template_version_preset_id in the workspace_builds table because this value is only set on the | ||
| -- initial workspace creation. Subsequent stop/start transitions will not have a value for template_version_preset_id, | ||
| -- and therefore we can't rely on (say) the latest build's chosen template_version_preset_id. | ||
| -- | ||
| -- See https://github.com/coder/internal/issues/398 | ||
| workspaces_with_latest_presets AS ( | ||
| SELECT DISTINCT ON (workspace_id) workspace_id, template_version_preset_id | ||
| FROM workspace_builds | ||
| WHERE template_version_preset_id IS NOT NULL | ||
| ORDER BY workspace_id, build_number DESC | ||
| ), | ||
| -- workspaces_with_agents_status contains workspaces owned by the "prebuilds" user, | ||
| -- along with the readiness status of their agents. | ||
| -- A workspace is marked as 'ready' only if ALL of its agents are ready. | ||
| workspaces_with_agents_status AS ( | ||
| SELECT w.id AS workspace_id, | ||
| BOOL_AND(wa.lifecycle_state = 'ready'::workspace_agent_lifecycle_state) AS ready | ||
| FROM workspaces w | ||
| INNER JOIN workspace_latest_builds wlb ON wlb.workspace_id = w.id | ||
| INNER JOIN workspace_resources wr ON wr.job_id = wlb.job_id | ||
| INNER JOIN workspace_agents wa ON wa.resource_id = wr.id | ||
| WHERE w.owner_id = 'c42fdf75-3097-471c-8c33-fb52454d81c0' -- The system user responsible for prebuilds. | ||
| GROUP BY w.id | ||
| ), | ||
| current_presets AS (SELECT w.id AS prebuild_id, wlp.template_version_preset_id | ||
| FROM workspaces w | ||
| INNER JOIN workspaces_with_latest_presets wlp ON wlp.workspace_id = w.id | ||
| WHERE w.owner_id = 'c42fdf75-3097-471c-8c33-fb52454d81c0') -- The system user responsible for prebuilds. | ||
| SELECT p.id, p.name, p.template_id, p.created_at, COALESCE(a.ready, false) AS ready, cp.template_version_preset_id AS current_preset_id | ||
| FROM all_prebuilds p | ||
| LEFT JOIN workspaces_with_agents_status a ON a.workspace_id = p.id | ||
| INNER JOIN current_presets cp ON cp.prebuild_id = p.id; | ||
| CREATE VIEW workspace_prebuild_builds AS | ||
| SELECT * | ||
| FROM workspace_builds | ||
| WHERE initiator_id = 'c42fdf75-3097-471c-8c33-fb52454d81c0'; -- The system user responsible for prebuilds. |
This file was deleted.
Uh oh!
There was an error while loading.Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| UPDATE template_version_presets | ||
| SET desired_instances = 1 | ||
| WHERE id = '28b42cc0-c4fe-4907-a0fe-e4d20f1e9bfe'; |
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.