Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/docs/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion apps/docs/content/docs/(guide)/quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
41 changes: 0 additions & 41 deletions apps/docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
48 changes: 0 additions & 48 deletions apps/sidecar/internal/httpapi/client_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/hex"
"errors"
"fmt"
"maps"
"reflect"
"sort"
"strings"
Expand Down Expand Up @@ -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
Expand Down
41 changes: 0 additions & 41 deletions apps/sidecar/internal/httpapi/client_backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
31 changes: 0 additions & 31 deletions apps/sidecar/internal/httpapi/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand Down
23 changes: 1 addition & 22 deletions apps/sidecar/internal/httpapi/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ type fakeBackend struct {
lastComposeDeployment ComposeDeployment
spreadErr error

caddySettings CaddySettingsResponse
lastCaddyRequest DeployCaddyRequest
caddySettings CaddySettingsResponse

lastCertificatesMachine string
}
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 0 additions & 9 deletions apps/sidecar/internal/httpapi/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 *));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ export type Entry = {
| { repository: GitRepository }
| { template: Template }
| { bucket: { connectionId: string } }
| { volumeService: VolumeTarget };
| { volumeService: VolumeTarget }
| { dialog: "sandbox" };
};

export const pageTitles: Record<AddPage, string> = {
Expand Down Expand Up @@ -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),
Expand All @@ -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",
Expand Down
Loading
Loading