forked from wrenn/wrenn
Introduces an end-to-end template building pipeline: admins submit a recipe
(list of shell commands) via the dashboard, a Redis-backed worker pool spins
up a sandbox, executes each command, and produces either a full snapshot
(with healthcheck) or an image-only template (rootfs flattened via a new
FlattenRootfs host-agent RPC). Build progress and per-step logs are persisted
to a new template_builds table and polled by the frontend.
Backend:
- New FlattenRootfs RPC (proto + host agent + sandbox manager)
- BuildService with Redis queue (BLPOP) and configurable worker pool (default 2)
- Admin-only REST endpoints: POST/GET /v1/admin/builds, GET /v1/admin/builds/{id}
- Migration for template_builds table with JSONB logs and recipe columns
- sqlc queries for build CRUD and progress updates
Frontend:
- /admin/templates page with Templates + Builds tabs
- Create Template dialog with recipe textarea, healthcheck, specs
- Build history with expandable per-step logs, status badges, progress bars
- Auto-polling every 3s for active builds
- AdminSidebar updated with Templates nav item
224 lines
5.6 KiB
Go
224 lines
5.6 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: template_builds.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const getTemplateBuild = `-- name: GetTemplateBuild :one
|
|
SELECT id, name, base_template, recipe, healthcheck, vcpus, memory_mb, status, current_step, total_steps, logs, error, sandbox_id, host_id, created_at, started_at, completed_at FROM template_builds WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetTemplateBuild(ctx context.Context, id string) (TemplateBuild, error) {
|
|
row := q.db.QueryRow(ctx, getTemplateBuild, id)
|
|
var i TemplateBuild
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.BaseTemplate,
|
|
&i.Recipe,
|
|
&i.Healthcheck,
|
|
&i.Vcpus,
|
|
&i.MemoryMb,
|
|
&i.Status,
|
|
&i.CurrentStep,
|
|
&i.TotalSteps,
|
|
&i.Logs,
|
|
&i.Error,
|
|
&i.SandboxID,
|
|
&i.HostID,
|
|
&i.CreatedAt,
|
|
&i.StartedAt,
|
|
&i.CompletedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const insertTemplateBuild = `-- name: InsertTemplateBuild :one
|
|
INSERT INTO template_builds (id, name, base_template, recipe, healthcheck, vcpus, memory_mb, status, total_steps)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, 'pending', $8)
|
|
RETURNING id, name, base_template, recipe, healthcheck, vcpus, memory_mb, status, current_step, total_steps, logs, error, sandbox_id, host_id, created_at, started_at, completed_at
|
|
`
|
|
|
|
type InsertTemplateBuildParams struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
BaseTemplate string `json:"base_template"`
|
|
Recipe []byte `json:"recipe"`
|
|
Healthcheck pgtype.Text `json:"healthcheck"`
|
|
Vcpus int32 `json:"vcpus"`
|
|
MemoryMb int32 `json:"memory_mb"`
|
|
TotalSteps int32 `json:"total_steps"`
|
|
}
|
|
|
|
func (q *Queries) InsertTemplateBuild(ctx context.Context, arg InsertTemplateBuildParams) (TemplateBuild, error) {
|
|
row := q.db.QueryRow(ctx, insertTemplateBuild,
|
|
arg.ID,
|
|
arg.Name,
|
|
arg.BaseTemplate,
|
|
arg.Recipe,
|
|
arg.Healthcheck,
|
|
arg.Vcpus,
|
|
arg.MemoryMb,
|
|
arg.TotalSteps,
|
|
)
|
|
var i TemplateBuild
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.BaseTemplate,
|
|
&i.Recipe,
|
|
&i.Healthcheck,
|
|
&i.Vcpus,
|
|
&i.MemoryMb,
|
|
&i.Status,
|
|
&i.CurrentStep,
|
|
&i.TotalSteps,
|
|
&i.Logs,
|
|
&i.Error,
|
|
&i.SandboxID,
|
|
&i.HostID,
|
|
&i.CreatedAt,
|
|
&i.StartedAt,
|
|
&i.CompletedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listTemplateBuilds = `-- name: ListTemplateBuilds :many
|
|
SELECT id, name, base_template, recipe, healthcheck, vcpus, memory_mb, status, current_step, total_steps, logs, error, sandbox_id, host_id, created_at, started_at, completed_at FROM template_builds ORDER BY created_at DESC
|
|
`
|
|
|
|
func (q *Queries) ListTemplateBuilds(ctx context.Context) ([]TemplateBuild, error) {
|
|
rows, err := q.db.Query(ctx, listTemplateBuilds)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []TemplateBuild
|
|
for rows.Next() {
|
|
var i TemplateBuild
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.BaseTemplate,
|
|
&i.Recipe,
|
|
&i.Healthcheck,
|
|
&i.Vcpus,
|
|
&i.MemoryMb,
|
|
&i.Status,
|
|
&i.CurrentStep,
|
|
&i.TotalSteps,
|
|
&i.Logs,
|
|
&i.Error,
|
|
&i.SandboxID,
|
|
&i.HostID,
|
|
&i.CreatedAt,
|
|
&i.StartedAt,
|
|
&i.CompletedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const updateBuildError = `-- name: UpdateBuildError :exec
|
|
UPDATE template_builds
|
|
SET error = $2, status = 'failed', completed_at = NOW()
|
|
WHERE id = $1
|
|
`
|
|
|
|
type UpdateBuildErrorParams struct {
|
|
ID string `json:"id"`
|
|
Error pgtype.Text `json:"error"`
|
|
}
|
|
|
|
func (q *Queries) UpdateBuildError(ctx context.Context, arg UpdateBuildErrorParams) error {
|
|
_, err := q.db.Exec(ctx, updateBuildError, arg.ID, arg.Error)
|
|
return err
|
|
}
|
|
|
|
const updateBuildProgress = `-- name: UpdateBuildProgress :exec
|
|
UPDATE template_builds
|
|
SET current_step = $2, logs = $3
|
|
WHERE id = $1
|
|
`
|
|
|
|
type UpdateBuildProgressParams struct {
|
|
ID string `json:"id"`
|
|
CurrentStep int32 `json:"current_step"`
|
|
Logs []byte `json:"logs"`
|
|
}
|
|
|
|
func (q *Queries) UpdateBuildProgress(ctx context.Context, arg UpdateBuildProgressParams) error {
|
|
_, err := q.db.Exec(ctx, updateBuildProgress, arg.ID, arg.CurrentStep, arg.Logs)
|
|
return err
|
|
}
|
|
|
|
const updateBuildSandbox = `-- name: UpdateBuildSandbox :exec
|
|
UPDATE template_builds
|
|
SET sandbox_id = $2, host_id = $3
|
|
WHERE id = $1
|
|
`
|
|
|
|
type UpdateBuildSandboxParams struct {
|
|
ID string `json:"id"`
|
|
SandboxID pgtype.Text `json:"sandbox_id"`
|
|
HostID pgtype.Text `json:"host_id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateBuildSandbox(ctx context.Context, arg UpdateBuildSandboxParams) error {
|
|
_, err := q.db.Exec(ctx, updateBuildSandbox, arg.ID, arg.SandboxID, arg.HostID)
|
|
return err
|
|
}
|
|
|
|
const updateBuildStatus = `-- name: UpdateBuildStatus :one
|
|
UPDATE template_builds
|
|
SET status = $2,
|
|
started_at = CASE WHEN $2 = 'running' AND started_at IS NULL THEN NOW() ELSE started_at END,
|
|
completed_at = CASE WHEN $2 IN ('success', 'failed') THEN NOW() ELSE completed_at END
|
|
WHERE id = $1
|
|
RETURNING id, name, base_template, recipe, healthcheck, vcpus, memory_mb, status, current_step, total_steps, logs, error, sandbox_id, host_id, created_at, started_at, completed_at
|
|
`
|
|
|
|
type UpdateBuildStatusParams struct {
|
|
ID string `json:"id"`
|
|
Status string `json:"status"`
|
|
}
|
|
|
|
func (q *Queries) UpdateBuildStatus(ctx context.Context, arg UpdateBuildStatusParams) (TemplateBuild, error) {
|
|
row := q.db.QueryRow(ctx, updateBuildStatus, arg.ID, arg.Status)
|
|
var i TemplateBuild
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.BaseTemplate,
|
|
&i.Recipe,
|
|
&i.Healthcheck,
|
|
&i.Vcpus,
|
|
&i.MemoryMb,
|
|
&i.Status,
|
|
&i.CurrentStep,
|
|
&i.TotalSteps,
|
|
&i.Logs,
|
|
&i.Error,
|
|
&i.SandboxID,
|
|
&i.HostID,
|
|
&i.CreatedAt,
|
|
&i.StartedAt,
|
|
&i.CompletedAt,
|
|
)
|
|
return i, err
|
|
}
|