ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.
Python astracloudflarecontrol-panelcyberpaneldnsfablehosting-control-panelhosting-panelkimi-k3server-managementserverkitubuntu-web-panelwebserver
feat(templates): deploy repo templates from the drawer too
Juan Denis29c926ef95cb
diff --git a/frontend/src/pages/Templates.jsx b/frontend/src/pages/Templates.jsxindex c4716430..ec2df5e4 100644--- a/frontend/src/pages/Templates.jsx+++ b/frontend/src/pages/Templates.jsx@@ -212,7 +212,9 @@ const Templates = () => {return;}const template = templates.find(t => t.id === installTemplateId);- if (template && template.kind !== 'repo') {+ // Repo templates are no longer excluded — they deploy from this same+ // drawer, so ?install=<id> works for the whole catalog.+ if (template) {handleViewTemplate(template).then(() => {setShowInstallModal(true);});@@ -396,13 +398,11 @@ const Templates = () => {}// What both a card click and its Deploy button do — one predictable- // outcome per template. Repo templates route to the wizard; compose- // templates open the deploy drawer.+ // outcome for every template, compose or repo. A curated repo template+ // already declares its repo, branch, build method and port, so the+ // detection wizard had nothing left to ask; it deploys from the same+ // drawer as everything else.async function handleDeploy(template) {- if (template.kind === 'repo') {- deployRepoTemplate(template.id);- return;- }if (template.id === 'wordpress') {navigate('/wordpress');return;@@ -705,12 +705,15 @@ const Templates = () => {);};-// Repo-template detail body: repo URL, detected manifests, and env preview from-// the /templates/<id>/manifest endpoint (real inspection or labeled hints).+// The one deploy surface for every template, compose or repo.const InstallModal = ({ template, onClose, onSuccess, renderIcon }) => {const toast = useToast();const navigate = useNavigate();- const [appName, setAppName] = useState(template.id.toLowerCase().replace(/[^a-z0-9-]/g, '-'));+ const isRepo = (template.kind || 'compose') === 'repo';+ const [appName, setAppName] = useState(+ (template.repo?.service_name || template.id).toLowerCase().replace(/[^a-z0-9-]/g, '-'),+ );+ const [branch, setBranch] = useState(template.repo?.branch || 'main');const [variables, setVariables] = useState({});const [servers, setServers] = useState([{ id: 'local', name: 'Local server', is_local: true }]);const [selectedServerId, setSelectedServerId] = useState('local');@@ -765,6 +768,37 @@ const InstallModal = ({ template, onClose, onSuccess, renderIcon }) => {setInstalling(true);setErrors([]);+ // A repo template builds from source rather than composing images, so+ // it goes through createAppFromRepository. Everything that endpoint+ // needs is already declared by the template, which is why this no+ // longer detours through the New Service wizard's detection steps.+ if (isRepo) {+ try {+ const repo = template.repo || {};+ const result = await api.createAppFromRepository({+ name: appName,+ template_id: template.id,+ repo_url: repo.url,+ branch: branch.trim() || repo.branch || 'main',+ app_type: repo.app_type || 'auto',+ build_method: repo.build_method || 'auto',+ port: repo.port ? Number(repo.port) : null,+ auto_deploy: true,+ ingress_plane: 'nginx',+ });+ onClose?.();+ if (result.deploy_job_id) {+ navigate(`/deployments/${result.deploy_job_id}`);+ } else {+ navigate(`/services/${result.app.id}`);+ }+ } catch (err) {+ setErrors([err?.data?.error || err.message || 'Deploy failed']);+ setInstalling(false);+ }+ return;+ }+try {// Validate firstconst validation = await api.validateTemplateInstall(template.id, appName, variables);@@ -838,6 +872,27 @@ const InstallModal = ({ template, onClose, onSuccess, renderIcon }) => {</span></div>+ {/* Repo templates build from source, so the branch is the one+ thing the template cannot decide for you. */}+ {isRepo && (+ <div className="tpl-deploy-drawer__field">+ <label htmlFor="tpl-deploy-branch">Branch</label>+ <div className="tpl-deploy-drawer__input">+ <GitBranch size={15} />+ <input+ id="tpl-deploy-branch"+ type="text"+ value={branch}+ onChange={(e) => setBranch(e.target.value)}+ placeholder="main"+ />+ </div>+ <span className="tpl-deploy-drawer__hint">+ {template.repo?.url || 'Builds from the template repository'}+ </span>+ </div>+ )}+{/* Only shown once a managed-sites base domain exists — withno base there is no subdomain to promise, and a deadfield would be worse than none. */}diff --git a/frontend/src/pages/new-service/ConnectStep.jsx b/frontend/src/pages/new-service/ConnectStep.jsxindex 14c5ca1f..324a22e7 100644--- a/frontend/src/pages/new-service/ConnectStep.jsx+++ b/frontend/src/pages/new-service/ConnectStep.jsx@@ -1,121 +1,19 @@-import { useState } from 'react';import { Link } from 'react-router-dom';import {- FileArchive, GitBranch, Info, Package, RefreshCw, Search, Settings2,+ FileArchive, Info, RefreshCw, Search, Settings2,} from 'lucide-react';import { SiGithub } from 'react-icons/si';import { Button } from '@/components/ui/button';import { Input } from '@/components/ui/input';import { Label } from '@/components/ui/label';-import { Badge } from '@/components/ui/badge';import { SOURCE_NEEDS } from './useNewServiceForm';-// Curated ordering for the gallery: these float to the front (in this order),-// everything else follows alphabetically. `agentsite` is also badged "Featured".-const FEATURED_ORDER = [- 'agentsite', 'wordpress', 'nextcloud', 'grafana', 'portainer',- 'uptime-kuma', 'gitea', 'n8n', 'vaultwarden', 'jellyfin',-];-const FEATURED_BADGE = ['agentsite'];-const COLLAPSED_COUNT = 8; // ~two rows of four before "Show all"--function orderTemplates(list) {- return [...list].sort((a, b) => {- const ai = FEATURED_ORDER.indexOf(a.id);- const bi = FEATURED_ORDER.indexOf(b.id);- const aw = ai === -1 ? 999 : ai;- const bw = bi === -1 ? 999 : bi;- if (aw !== bw) return aw - bw;- return (a.name || '').localeCompare(b.name || '');- });-}--// Template icon with a graceful fallback to a Package glyph if the inline/URL-// icon is missing or fails to load.-const TemplateIcon = ({ template }) => {- const [failed, setFailed] = useState(false);- if (template.icon && !failed) {- return <img src={template.icon} alt="" onError={() => setFailed(true)} />;- }- return <Package size={20} />;-};--// A mini app gallery: icon + title tiles, ~4 across. Collapsed to two rows;-// "Show all" expands into a scrollable, searchable grid.-const TemplateGallery = ({ templates, loading, selectedId, onPick }) => {- const [expanded, setExpanded] = useState(false);- const [query, setQuery] = useState('');-- if (loading) {- return <div className="new-service-page__repo-state">Loading templates…</div>;- }- if (!templates.length) {- return <div className="new-service-page__repo-state">No templates available yet.</div>;- }-- const q = query.trim().toLowerCase();- const filtered = orderTemplates(templates).filter(t => !q- || (t.name || '').toLowerCase().includes(q)- || (t.description || '').toLowerCase().includes(q)- || (t.categories || []).some(c => c.toLowerCase().includes(q)));- const visible = expanded ? filtered : filtered.slice(0, COLLAPSED_COUNT);- const hiddenCount = filtered.length - visible.length;-- return (- <div className="new-service-page__tpl-gallery">- {expanded && (- <div className="new-service-page__tpl-gallery-search">- <Search size={16} />- <Input- value={query}- onChange={(e) => setQuery(e.target.value)}- placeholder="Search templates…"- autoFocus- />- </div>- )}- <div className={`new-service-page__tpl-gallery-grid ${expanded ? 'new-service-page__tpl-gallery-grid--scroll' : ''}`}>- {visible.map(template => (- <button- key={template.id}- type="button"- title={template.description || template.name}- className={`new-service-page__tpl-tile ${selectedId === template.id ? 'new-service-page__tpl-tile--active' : ''}`}- onClick={() => onPick(template)}- >- {FEATURED_BADGE.includes(template.id) && (- <Badge variant="info" className="new-service-page__tpl-tile-badge">Featured</Badge>- )}- <span className="new-service-page__tpl-tile-icon">- <TemplateIcon template={template} />- </span>- <span className="new-service-page__tpl-tile-name">{template.name}</span>- </button>- ))}- {visible.length === 0 && (- <div className="new-service-page__repo-state">No templates match “{query}”.</div>- )}- </div>- {(hiddenCount > 0 || expanded) && (- <button- type="button"- className="new-service-page__tpl-gallery-toggle"- onClick={() => setExpanded(x => !x)}- >- {expanded ? 'Show less' : `Show all ${filtered.length} templates`}- </button>- )}- </div>- );-};-// Step 2 — Connect. Only the source-specific input, plus the editable detected// service name + branch shown inline (not buried in Advanced).const ConnectStep = ({ form }) => {const {- sourceMode, selectSource, githubConnection, githubConfigured, reposLoading, repos, repoSearch,+ sourceMode, githubConnection, githubConfigured, reposLoading, repos, repoSearch,setRepoSearch, selectedRepo, setSelectedRepo, loadGithubRepos, handleConnectGithub,- templates, templatesLoading, selectedTemplate, pickTemplate,manualRepoUrl, handleManualRepoChange, localPath, setLocalPath, composeFile,setComposeFile, systemdUnit, setSystemdUnit, managedBy, setManagedBy,uploadFile, onUploadFile, uploadDragOver, setUploadDragOver,@@ -129,7 +27,6 @@ const ConnectStep = ({ form }) => {<div className="new-service-page__step-head"><h2>{sourceMode === 'github' ? 'Pick a repository'- : sourceMode === 'template' ? 'Choose a template': sourceMode === 'local' ? 'Point at the service': sourceMode === 'upload' ? 'Upload the archive': 'Connect the remote'}@@ -219,31 +116,6 @@ const ConnectStep = ({ form }) => {</div>)}- {sourceMode === 'template' && (- <div className="new-service-page__pane">- <TemplateGallery- templates={templates}- loading={templatesLoading}- selectedId={selectedTemplate?.id}- onPick={pickTemplate}- />-- {/* Bring your own — no curated entry needed. Any repo with a- serverkit.yml / Docker Compose / Dockerfile deploys the same- way; this switches to the Git-remote input in place. */}- <div className="new-service-page__byo">- <div>- <strong>Bring your own manifest</strong>- <span>Deploy any Git repo that ships a serverkit.yml, Docker Compose, or Dockerfile — we detect it for you.</span>- </div>- <Button type="button" variant="outline" onClick={() => selectSource('manual')}>- <GitBranch size={16} />- Use a repo URL- </Button>- </div>- </div>- )}-{sourceMode === 'local' && (<div className="new-service-page__pane"><div className="new-service-page__field">diff --git a/frontend/src/pages/new-service/SourceStep.jsx b/frontend/src/pages/new-service/SourceStep.jsxindex c5ac8d54..bf74b475 100644--- a/frontend/src/pages/new-service/SourceStep.jsx+++ b/frontend/src/pages/new-service/SourceStep.jsx@@ -1,13 +1,17 @@-import { GitBranch, FolderOpen, FileArchive, Package } from 'lucide-react';+import { GitBranch, FolderOpen, FileArchive } from 'lucide-react';import { SiGithub } from 'react-icons/si';-// Step 1 — Source. Five clean radio-cards; selecting one advances to Connect.+// Step 1 — Source. Four clean radio-cards; selecting one advances to Connect.+//+// No "Deploy Template" card: a curated template already declares its repo,+// branch, build method and port, so this wizard's detect-and-confirm steps had+// nothing left to ask. Templates deploy from the drawer on /templates, which is+// also what their cards and Deploy buttons open — one surface, not two.const SOURCES = [{ mode: 'github', Icon: SiGithub, title: 'GitHub', sub: 'Connect with OAuth and choose a repository' },{ mode: 'manual', Icon: GitBranch, title: 'Other Git Remote', sub: 'GitLab, Bitbucket, Gitea, or SSH' },{ mode: 'local', Icon: FolderOpen, title: 'Manual / Local', sub: 'Register an app already on the server' },{ mode: 'upload', Icon: FileArchive, title: 'Upload ZIP', sub: 'Deploy or update from a zip archive' },- { mode: 'template', Icon: Package, title: 'Deploy Template', sub: 'Fast import from a curated repo template' },];const SourceStep = ({ form }) => {diff --git a/frontend/src/pages/new-service/useNewServiceForm.js b/frontend/src/pages/new-service/useNewServiceForm.jsindex 1a812f22..a0d4553e 100644--- a/frontend/src/pages/new-service/useNewServiceForm.js+++ b/frontend/src/pages/new-service/useNewServiceForm.js@@ -29,7 +29,6 @@ export const SOURCE_NEEDS = {manual: 'The repository URL, plus a deploy key or credentials if it is private.',local: 'The path on the server, and its compose file or systemd unit if any.',upload: 'A .zip of the project (with a Dockerfile/compose or a detectable runtime).',- template: 'A curated repo template — its manifests prefill the deploy for you.',};export function slugify(value) {@@ -59,24 +58,6 @@ export function formatBuildMethod(value) {return BUILD_METHOD_LABELS[value] || value || 'Auto build';}-// Map an API template detail object (kind: repo) to the flat fields the wizard-// prefills. Keeps the create-payload contract identical to before.-function templateFields(template) {- const repo = template.repo || {};- return {- id: template.id,- name: template.name,- serviceName: repo.service_name || template.id,- description: template.description,- repoUrl: repo.url,- branch: repo.branch || 'main',- appType: repo.app_type || 'auto',- buildMethod: repo.build_method || 'auto',- port: repo.port || null,- categories: template.categories || [],- };-}-/*** All state, derived values, and handlers for the New Service wizard. Kept in a* hook so the page component is just step orchestration + submit, and the step@@ -97,13 +78,6 @@ export function useNewServiceForm() {const [repoSearch, setRepoSearch] = useState('');const [selectedRepo, setSelectedRepo] = useState(null);- // Repo-kind deploy templates, fetched from the backend catalog.- const [templates, setTemplates] = useState([]);- const [templatesLoading, setTemplatesLoading] = useState(false);- const [selectedTemplate, setSelectedTemplate] = useState(null);- const [templateManifest, setTemplateManifest] = useState(null);- const [templateManifestLoading, setTemplateManifestLoading] = useState(false);-const [branches, setBranches] = useState([]);const [branchesLoading, setBranchesLoading] = useState(false);const [repoManifest, setRepoManifest] = useState(null);@@ -142,40 +116,33 @@ export function useNewServiceForm() {const githubConfigured = githubStatus?.configured;const normalizedManualRepo = useMemo(() => normalizeManualRepo(manualRepoUrl), [manualRepoUrl]);- const activeManifest = sourceMode === 'template' ? templateManifest : repoManifest;- const activeManifestLoading = sourceMode === 'template' ? templateManifestLoading : repoManifestLoading;+ const activeManifest = repoManifest;+ const activeManifestLoading = repoManifestLoading;const recommended = activeManifest?.recommended || {};const detectedServiceName = useMemo(() => {- if (sourceMode === 'template' && selectedTemplate) {- return slugify(selectedTemplate.serviceName || selectedTemplate.name || '');- }if (sourceMode === 'github' && selectedRepo) return slugify(selectedRepo.name || '');return repoNameFromUrl(normalizedManualRepo);- }, [normalizedManualRepo, selectedRepo, selectedTemplate, sourceMode]);+ }, [normalizedManualRepo, selectedRepo, sourceMode]);const serviceName = nameTouched ? name : detectedServiceName;const canSubmit = sourceMode === 'github'? Boolean(githubConnection && selectedRepo && serviceName?.length >= 2)- : sourceMode === 'template'- ? Boolean(selectedTemplate && serviceName?.length >= 2)- : sourceMode === 'local'- ? Boolean(serviceName?.length >= 2 && localPath?.length >= 1)- : sourceMode === 'upload'- ? Boolean(serviceName?.length >= 2 && uploadFile)- : Boolean(normalizedManualRepo && serviceName?.length >= 2);+ : sourceMode === 'local'+ ? Boolean(serviceName?.length >= 2 && localPath?.length >= 1)+ : sourceMode === 'upload'+ ? Boolean(serviceName?.length >= 2 && uploadFile)+ : Boolean(normalizedManualRepo && serviceName?.length >= 2);// Whether step 2 (Connect) has enough input to move on to Review.const canProceedFromConnect = sourceMode === 'github'? Boolean(githubConnection && selectedRepo)- : sourceMode === 'template'- ? Boolean(selectedTemplate)- : sourceMode === 'local'- ? Boolean(localPath?.length >= 1)- : sourceMode === 'upload'- ? Boolean(uploadFile)- : Boolean(normalizedManualRepo);+ : sourceMode === 'local'+ ? Boolean(localPath?.length >= 1)+ : sourceMode === 'upload'+ ? Boolean(uploadFile)+ : Boolean(normalizedManualRepo);const buildSummary = buildMethod === 'auto' && recommended.build_method? `Auto → ${formatBuildMethod(recommended.build_method)}`@@ -186,7 +153,7 @@ export function useNewServiceForm() {|| (sourceMode === 'local' && managedBy === 'docker_compose');const buildpackEligible = (buildMethod === 'auto' || buildMethod === 'nixpacks')- && (sourceMode === 'github' || sourceMode === 'manual' || sourceMode === 'template');+ && (sourceMode === 'github' || sourceMode === 'manual');const loadGithubStatus = useCallback(async () => {try {@@ -222,22 +189,7 @@ export function useNewServiceForm() {}}, [toast]);- // The template gallery shows the FULL catalog (repo + one-click compose), so- // the picker feels like a real app gallery rather than a single row.- const loadTemplates = useCallback(async () => {- setTemplatesLoading(true);- try {- const data = await api.listTemplates();- setTemplates(data.templates || []);- } catch (err) {- setTemplates([]);- } finally {- setTemplatesLoading(false);- }- }, []);-useEffect(() => { loadGithubStatus(); }, [loadGithubStatus]);- useEffect(() => { loadTemplates(); }, [loadTemplates]);useEffect(() => {if (!ingressProxyEligible && ingressPlane !== 'nginx') {@@ -295,7 +247,7 @@ export function useNewServiceForm() {useEffect(() => {if (sourceMode !== 'github' || !selectedRepo) {- if (sourceMode !== 'template') setRepoManifest(null);+ setRepoManifest(null);setRepoManifestLoading(false);return undefined;}@@ -337,8 +289,6 @@ export function useNewServiceForm() {body.source_connection_id = githubConnection.id;body.repository_full_name = selectedRepo.full_name;body.repo_url = `https://github.com/${selectedRepo.full_name}.git`;- } else if (sourceMode === 'template' && selectedTemplate) {- body.repo_url = selectedTemplate.repoUrl;} else if (sourceMode === 'manual' && normalizedManualRepo) {body.repo_url = normalizedManualRepo;} else {@@ -354,7 +304,7 @@ export function useNewServiceForm() {.finally(() => { if (!cancelled) setBuildpackLoading(false); });return () => { cancelled = true; };// eslint-disable-next-line react-hooks/exhaustive-deps- }, [buildpackEligible, sourceMode, selectedRepo, selectedTemplate, normalizedManualRepo, branch, githubConnection]);+ }, [buildpackEligible, sourceMode, selectedRepo, normalizedManualRepo, branch, githubConnection]);async function handleConnectGithub() {try {@@ -373,55 +323,7 @@ export function useNewServiceForm() {if (mode === 'upload') setAppType('auto');}- // Apply a repo-kind template (API detail object) to the flat wizard fields- // and fetch its live/hinted manifest for the review step.- const selectTemplate = useCallback((templateDetail) => {- const fields = templateFields(templateDetail);- setSelectedTemplate(fields);- setSelectedRepo(null);- setManualRepoUrl(fields.repoUrl || '');- setName(slugify(fields.serviceName || fields.name || ''));- setNameTouched(false);- setBranch(fields.branch || 'main');- setAppType(fields.appType || 'auto');- setBuildMethod(fields.buildMethod || 'auto');- setPort(fields.port ? String(fields.port) : '');- setAutoDeploy(true);-- setTemplateManifest(null);- setTemplateManifestLoading(true);- api.inspectTemplateManifest(fields.id, fields.branch)- .then((data) => setTemplateManifest(data?.manifest || null))- .catch(() => setTemplateManifest(null))- .finally(() => setTemplateManifestLoading(false));- }, []);-// Pick a template by id (deep link or list click): fetch its detail, then apply.- const selectTemplateById = useCallback(async (templateId) => {- try {- const result = await api.getTemplate(templateId);- if (result?.template) {- setSourceMode('template');- selectTemplate(result.template);- return true;- }- } catch (err) {- toast.error(err.message || 'Failed to load template');- }- return false;- }, [selectTemplate, toast]);-- // Pick a template from the gallery. Repo templates continue in the wizard- // (they deploy from their Git repo); one-click compose templates route to- // their install flow on the Templates page, which is their real deploy path.- const pickTemplate = useCallback((template) => {- if ((template.kind || 'compose') === 'repo') {- selectTemplateById(template.id);- } else {- navigate(`/templates?install=${encodeURIComponent(template.id)}`);- }- }, [selectTemplateById, navigate]);-function handleManualRepoChange(value) {setManualRepoUrl(value);if (!nameTouched) setName(repoNameFromUrl(normalizeManualRepo(value)));@@ -438,16 +340,20 @@ export function useNewServiceForm() {if (!nameTouched) setName(slugify(file.name.replace(/\.zip$/i, '')));}- // Deep links: /services/new?template=<id> or ?source=<mode> land preloaded on- // the Connect step. Runs once on mount.+ // Deep links: ?source=<mode> lands preloaded on the Connect step. Runs once+ // on mount.+ //+ // ?template=<id> is kept working but forwarded: templates now deploy from+ // the drawer on /templates, so an old link lands on the same surface the+ // catalog's own cards open rather than a second, different one.useEffect(() => {const templateId = searchParams.get('template');const source = searchParams.get('source');if (templateId) {- selectTemplateById(templateId).then((ok) => { if (ok) setStep(2); });+ navigate(`/templates?install=${encodeURIComponent(templateId)}`, { replace: true });return;}- if (source && ['github', 'manual', 'local', 'upload', 'template'].includes(source)) {+ if (source && ['github', 'manual', 'local', 'upload'].includes(source)) {selectSource(source);setStep(2);}@@ -528,9 +434,6 @@ export function useNewServiceForm() {payload.source_connection_id = githubConnection.id;payload.repository_full_name = selectedRepo.full_name;payload.repo_url = `https://github.com/${selectedRepo.full_name}.git`;- } else if (sourceMode === 'template') {- payload.template_id = selectedTemplate.id;- payload.repo_url = selectedTemplate.repoUrl;} else {payload.repo_url = normalizedManualRepo;}@@ -563,8 +466,6 @@ export function useNewServiceForm() {githubStatus, githubConnection, githubConfigured,repos, reposLoading, repoSearch, setRepoSearch, selectedRepo, setSelectedRepo,loadGithubRepos, handleConnectGithub, branches, branchesLoading,- // templates- templates, templatesLoading, selectedTemplate, selectTemplate, selectTemplateById, pickTemplate,// manual / local / uploadmanualRepoUrl, handleManualRepoChange, normalizedManualRepo,localPath, setLocalPath, composeFile, setComposeFile,