d0d3c068ba
Adds append-only version history on disk (compose/{id}/v{N}/<files>) for
file-based (WorkflowID==0) Compose/Swarm stacks, with rollback to any past
version. Git stacks (versioned by commit) and Kubernetes are untouched.
Backend:
- Stack model: StackFileVersion, PreviousDeploymentInfo, Versions[]; new
StackFileVersionInfo type. APIVersion 2.43.0 -> 2.44.0.
- Versioned multi-file snapshot (entrypoint + AdditionalFiles) into v{N}/;
ProjectPath repointed via GetStackProjectPathByVersion each deploy. Retention
cap (20): Versions[] trimmed in-tx, old dirs deleted only AFTER the tx commits.
- Update handlers: RollbackTo (content read server-side from the target version,
never trusted from the client; validated 1..current & present in Versions).
- Create paths seed v1. stackFile reads ?version= (validated; negative -> 400).
- New GET /stacks/{id}/versions endpoint.
- Migration 2.44.0: move existing file-based stacks' files into v1/ (idempotent,
atomic pre-read of the full file set, skips git/kube/orphans).
Frontend:
- useStackVersions query + stackVersions key; StackEditorTab builds the full
history list; StackVersionSelector shows 'v{N} · date · author'; file/versions
caches invalidated (by prefix) after deploy/rollback.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
52 lines
1.3 KiB
TypeScript
52 lines
1.3 KiB
TypeScript
import { useQuery } from '@tanstack/react-query';
|
|
|
|
import axios, { parseAxiosError } from '@/portainer/services/axios/axios';
|
|
import { EnvironmentId } from '@/react/portainer/environments/types';
|
|
import { withError } from '@/react-tools/react-query';
|
|
|
|
import { StackFileVersionInfo, StackId } from '../types';
|
|
|
|
import { queryKeys } from './query-keys';
|
|
|
|
export function useStackVersions(
|
|
stackId?: StackId,
|
|
environmentId?: EnvironmentId,
|
|
{ enabled }: { enabled?: boolean } = {}
|
|
) {
|
|
return useQuery({
|
|
queryKey: queryKeys.stackVersions(stackId),
|
|
queryFn: ({ signal }) =>
|
|
getStackVersions({
|
|
stackId: stackId!,
|
|
environmentId,
|
|
options: { signal },
|
|
}),
|
|
|
|
...withError('Unable to retrieve stack versions'),
|
|
enabled: !!stackId && enabled,
|
|
});
|
|
}
|
|
|
|
export async function getStackVersions({
|
|
stackId,
|
|
environmentId,
|
|
options = {},
|
|
}: {
|
|
stackId: StackId;
|
|
environmentId?: EnvironmentId;
|
|
options?: { signal?: AbortSignal };
|
|
}) {
|
|
try {
|
|
const { data } = await axios.get<StackFileVersionInfo[]>(
|
|
`/stacks/${stackId}/versions`,
|
|
{
|
|
params: { endpointId: environmentId },
|
|
signal: options.signal,
|
|
}
|
|
);
|
|
return data;
|
|
} catch (e) {
|
|
throw parseAxiosError(e, 'Unable to retrieve stack versions');
|
|
}
|
|
}
|