diff --git a/apps/docs/compose.yaml b/apps/docs/compose.yaml index 9ec74bcd..d2bbc9eb 100644 --- a/apps/docs/compose.yaml +++ b/apps/docs/compose.yaml @@ -3,7 +3,7 @@ services: build: dockerfile: apps/docs/Dockerfile context: ../.. - image: pkg.bar/clowder-docs:latest + image: pkg.bar/clowder-docs pull_policy: always x-ports: - clowder.run:80/https diff --git a/apps/docs/content/docs/(guide)/quickstart.mdx b/apps/docs/content/docs/(guide)/quickstart.mdx index b2aa2d60..942b1c5a 100644 --- a/apps/docs/content/docs/(guide)/quickstart.mdx +++ b/apps/docs/content/docs/(guide)/quickstart.mdx @@ -6,7 +6,7 @@ description: Install Clowder and deploy your first template ## Prerequisites -A Linux server with root or passwordless sudo, preferably a domain(clowder.example.com). You can also run this under an IP but its unsecured and support wont be provided +A Linux server with root or passwordless sudo, preferably a domain(clowder.example.com). You can also run this under an IP but its unsecure and support wont be provided. I recommend just using the cluster dns ## Install diff --git a/apps/docs/openapi.json b/apps/docs/openapi.json index a9350f81..292ee4f8 100644 --- a/apps/docs/openapi.json +++ b/apps/docs/openapi.json @@ -888,47 +888,6 @@ } } }, - "/cluster/deployCaddy": { - "post": { - "operationId": "cluster.deployCaddy", - "requestBody": { - "required": true, - "content": { - "application/json": { - "schema": { - "type": "object", - "properties": { - "clusterId": { - "type": "string", - "format": "uuid" - }, - "image": { - "type": "string", - "minLength": 1, - "maxLength": 512 - }, - "caddyfile": { - "type": "string", - "maxLength": 262144 - } - }, - "required": [ - "clusterId", - "image", - "caddyfile" - ] - } - } - } - }, - "responses": { - "200": { - "description": "OK", - "content": {} - } - } - } - }, "/cluster/getDomain": { "post": { "operationId": "cluster.getDomain", diff --git a/apps/sidecar/internal/httpapi/client_backend.go b/apps/sidecar/internal/httpapi/client_backend.go index da5d00f5..ccc52a7f 100644 --- a/apps/sidecar/internal/httpapi/client_backend.go +++ b/apps/sidecar/internal/httpapi/client_backend.go @@ -6,7 +6,6 @@ import ( "encoding/hex" "errors" "fmt" - "maps" "reflect" "sort" "strings" @@ -391,53 +390,6 @@ func (b *clientBackend) CaddySettings(ctx context.Context) (CaddySettingsRespons return CaddySettingsResponse{Deployed: true, Image: spec.Container.Image, Caddyfile: spec.CaddyConfig()}, nil } -// DeployCaddy rolls out the caddy service with a new image and global -// Caddyfile. Unlike 'uc caddy deploy', it patches the running spec instead of -// rebuilding it, so environment, volumes and placement set through a Compose -// deployment of caddy survive. -func (b *clientBackend) DeployCaddy(ctx context.Context, request DeployCaddyRequest) (<-chan DeployComposeEvent, error) { - spec, err := b.caddySpec(ctx) - switch { - case errors.Is(err, api.ErrNotFound): - // Start from Uncloud's default caddy spec (admin socket, volumes, host ports). - fresh, err := b.Client.Caddy.NewDeployment(ctx, client.CaddyDeploymentOptions{Image: request.Image}) - if err != nil { - return nil, fmt.Errorf("create caddy deployment: %w", err) - } - spec = fresh.Spec - case err != nil: - return nil, fmt.Errorf("inspect caddy service: %w", err) - } - caddyDeploy := b.Client.NewDeployment(patchCaddySpec(spec, request), nil) - - events := make(chan DeployComposeEvent, 16) - go func() { - defer close(events) - runServiceDeployment(ctx, b.Client, caddyDeploy, events) - }() - return events, nil -} - -// patchCaddySpec sets the image and global Caddyfile and merges the request's env, leaving the -// rest of the spec as deployed. -func patchCaddySpec(spec api.ServiceSpec, request DeployCaddyRequest) api.ServiceSpec { - spec.Container.Image = request.Image - if len(request.Env) > 0 { - // Env is a map shared with the caller's spec, so merge into a copy. - env := maps.Clone(spec.Container.Env) - if env == nil { - env = make(map[string]string, len(request.Env)) - } - maps.Copy(env, request.Env) - spec.Container.Env = env - } - spec.Caddy = nil - if request.Caddyfile != "" { - spec.Caddy = &api.CaddySpec{Config: request.Caddyfile} - } - return spec -} - // ListCaddyCertificates reads Caddy's certificate storage from one replica of // the cluster store: the connected machine, or machine when it is set. Stored // certificates that fail to parse are reported in Errors instead of failing diff --git a/apps/sidecar/internal/httpapi/client_backend_test.go b/apps/sidecar/internal/httpapi/client_backend_test.go index 0d28e28b..9a1b7f0b 100644 --- a/apps/sidecar/internal/httpapi/client_backend_test.go +++ b/apps/sidecar/internal/httpapi/client_backend_test.go @@ -118,47 +118,6 @@ func TestImageRemoteReferenceRequiresRepositoryReference(t *testing.T) { require.EqualError(t, err, "image has no repository tag or digest") } -func TestPatchCaddySpecKeepsCustomizations(t *testing.T) { - deployed := api.ServiceSpec{ - Name: "caddy", - Mode: api.ServiceModeGlobal, - Container: api.ContainerSpec{ - Image: "caddy:2.10.0", - Env: map[string]string{"CADDY_ADMIN": "unix//run/caddy/admin.sock", "CF_API_TOKEN": "token"}, - VolumeMounts: []api.VolumeMount{ - {VolumeName: "data", ContainerPath: "/data"}, - }, - }, - Placement: api.Placement{Machines: []string{"edge-1"}}, - Caddy: &api.CaddySpec{Config: "{\n\temail old@example.com\n}"}, - } - - patched := patchCaddySpec(deployed, DeployCaddyRequest{ - Image: "ghcr.io/example/caddy-cloudflare:2.10", Caddyfile: "{\n\temail ops@example.com\n}", - }) - assert.Equal(t, "ghcr.io/example/caddy-cloudflare:2.10", patched.Container.Image) - assert.Equal(t, "{\n\temail ops@example.com\n}", patched.CaddyConfig()) - assert.Equal(t, deployed.Container.Env, patched.Container.Env) - assert.Equal(t, deployed.Container.VolumeMounts, patched.Container.VolumeMounts) - assert.Equal(t, deployed.Placement, patched.Placement) - assert.Equal(t, api.ServiceModeGlobal, patched.Mode) - // The deployed spec is a value, so patching must not touch the caller's copy. - assert.Equal(t, "caddy:2.10.0", deployed.Container.Image) - - cleared := patchCaddySpec(deployed, DeployCaddyRequest{Image: "caddy:2.10.0"}) - assert.Nil(t, cleared.Caddy) - - withEnv := patchCaddySpec(deployed, DeployCaddyRequest{ - Image: "caddy:2.11.7", Env: map[string]string{"OTEL_SERVICE_NAME": "caddy", "CF_API_TOKEN": "new"}, - }) - assert.Equal(t, api.EnvVars{ - "CADDY_ADMIN": "unix//run/caddy/admin.sock", - "CF_API_TOKEN": "new", - "OTEL_SERVICE_NAME": "caddy", - }, withEnv.Container.Env) - assert.Equal(t, "token", deployed.Container.Env["CF_API_TOKEN"]) -} - func mustImageRemoteReference(t *testing.T, images []api.MachineImage) string { t.Helper() diff --git a/apps/sidecar/internal/httpapi/server.go b/apps/sidecar/internal/httpapi/server.go index 68d37f82..aa8ce2f3 100644 --- a/apps/sidecar/internal/httpapi/server.go +++ b/apps/sidecar/internal/httpapi/server.go @@ -24,7 +24,6 @@ import ( scalargo "github.com/bdpiprava/scalar-go" "github.com/danielgtaylor/huma/v2" "github.com/danielgtaylor/huma/v2/adapters/humafiber" - "github.com/distribution/reference" "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/volume" "github.com/gofiber/fiber/v3" @@ -106,7 +105,6 @@ type Backend interface { ListCaddyConfigs(context.Context) (CaddyConfigsResponse, error) ListCaddyCertificates(context.Context, string) (CaddyCertificatesResponse, error) CaddySettings(context.Context) (CaddySettingsResponse, error) - DeployCaddy(context.Context, DeployCaddyRequest) (<-chan DeployComposeEvent, error) ListMachines(context.Context, *api.MachineFilter) ([]api.MachineMember, error) InspectMachine(context.Context, string) (api.MachineMember, error) @@ -563,15 +561,6 @@ func (s *Server) registerOperations(humaAPI huma.API) { OperationID: "getCaddySettings", Method: http.MethodGet, Path: "/api/v1/caddy", Summary: "Get the Caddy image and global Caddyfile", Tags: []string{"cluster"}, }, s.getCaddySettings) - register(humaAPI, huma.Operation{ - OperationID: "deployCaddy", Method: http.MethodPost, Path: "/api/v1/caddy/deploy", - Summary: "Deploy Caddy with an image and global Caddyfile", Tags: []string{"cluster"}, - Description: "Like `uc caddy deploy`, but keeps the rest of the running caddy service spec " + - "(environment, volumes, placement), so a Caddy deployed from Compose keeps its customizations. " + - "An invalid global Caddyfile does not fail the deployment: Caddy keeps its previous config " + - "and the reason shows up as lastReconciliationError in /api/v1/caddy/configs.", - Responses: eventStreamResponse(humaAPI, "Server-Sent deployment events", DeployComposeEvent{}), - }, s.deployCaddy) register(humaAPI, huma.Operation{ OperationID: "listMachines", Method: http.MethodGet, Path: "/api/v1/machines", @@ -836,26 +825,6 @@ func (s *Server) getCaddySettings(ctx context.Context, _ *struct{}) (*bodyOutput return reply(settings), nil } -func (s *Server) deployCaddy(ctx context.Context, input *bodyInput[DeployCaddyRequest]) (*huma.StreamResponse, error) { - request := DeployCaddyRequest{ - Image: strings.TrimSpace(input.Body.Image), - Caddyfile: strings.TrimSpace(input.Body.Caddyfile), - Env: input.Body.Env, - } - if _, err := reference.ParseNormalizedNamed(request.Image); err != nil { - return nil, huma.Error400BadRequest("invalid image reference: " + err.Error()) - } - - streamCtx, cancel := streamContext(ctx) - events, err := s.backend.DeployCaddy(streamCtx, request) - if err != nil { - cancel() - return nil, err - } - - return eventStream(cancel, events, encodeDeployEvent), nil -} - func (s *Server) openapi(c fiber.Ctx) error { c.Set(fiber.HeaderContentType, fiber.MIMEApplicationJSON) return c.Send(s.openapiJSON) diff --git a/apps/sidecar/internal/httpapi/server_test.go b/apps/sidecar/internal/httpapi/server_test.go index 715f7247..6ab9ab41 100644 --- a/apps/sidecar/internal/httpapi/server_test.go +++ b/apps/sidecar/internal/httpapi/server_test.go @@ -106,8 +106,7 @@ type fakeBackend struct { lastComposeDeployment ComposeDeployment spreadErr error - caddySettings CaddySettingsResponse - lastCaddyRequest DeployCaddyRequest + caddySettings CaddySettingsResponse lastCertificatesMachine string } @@ -423,14 +422,6 @@ func (f *fakeBackend) CaddySettings(context.Context) (CaddySettingsResponse, err return f.caddySettings, nil } -func (f *fakeBackend) DeployCaddy(_ context.Context, request DeployCaddyRequest) (<-chan DeployComposeEvent, error) { - f.lastCaddyRequest = request - events := make(chan DeployComposeEvent, 1) - events <- DeployComposeEvent{Type: "complete", DeployStatus: "deployed"} - close(events) - return events, nil -} - // testAuthToken is the bearer token every test server requires. const testAuthToken = "test-token-0123456789" @@ -1186,18 +1177,6 @@ func TestCaddySettingsRoutes(t *testing.T) { response := doRequest(t, server, http.MethodGet, "/api/v1/caddy", nil, "") assert.Equal(t, http.StatusOK, response.StatusCode) assert.Equal(t, fake.caddySettings, decodeResponse[CaddySettingsResponse](t, response)) - - response = doRequest(t, server, http.MethodPost, "/api/v1/caddy/deploy", DeployCaddyRequest{ - Image: " ghcr.io/example/caddy-cloudflare:2.10 ", Caddyfile: "\n{\n\temail ops@example.com\n}\n", - }, "") - assert.Equal(t, http.StatusOK, response.StatusCode) - assert.Contains(t, readBody(t, response), "event: complete") - assert.Equal(t, DeployCaddyRequest{ - Image: "ghcr.io/example/caddy-cloudflare:2.10", Caddyfile: "{\n\temail ops@example.com\n}", - }, fake.lastCaddyRequest) - - response = doRequest(t, server, http.MethodPost, "/api/v1/caddy/deploy", DeployCaddyRequest{Image: "Not An Image"}, "") - assert.Equal(t, http.StatusBadRequest, response.StatusCode) } func TestSpreadServiceRoute(t *testing.T) { diff --git a/apps/sidecar/internal/httpapi/types.go b/apps/sidecar/internal/httpapi/types.go index ec160730..d289caad 100644 --- a/apps/sidecar/internal/httpapi/types.go +++ b/apps/sidecar/internal/httpapi/types.go @@ -113,15 +113,6 @@ type CaddySettingsResponse struct { Caddyfile string `json:"caddyfile" doc:"Global Caddyfile prepended to the generated config (the caddy service's x-caddy)."` } -// DeployCaddyRequest is the desired caddy image and global Caddyfile. Both are -// always sent, so an empty Caddyfile removes the global config. -type DeployCaddyRequest struct { - Image string `json:"image" minLength:"1" maxLength:"512" doc:"Caddy image. Custom images must include curl and start Caddy with /etc/caddy/Caddyfile."` - Caddyfile string `json:"caddyfile" maxLength:"262144" doc:"Global Caddyfile prepended to the generated config. Empty removes it."` - // Env is merged into the deployed environment, so variables set elsewhere survive. - Env map[string]string `json:"env,omitempty" maxProperties:"32" doc:"Environment variables merged into the caddy container's environment."` -} - // CaddyCertificatesResponse lists certificates in Caddy's cluster storage. // Errors holds stored certificates that could not be parsed. type CaddyCertificatesResponse struct { diff --git a/apps/web/package.json b/apps/web/package.json index 933d2f09..c54001ae 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -37,6 +37,7 @@ "@orpc/openapi": "catalog:", "@orpc/server": "catalog:", "@orpc/tanstack-query": "catalog:", + "@regular-ppl/hitbox": "^0.1.0", "@shardsui/svelte": "0.1.0-beta.0", "@tanstack/charts": "^1.0.0", "@tanstack/svelte-query": "^6.1.48", diff --git a/apps/web/src/app.css b/apps/web/src/app.css index 4bb271cd..17fe262a 100644 --- a/apps/web/src/app.css +++ b/apps/web/src/app.css @@ -4,6 +4,7 @@ @import "shadcn-svelte/tailwind.css"; @import "tailwindcss"; @import "tw-animate-css"; +@import "@regular-ppl/hitbox"; @custom-variant dark (&:where(.dark, .dark *)); diff --git a/apps/web/src/lib/components/canvas/controls/add-palette-entries.ts b/apps/web/src/lib/components/canvas/controls/add-palette-entries.ts index 9028b725..ac85329a 100644 --- a/apps/web/src/lib/components/canvas/controls/add-palette-entries.ts +++ b/apps/web/src/lib/components/canvas/controls/add-palette-entries.ts @@ -70,7 +70,8 @@ export type Entry = { | { repository: GitRepository } | { template: Template } | { bucket: { connectionId: string } } - | { volumeService: VolumeTarget }; + | { volumeService: VolumeTarget } + | { dialog: "sandbox" }; }; export const pageTitles: Record = { @@ -112,7 +113,7 @@ function pageEntry(id: AddPage, label: string, icon: Component): Entry { } /** The first page. Volumes and configs need a service to attach to. */ -export function rootEntries(projectId: string, hasVolumeTargets: boolean): Entry[] { +export function rootEntries(hasVolumeTargets: boolean): Entry[] { return [ pageEntry("git", "Git Repository", GitBranch), pageEntry("database", "Database", Database), @@ -129,7 +130,7 @@ export function rootEntries(projectId: string, hasVolumeTargets: boolean): Entry logo: null, icon: Box, provider: undefined, - target: { href: `/projects/${projectId}/create/sandbox` }, + target: { dialog: "sandbox" }, }, { id: "empty", diff --git a/apps/web/src/lib/components/canvas/controls/add-palette.svelte b/apps/web/src/lib/components/canvas/controls/add-palette.svelte index 9dd4b02f..af04708d 100644 --- a/apps/web/src/lib/components/canvas/controls/add-palette.svelte +++ b/apps/web/src/lib/components/canvas/controls/add-palette.svelte @@ -31,6 +31,7 @@ keepPreviousData, } from "@tanstack/svelte-query"; import { + parseAsBoolean, parseAsString, parseAsStringLiteral, useQueryState, @@ -58,6 +59,7 @@ type GitRepository, } from "./add-palette-entries"; import AddPaletteItem from "./add-palette-item.svelte"; + import SandboxDialog from "./sandbox-dialog.svelte"; import { configNodeId, volumeNodeId, @@ -100,6 +102,12 @@ parseAsString.withOptions({ shallow: true, scroll: false }), ); + // The sandbox form, a dialog of its own: too many fields for the palette. + const sandbox = useQueryState( + "addSandbox", + parseAsBoolean.withOptions({ shallow: true, scroll: false }), + ); + // The service a new volume is being attached to, `:`: Railway then asks for // the mount path in the same palette. const volumeKey = useQueryState( @@ -267,7 +275,7 @@ current === "database", ); - return rootEntries(projectId, volumeTargets.length > 0); + return rootEntries(volumeTargets.length > 0); }); const s3Connections = $derived(s3ConnectionsQuery.data ?? []); @@ -616,7 +624,10 @@ if ("page" in target) open(target.page); else if ("href" in target) void goto(target.href); - else if ("create" in target) + else if ("dialog" in target) { + open(null); + void sandbox.set(true); + } else if ("create" in target) void createResource(target.create); else if ("repository" in target) pickRepository(target.repository, null); @@ -871,3 +882,14 @@ {/if} + +{#if sandbox.current} + { + void sandbox.set(null); + void showCreated(resourceId); + }} + onclose={() => void sandbox.set(null)} + /> +{/if} diff --git a/apps/web/src/lib/components/canvas/controls/canvas-context-menu.svelte b/apps/web/src/lib/components/canvas/controls/canvas-context-menu.svelte index 5c8cb07f..72d67e35 100644 --- a/apps/web/src/lib/components/canvas/controls/canvas-context-menu.svelte +++ b/apps/web/src/lib/components/canvas/controls/canvas-context-menu.svelte @@ -62,6 +62,7 @@ import Braces from "phosphor-svelte/lib/BracketsCurlyIcon"; import Zap from "phosphor-svelte/lib/LightningIcon"; import type { Snippet } from "svelte"; + import { parseAsBoolean, useQueryState } from "nuqs-svelte"; import type { AddPage } from "./add-palette.svelte"; import { getCanvasActions } from "../context"; import { parseNodeId } from "../graph"; @@ -94,6 +95,12 @@ const create = $derived(`/projects/${projectId}/create`); + // Opens the add palette's sandbox dialog, which reads the same param. + const addSandbox = useQueryState( + "addSandbox", + parseAsBoolean.withOptions({ shallow: true, scroll: false }), + ); + const resourceId = $derived( target?.kind === "node" ? parseNodeId(target.nodeId).resourceId @@ -428,7 +435,7 @@ void goto(`${create}/sandbox`)} + onclick={() => void addSandbox.set(true)} >