diff --git a/DESIGN.md b/DESIGN.md
index fa10c50db..9a656f28f 100644
--- a/DESIGN.md
+++ b/DESIGN.md
@@ -12,7 +12,7 @@ This file collects architecture and design notes for studio that aren't otherwis
- [`src/features/instance/databases/DESIGN.md`](src/features/instance/databases/DESIGN.md) — when the browse grid may show its spinner, and why a table without a primary key can't be listed.
-- [`src/features/instance/applications/DESIGN.md`](src/features/instance/applications/DESIGN.md) — when a rolling deploy is done: following its restart job, and why a job Studio can't follow is never a success.
+- [`src/features/instance/applications/DESIGN.md`](src/features/instance/applications/DESIGN.md) — when a rolling deploy is done: following its restart job, and why a job Studio can't follow is never a success; and when a live deploy may be sent again.
- [`src/features/instance/config/roles/DESIGN.md`](src/features/instance/config/roles/DESIGN.md) — why the role editor's JSON text is the only source of truth, what forces the JSON view, and what Save changes on purpose.
- [`src/router/DESIGN.md`](src/router/DESIGN.md) — why a failed route load is reported and shown only by its route, and why a preload still toasts.
diff --git a/src/features/instance/applications/DESIGN.md b/src/features/instance/applications/DESIGN.md
index 95b77130f..e58317fc0 100644
--- a/src/features/instance/applications/DESIGN.md
+++ b/src/features/instance/applications/DESIGN.md
@@ -31,3 +31,27 @@ node the job could not reach is listed with its error and the job still complete
Canary certification is shown only when the response carries it, which only 5.4+ does. There is no version check on
the deploy path: `registration_info` is denied to a role with an operations allowlist, which is exactly the kind of
role that may be allowed to deploy, so a version gate there would hide the result from it.
+
+## Staging and activation are gated the other way
+
+Stage only (`activate: false`) and Activate (`deployment_id`) are offered only when `registration_info` reads 5.3.0 or
+later (`useStagedDeploymentsAvailable`), and an unreadable version offers neither. The difference from certification is
+what happens when the guess is wrong: a node older than 5.3.0 accepts `activate: false` as an unknown field and makes
+the release live, which is the opposite of what the person asked for. Certification only adds a field to a response.
+
+All three kinds of request are built in one place, [`deployRequestBody`](../../../integrations/api/instance/applications/deployComponent.ts),
+because Harper's validator refuses the wrong mix outright: a stage with `restart`, or an activation carrying `package`,
+install options or `activate`. A stage succeeds only once every other node confirmed staging it, so a stage restarts
+nothing and is reported without a health check. Rollback to a kept release (#1232) is the same activation call.
+
+## A live deploy is sent once
+
+A live (SSE) deploy that gets no event stream goes out again as the buffered POST only when its status proves Harper
+never started it: a 4xx. Harper refuses a request before the operation starts (authentication, permissions,
+validation) with a 4xx, and answers one it started with a 200 event stream at once. Everything else can follow a deploy
+that is already running: a gateway's 5xx after forwarding, a 2xx that is not a stream, a dropped connection, the idle
+watchdog firing before headers. Harper's own request-queue 503 never started anything either, but status alone cannot
+tell it from a gateway's. So [`onDeployComponentSubmit`](../../../integrations/api/instance/applications/deployComponent.ts)
+turns those into `SSEInconclusiveError`, which every deploy caller already answers by checking rather than resending.
+`streamOperation` stays neutral: it puts the `status` on `SSEUnsupportedError` and leaves the decision to the caller,
+because a read (`get_deployment`) may fall back on anything.
diff --git a/src/features/instance/applications/components/ContentActions.tsx b/src/features/instance/applications/components/ContentActions.tsx
index 6638d13dd..39fd53629 100644
--- a/src/features/instance/applications/components/ContentActions.tsx
+++ b/src/features/instance/applications/components/ContentActions.tsx
@@ -16,10 +16,16 @@ import { useEditorFileContent } from '@/features/instance/applications/context/e
import { isDirectory } from '@/features/instance/applications/context/isDirectory';
import { useEditorView } from '@/features/instance/applications/hooks/useEditorView';
import { useEntryActions } from '@/features/instance/applications/hooks/useEntryActions';
-import { useInstanceBrowseManagePermission } from '@/hooks/usePermissions';
+import {
+ useDeploymentsAvailable,
+ useStagedDeploymentsAvailable,
+} from '@/features/instance/applications/hooks/useSupportsDeploymentSSE';
+import { useInstanceBrowseManagePermission, useInstanceManagePermission } from '@/hooks/usePermissions';
import { useRestartInstanceClick } from '@/hooks/useRestartInstanceClick';
import { emitToListeners, useEmitToListeners } from '@/lib/events/listener';
import { useSetWatchedValue, useWatchedValue } from '@/lib/events/watcher';
+import { buildAbsoluteLinkToPage } from '@/lib/urls/buildAbsoluteLinkToPage';
+import { useNavigate, useParams } from '@tanstack/react-router';
import {
ArrowLeftIcon,
ArrowRightIcon,
@@ -28,12 +34,14 @@ import {
DownloadIcon,
FilePlusIcon,
FolderPlusIcon,
+ HistoryIcon,
LockIcon,
PackageIcon,
PanelRightCloseIcon,
PanelRightOpenIcon,
PencilIcon,
PlusIcon,
+ RocketIcon,
RotateCcwIcon,
SaveIcon,
TrashIcon,
@@ -73,6 +81,14 @@ export function ContentActions({
const { openedEntryContents, openedEntry, isSavingFile, restrictPackageModification } = useEditorView();
const { content: updatedFileContent } = useEditorFileContent(openedEntry?.path);
const canManageBrowseInstance = useInstanceBrowseManagePermission();
+ const canManageInstance = useInstanceManagePermission();
+ const deploymentsAvailable = useDeploymentsAvailable();
+ const stagingAvailable = useStagedDeploymentsAvailable();
+ const canViewDeployments = canManageInstance && deploymentsAvailable;
+ const navigate = useNavigate();
+ const routeParams: { clusterId?: string; instanceId?: string; organizationId?: string } = useParams({
+ strict: false,
+ });
const { onRestartClick, isRestartPending } = useRestartInstanceClick({
operation: 'restart_service',
instanceClient: instanceParams.instanceClient,
@@ -133,7 +149,8 @@ export function ContentActions({
useEntryActions(openedEntry);
const showFileMenu = canEditFile || canRename || canAddEntries || canAddTable || canDeleteEntry;
- const showApplicationMenu = canDownload || canManageBrowseInstance || canRedeploy;
+ const deploymentsProject = canViewDeployments && openedEntry?.project ? openedEntry.project : undefined;
+ const showApplicationMenu = canDownload || canManageBrowseInstance || canRedeploy || !!deploymentsProject;
// The "File" menu acts on whatever is selected, so name it for that thing.
const fileMenuLabel = openedEntry && isDirectory(openedEntry) ? 'Directory' : 'File';
@@ -389,6 +406,30 @@ export function ContentActions({
Redeploy Package
)}
+ {deploymentsProject && (
+
+ void navigate({
+ to: buildAbsoluteLinkToPage(routeParams, 'config/deployments'),
+ search: { project: deploymentsProject },
+ })}
+ >
+
+ View Deployments
+
+ )}
+ {deploymentsProject && stagingAvailable && (
+
+ void navigate({
+ to: buildAbsoluteLinkToPage(routeParams, 'config/deployments'),
+ search: { project: deploymentsProject, status: 'staged' },
+ })}
+ >
+
+ Staged Releases
+
+ )}
)}
diff --git a/src/features/instance/applications/components/DeployProgress/DeployProgress.test.tsx b/src/features/instance/applications/components/DeployProgress/DeployProgress.test.tsx
index 70f582348..fb867318e 100644
--- a/src/features/instance/applications/components/DeployProgress/DeployProgress.test.tsx
+++ b/src/features/instance/applications/components/DeployProgress/DeployProgress.test.tsx
@@ -119,6 +119,20 @@ describe('DeployProgress canary certification (Harper 5.4+)', () => {
});
});
+describe('DeployProgress staging (Harper 5.3+)', () => {
+ it('ends a stage at Staged, with no restart', () => {
+ render(
+ ,
+ );
+ expect(screen.getByText('Staged')).toBeTruthy();
+ expect(screen.queryByText('Restart')).toBeNull();
+ expect(screen.queryByText('Finish')).toBeNull();
+ });
+});
+
describe('DeployProgress warnings and rollout', () => {
it('keeps the warnings the deploy streamed', () => {
render();
diff --git a/src/features/instance/applications/components/DeployProgress/DeployProgress.tsx b/src/features/instance/applications/components/DeployProgress/DeployProgress.tsx
index 40c517ccc..bec4f3674 100644
--- a/src/features/instance/applications/components/DeployProgress/DeployProgress.tsx
+++ b/src/features/instance/applications/components/DeployProgress/DeployProgress.tsx
@@ -2,7 +2,7 @@ import { Badge } from '@/components/ui/badge';
import { ScrollArea } from '@/components/ui/scrollArea';
import { Separator } from '@/components/ui/separator';
import { deploymentRecordPath } from '@/features/instance/applications/hooks/useDeploymentRecordAction';
-import { DEPLOY_PHASE_ORDER } from '@/integrations/api/instance/applications/deployComponentStream';
+import { DEPLOY_PHASE_ORDER, STAGE_PHASE_ORDER } from '@/integrations/api/instance/applications/deployComponentStream';
import { CertificationDecision } from '@/integrations/api/instance/applications/deployOutcome';
import { RolloutNode, RolloutSnapshot } from '@/integrations/api/instance/applications/restartJob';
import { cn } from '@/lib/cn';
@@ -33,6 +33,7 @@ const PHASE_LABELS: Record = {
replicate: 'Replicate',
restart: 'Restart',
success: 'Finish',
+ staged: 'Staged',
};
/**
@@ -62,10 +63,12 @@ function PhaseIcon({ status, isCurrent }: { status?: PhaseStatus; isCurrent: boo
export function DeployProgress({
state,
onNavigateAway,
+ staging = false,
}: {
state: DeploymentStreamState;
/** Called when a guidance link navigates away — lets a hosting modal close itself first. */
onNavigateAway?: () => void;
+ staging?: boolean;
}) {
const logEndRef = useRef(null);
const params: { clusterId?: string; instanceId?: string; organizationId?: string } = useParams({ strict: false });
@@ -79,7 +82,7 @@ export function DeployProgress({
return (
- {DEPLOY_PHASE_ORDER.map((phase) => {
+ {(staging ? STAGE_PHASE_ORDER : DEPLOY_PHASE_ORDER).map((phase) => {
const status = state.phases[phase];
const isCurrent = state.currentPhase === phase && status !== 'done';
return (
diff --git a/src/features/instance/applications/components/NewApplication/ImportInstructions.tsx b/src/features/instance/applications/components/NewApplication/ImportInstructions.tsx
index 4399f8c89..a63381c2d 100644
--- a/src/features/instance/applications/components/NewApplication/ImportInstructions.tsx
+++ b/src/features/instance/applications/components/NewApplication/ImportInstructions.tsx
@@ -1,13 +1,16 @@
import { Button } from '@/components/ui/button';
import { CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import { FormControl } from '@/components/ui/form/FormControl';
+import { FormDescription } from '@/components/ui/form/FormDescription';
import { FormField } from '@/components/ui/form/FormField';
import { FormItem } from '@/components/ui/form/FormItem';
import { FormLabel } from '@/components/ui/form/FormLabel';
import { FormMessage } from '@/components/ui/form/FormMessage';
import { Input } from '@/components/ui/input';
import { Separator } from '@/components/ui/separator';
+import { Switch } from '@/components/ui/switch';
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
+import { useStagedDeploymentsAvailable } from '@/features/instance/applications/hooks/useSupportsDeploymentSSE';
import { GitMergeIcon, LinkIcon, PackageIcon, RocketIcon } from 'lucide-react';
import { useCallback } from 'react';
import { Control, FormState, UseFormSetValue, UseFormWatch } from 'react-hook-form';
@@ -29,6 +32,7 @@ export function ImportInstructions({
watch: UseFormWatch>;
}) {
const importSource = watch('contents.source');
+ const canStage = useStagedDeploymentsAvailable();
const setImportSource = useCallback((source: string) => {
setValue('contents.source', source as 'git' | 'npm' | 'tarball');
}, [setValue]);
@@ -154,6 +158,26 @@ export function ImportInstructions({
{importSource === 'git' && }
+ {canStage && (
+ (
+
+
+
+
+
+ Stage only
+
+ Install it on every node without making it live. Activate it later from Deployments.
+
+
+
+ )}
+ />
+ )}
+
>
diff --git a/src/features/instance/applications/components/NewApplication/NewApplication.test.tsx b/src/features/instance/applications/components/NewApplication/NewApplication.test.tsx
index b2d2f39bf..fb44778fe 100644
--- a/src/features/instance/applications/components/NewApplication/NewApplication.test.tsx
+++ b/src/features/instance/applications/components/NewApplication/NewApplication.test.tsx
@@ -21,6 +21,9 @@ vi.mock('./useCheckCLI', () => ({ useCheckCLI: () => ({ checkCLI: vi.fn() }) }))
// These read the instance's SSH keys and auth, which aren't what these tests exercise.
vi.mock('./ImportAuthorization', () => ({ ImportAuthorization: () => null }));
vi.mock('./useCLISteps', () => ({ useCLISteps: () => [] }));
+vi.mock('@/features/instance/applications/hooks/useSupportsDeploymentSSE', () => ({
+ useStagedDeploymentsAvailable: () => false,
+}));
import { NewApplication } from './index';
diff --git a/src/features/instance/applications/components/NewApplication/schema.ts b/src/features/instance/applications/components/NewApplication/schema.ts
index 70c1d1d9f..d55d7da44 100644
--- a/src/features/instance/applications/components/NewApplication/schema.ts
+++ b/src/features/instance/applications/components/NewApplication/schema.ts
@@ -20,6 +20,7 @@ export const ImportSchema = z.object({
// The SSH key the import URL is expected to use. Form-only state used to verify the URL's host
// — it is not sent to deploy_component (the backend resolves the key from the URL host alias).
sshKeyName: z.string(),
+ stageOnly: z.boolean(),
});
export const defaultImportOptions: z.infer = {
@@ -29,6 +30,7 @@ export const defaultImportOptions: z.infer = {
requiresAuth: false,
installCommand: '',
sshKeyName: '',
+ stageOnly: false,
};
export const CLISchema = z.object({
diff --git a/src/features/instance/applications/components/NewApplication/useImportApplication.ts b/src/features/instance/applications/components/NewApplication/useImportApplication.ts
index 30f6cccb7..156156d32 100644
--- a/src/features/instance/applications/components/NewApplication/useImportApplication.ts
+++ b/src/features/instance/applications/components/NewApplication/useImportApplication.ts
@@ -2,8 +2,11 @@ import { useInstanceClientIdParams } from '@/config/useInstanceClient';
import { useComponentHealthCheck } from '@/features/instance/applications/hooks/useComponentHealthCheck';
import { useDeploymentRecordAction } from '@/features/instance/applications/hooks/useDeploymentRecordAction';
import { useEditorView } from '@/features/instance/applications/hooks/useEditorView';
-import { useSupportsDeploymentSSE } from '@/features/instance/applications/hooks/useSupportsDeploymentSSE';
-import { reportDeployOutcome } from '@/features/instance/applications/modals/reportDeployHealth';
+import {
+ useStagedDeploymentsAvailable,
+ useSupportsDeploymentSSE,
+} from '@/features/instance/applications/hooks/useSupportsDeploymentSSE';
+import { reportDeployOutcome, reportStaged } from '@/features/instance/applications/modals/reportDeployHealth';
import { useDeployComponentMutation } from '@/integrations/api/instance/applications/deployComponent';
import { deployFailureDetails } from '@/integrations/api/instance/applications/deployOutcome';
import { DeployRolloutError } from '@/integrations/api/instance/applications/restartJob';
@@ -31,6 +34,7 @@ export function useImportApplication(
const queryClient = useQueryClient();
const instanceParams = useInstanceClientIdParams();
const sseDeploy = useSupportsDeploymentSSE();
+ const canStage = useStagedDeploymentsAvailable();
const runHealthCheck = useComponentHealthCheck(instanceParams);
const recordAction = useDeploymentRecordAction();
const { reloadRootEntries, setFocusedItem, setExpandedItems, setSelectedItems } = useEditorView();
@@ -59,32 +63,36 @@ export function useImportApplication(
contents: z.infer;
project: string;
}) => {
- const toastId = toast.loading(`Importing application...`, {
+ const stage = canStage && contents.stageOnly;
+ const toastId = toast.loading(stage ? 'Staging application...' : 'Importing application...', {
description: 'This may take a bit.',
duration: 300_000,
});
mutate({
- applicationName: project,
- applicationUrl: contents.ref,
- installCommand: contents.installCommand,
+ request: {
+ kind: stage ? 'stage' : 'deploy',
+ project,
+ package: contents.ref,
+ installCommand: contents.installCommand,
+ },
useSSE: sseDeploy,
onEvent: (event) => {
// Stream live progress into the loading toast: phase transitions, and the latest
// install output line during the install/load phase (so npm output shows through).
if (event.type === 'phase' && event.data.status === 'start') {
- toast.loading(`Importing ${project}…`, {
+ toast.loading(`${stage ? 'Staging' : 'Importing'} ${project}…`, {
id: toastId,
description: PHASE_LABELS[event.data.phase] ?? event.data.phase,
duration: 300_000,
});
} else if (event.type === 'install' && event.data.line?.trim()) {
- toast.loading(`Importing ${project}…`, {
+ toast.loading(`${stage ? 'Staging' : 'Importing'} ${project}…`, {
id: toastId,
description: event.data.line.trim().slice(0, 140),
duration: 300_000,
});
} else if (event.type === 'rollout' && event.data.state === 'following') {
- toast.loading(`Importing ${project}…`, {
+ toast.loading(`${stage ? 'Staging' : 'Importing'} ${project}…`, {
id: toastId,
description: 'Rolling out to the other nodes…',
duration: Infinity,
@@ -95,6 +103,11 @@ export function useImportApplication(
}, {
onSuccess: async (result) => {
toast.dismiss(toastId);
+ if (stage) {
+ // Nothing went live, so there is no new application in the tree to open.
+ reportStaged(project, result, { action: recordAction(result?.deployment_id) });
+ return;
+ }
onImported(project);
// A followed rollout restarted the other nodes, so there is a health to check however the deploy was sent.
if (sseDeploy || result?.rollout) {
@@ -111,6 +124,12 @@ export function useImportApplication(
onError: async (error) => {
toast.dismiss(toastId);
// Live stream dropped after the deploy started — verify rather than assume failure.
+ if (error instanceof SSEInconclusiveError && stage) {
+ toast.warning(`${project} may not be staged`, {
+ description: 'Live updates ended before the stage finished. Check Deployments for its record.',
+ });
+ return;
+ }
if (error instanceof SSEInconclusiveError) {
onImported(project);
await reportDeployOutcome(project, undefined, runHealthCheck);
@@ -122,13 +141,13 @@ export function useImportApplication(
toast.error(`${project} did not reach every node`, { description: error.message, action });
return;
}
- toast.error(`Failed to import ${project}`, {
+ toast.error(`Failed to ${stage ? 'stage' : 'import'} ${project}`, {
description: error instanceof Error ? error.message : undefined,
action,
});
},
});
- }, [mutate, sseDeploy, instanceParams, runHealthCheck, onImported, recordAction]);
+ }, [mutate, sseDeploy, canStage, instanceParams, runHealthCheck, onImported, recordAction]);
return useMemo(() => ({
isImportingApplication,
diff --git a/src/features/instance/applications/hooks/useSupportsDeploymentSSE.test.ts b/src/features/instance/applications/hooks/useSupportsDeploymentSSE.test.ts
new file mode 100644
index 000000000..5fb026b9d
--- /dev/null
+++ b/src/features/instance/applications/hooks/useSupportsDeploymentSSE.test.ts
@@ -0,0 +1,20 @@
+/** @vitest-environment jsdom */
+import { describe, expect, it } from 'vitest';
+import { supportsStagedDeployments } from './useSupportsDeploymentSSE';
+
+describe('supportsStagedDeployments', () => {
+ it.each([
+ ['5.3.0', true],
+ ['5.3.2', true],
+ ['5.4.0', true],
+ ['6.0.0', true],
+ ['5.2.15', false],
+ ['4.7.9', false],
+ // An older node reads `activate: false` as an ordinary deploy, so anything short of a release is refused.
+ ['5.3.0-beta.4', false],
+ [undefined, false],
+ ['not a version', false],
+ ])('%s -> %s', (version, expected) => {
+ expect(supportsStagedDeployments(version)).toBe(expected);
+ });
+});
diff --git a/src/features/instance/applications/hooks/useSupportsDeploymentSSE.ts b/src/features/instance/applications/hooks/useSupportsDeploymentSSE.ts
index deedf2c6b..4bdbf78a6 100644
--- a/src/features/instance/applications/hooks/useSupportsDeploymentSSE.ts
+++ b/src/features/instance/applications/hooks/useSupportsDeploymentSSE.ts
@@ -15,6 +15,26 @@ export function supportsDeployments(harperVersion: string | undefined): boolean
return !!harperVersion && wasAReleasedBeforeB(MIN_DEPLOYMENT_SSE_VERSION, harperVersion);
}
+/**
+ * Staging (`activate: false`), activation by `deployment_id`, and the `staged` status ship in 5.3.0 (harper
+ * `v5.3.0:components/operations.js:638`). A 5.3.0 prerelease is refused, as `supportsPutOperation` refuses one.
+ */
+export const MIN_STAGED_DEPLOYMENT_VERSION = '5.3.0';
+
+export function supportsStagedDeployments(harperVersion: string | undefined): boolean {
+ return !!harperVersion && wasAReleasedBeforeB(MIN_STAGED_DEPLOYMENT_VERSION, harperVersion);
+}
+
+/**
+ * Whether to offer staging and activation. Unlike a put, an unreadable version must not offer them: a node older
+ * than 5.3.0 accepts `activate: false` as an unknown field and deploys the release live.
+ */
+export function useStagedDeploymentsAvailable(): boolean {
+ const params = useInstanceClientIdParams();
+ const { data } = useQuery(getRegistrationInfoQueryOptions(params));
+ return supportsStagedDeployments(data?.version);
+}
+
/**
* True when the instance/cluster is Harper >= 5.1.0, so the deployment history/detail
* feature (`list_deployments` / `get_deployment`) is available. This gates feature
diff --git a/src/features/instance/applications/modals/RedeployApplicationModal.tsx b/src/features/instance/applications/modals/RedeployApplicationModal.tsx
index 6882bbed7..2047b14a1 100644
--- a/src/features/instance/applications/modals/RedeployApplicationModal.tsx
+++ b/src/features/instance/applications/modals/RedeployApplicationModal.tsx
@@ -2,18 +2,23 @@ import { Button } from '@/components/ui/button';
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@/components/ui/dialog';
import { Form } from '@/components/ui/form/Form';
import { FormControl } from '@/components/ui/form/FormControl';
+import { FormDescription } from '@/components/ui/form/FormDescription';
import { FormField } from '@/components/ui/form/FormField';
import { FormItem } from '@/components/ui/form/FormItem';
import { FormLabel } from '@/components/ui/form/FormLabel';
import { FormMessage } from '@/components/ui/form/FormMessage';
import { Input } from '@/components/ui/input';
+import { Switch } from '@/components/ui/switch';
import { useInstanceClientIdParams } from '@/config/useInstanceClient';
import { DeployProgress } from '@/features/instance/applications/components/DeployProgress/DeployProgress';
import { useDeploymentStream } from '@/features/instance/applications/components/DeployProgress/useDeploymentStream';
import { useComponentHealthCheck } from '@/features/instance/applications/hooks/useComponentHealthCheck';
import { useDeploymentRecordAction } from '@/features/instance/applications/hooks/useDeploymentRecordAction';
import { useEditorView } from '@/features/instance/applications/hooks/useEditorView';
-import { useSupportsDeploymentSSE } from '@/features/instance/applications/hooks/useSupportsDeploymentSSE';
+import {
+ useStagedDeploymentsAvailable,
+ useSupportsDeploymentSSE,
+} from '@/features/instance/applications/hooks/useSupportsDeploymentSSE';
import { useDeployComponentMutation } from '@/integrations/api/instance/applications/deployComponent';
import { deployFailureDetails } from '@/integrations/api/instance/applications/deployOutcome';
import { DeployRolloutError } from '@/integrations/api/instance/applications/restartJob';
@@ -26,7 +31,7 @@ import { RefreshCwIcon } from 'lucide-react';
import { useCallback, useEffect, useState } from 'react';
import { useForm } from 'react-hook-form';
import { toast } from 'sonner';
-import { deployNotes, reportDeployOutcome, reportDeployResult } from './reportDeployHealth';
+import { deployNotes, reportDeployOutcome, reportDeployResult, reportStaged } from './reportDeployHealth';
export function RedeployApplicationModal() {
const { value: isModalOpen, trigger } = useWatchedValue('ShowRedeployApplicationModal', false);
@@ -34,6 +39,7 @@ export function RedeployApplicationModal() {
const queryClient = useQueryClient();
const instanceParams = useInstanceClientIdParams();
const sseDeploy = useSupportsDeploymentSSE();
+ const canStage = useStagedDeploymentsAvailable();
const stream = useDeploymentStream();
const runHealthCheck = useComponentHealthCheck(instanceParams);
const recordAction = useDeploymentRecordAction();
@@ -43,25 +49,29 @@ export function RedeployApplicationModal() {
const { mutate: reDeployApplication, isPending } = useDeployComponentMutation();
const [isStreaming, setIsStreaming] = useState(false);
+ const [isStaging, setIsStaging] = useState(false);
const methods = useForm({
defaultValues: {
applicationUrl: packageUrl,
installCommand: '',
+ stageOnly: false,
},
});
- const { control, handleSubmit, reset } = methods;
+ const { control, handleSubmit, reset, watch } = methods;
+ const stageOnlyChecked = canStage && watch('stageOnly');
useEffect(() => {
- reset({ applicationUrl: packageUrl });
+ reset({ applicationUrl: packageUrl, stageOnly: false });
}, [reset, packageUrl]);
const closeModal = useCallback(() => {
setWatchedValue('ShowRedeployApplicationModal', false);
attemptToRestoreFocus(trigger);
- reset({ applicationUrl: packageUrl });
+ reset({ applicationUrl: packageUrl, stageOnly: false });
setIsStreaming(false);
+ setIsStaging(false);
stream.reset();
}, [reset, packageUrl, trigger, stream]);
@@ -73,7 +83,7 @@ export function RedeployApplicationModal() {
}, [queryClient, instanceParams.entityId]);
const redeployWithProgress = useCallback(
- (applicationUrl: string, installCommand: string | undefined) => {
+ (applicationUrl: string, installCommand: string | undefined, stage: boolean) => {
if (!openedEntry) {
return;
}
@@ -81,18 +91,25 @@ export function RedeployApplicationModal() {
stream.reset();
stream.markStarted();
setIsStreaming(true);
+ setIsStaging(stage);
reDeployApplication(
{
- applicationName: project,
- applicationUrl,
- installCommand,
+ request: { kind: stage ? 'stage' : 'deploy', project, package: applicationUrl, installCommand },
useSSE: true,
onEvent: stream.onEvent,
...instanceParams,
},
{
onSuccess: async (result) => {
+ if (stage) {
+ stream.markSettled('success', undefined, { result });
+ reportStaged(project, result, { action: recordAction(result?.deployment_id) });
+ if (!deployNotes(result).warn) {
+ closeModal();
+ }
+ return;
+ }
const known = result?.rollout?.state !== 'unfollowable';
stream.markSettled(known ? 'success' : 'inconclusive', undefined, { result });
invalidateComponents();
@@ -109,6 +126,14 @@ export function RedeployApplicationModal() {
// instead of reporting a failure we don't actually know happened.
if (error instanceof SSEInconclusiveError) {
stream.markSettled('inconclusive');
+ if (stage) {
+ // A stage changes nothing that is running, so the component's health says nothing about it.
+ toast.warning(`${project} may not be staged`, {
+ description: 'Live updates ended before the stage finished. Check Deployments for its record.',
+ });
+ closeModal();
+ return;
+ }
invalidateComponents();
await reportDeployOutcome(project, undefined, runHealthCheck);
closeModal();
@@ -125,7 +150,7 @@ export function RedeployApplicationModal() {
stream.markSettled('error', error instanceof Error ? error.message : String(error), {
failure: error,
});
- toast.error(`Failed to redeploy ${project}`, {
+ toast.error(`Failed to ${stage ? 'stage' : 'redeploy'} ${project}`, {
description: error instanceof Error ? error.message : undefined,
action,
});
@@ -146,16 +171,28 @@ export function RedeployApplicationModal() {
);
const redeployBuffered = useCallback(
- (applicationUrl: string, installCommand: string | undefined) => {
+ (applicationUrl: string, installCommand: string | undefined, stage: boolean) => {
if (!openedEntry) {
return;
}
closeModal();
- const toastId = toast.loading('Redeploying...');
+ const toastId = toast.loading(stage ? 'Staging...' : 'Redeploying...');
reDeployApplication(
- { applicationName: openedEntry.project, applicationUrl, installCommand, ...instanceParams },
+ {
+ request: {
+ kind: stage ? 'stage' : 'deploy',
+ project: openedEntry.project,
+ package: applicationUrl,
+ installCommand,
+ },
+ ...instanceParams,
+ },
{
onSuccess: (result) => {
+ if (stage) {
+ reportStaged(openedEntry.project, result, { id: toastId, action: recordAction(result?.deployment_id) });
+ return;
+ }
reportDeployResult(
openedEntry.project,
result,
@@ -177,7 +214,7 @@ export function RedeployApplicationModal() {
return;
}
if (action) {
- toast.error(`Failed to redeploy ${openedEntry.project}`, {
+ toast.error(`Failed to ${stage ? 'stage' : 'redeploy'} ${openedEntry.project}`, {
id: toastId,
description: describeError(error).message,
action,
@@ -192,17 +229,19 @@ export function RedeployApplicationModal() {
[reDeployApplication, openedEntry, instanceParams, invalidateComponents, closeModal, recordAction],
);
- const submitForm = ({ applicationUrl, installCommand }: {
+ const submitForm = ({ applicationUrl, installCommand, stageOnly }: {
applicationUrl: string | undefined;
installCommand: string | undefined;
+ stageOnly?: boolean;
}) => {
if (!applicationUrl) {
return;
}
+ const stage = canStage && !!stageOnly;
if (sseDeploy) {
- redeployWithProgress(applicationUrl, installCommand);
+ redeployWithProgress(applicationUrl, installCommand, stage);
} else {
- redeployBuffered(applicationUrl, installCommand);
+ redeployBuffered(applicationUrl, installCommand, stage);
}
};
@@ -215,14 +254,16 @@ export function RedeployApplicationModal() {
Redeploy Package
- {isStreaming ? `Redeploying ${openedEntry?.project ?? 'package'}…` : 'Redeploy this package?'}
+ {isStreaming
+ ? `${isStaging ? 'Staging' : 'Redeploying'} ${openedEntry?.project ?? 'package'}…`
+ : 'Redeploy this package?'}
{isStreaming
? (
-
+
+ {deployment.status === 'staged' && (
+ <>
+
+ Staged: built and installed, but not live. Activating it makes it live with nothing to install.
+