Files
portainer/app/react/docker/containers/update/useUpdateContainerImage.ts
T
claude code agent be3bfd0513 fix(automation): maintainer pre-merge review — stale detection, daemon edge cases, parity (F1-F9)
F1: cap the image-status cache TTL at 5m (was 24h) — the cache is keyed by the
    LOCAL imageID, which doesn't change when upstream pushes a new image under the
    same tag, so the 24h TTL hid new images from both the badge and the auto-update
    daemon; a short TTL re-resolves the remote digest within the poll window.
F2: document that the update->rollback guard map is in-memory (restart implication).
F3: skip auto-update for an unnamed container when rollback is on (the endpoint+name
    keyed guard can't record it, so it would loop) — pure skipUnnamedForRollback + test.
F4: wrap the pre-update ContainerInspect in context.WithTimeout(endpointTimeout).
F5: document Reload() does not interrupt an in-flight tick.
F6: floor auto-heal CheckInterval at 1s (mirrors auto-update) + test.
F7: wontfix — migration is currently correct; namespace rework is out of scope.
F8: correct the misleading SSRF/AllowList comment (no filter is applied).
F9: front auto-heal interval floor + test; dedup STALE_TIME; fix invalidation comment.
Also refresh three stale '24h/long-lived cache' comments to match the 5m TTL.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-29 19:51:15 +03:00

64 lines
2.3 KiB
TypeScript

import { QueryClient, useMutation, useQueryClient } from '@tanstack/react-query';
import { withError } from '@/react-tools/react-query';
import { Stack } from '@/react/common/stacks/types';
import { queryKeys as stacksQueryKeys } from '@/react/common/stacks/queries/query-keys';
import { queryKeys as containerQueryKeys } from '../queries/query-keys';
import { applyContainerUpdate } from './applyContainerUpdate';
import { ContainerUpdateContext } from './types';
/**
* Refresh the data affected by a container image update: the container itself,
* its image-status badge (so it flips away from "outdated") and the stacks
* list (a stack redeploy bumps its deployment info).
*
* Note: for a stack redeploy this invalidates only the representative container's
* badge, not those of its siblings in the same stack — a stack redeploy updates
* every container, but only `context` is passed here. The sibling badges refresh
* on their next natural refetch (staleTime / window focus) or a manual reload.
* They are deliberately not force-invalidated from this shared helper (also used
* by the single standalone "Update now") to avoid an endpoint-wide badge refetch.
*/
export function invalidateContainerUpdateQueries(
queryClient: QueryClient,
context: ContainerUpdateContext
) {
queryClient.invalidateQueries(
containerQueryKeys.container(context.environmentId, context.id)
);
queryClient.invalidateQueries(
containerQueryKeys.imageStatus(
context.environmentId,
context.id,
context.nodeName
)
);
queryClient.invalidateQueries(stacksQueryKeys.base());
}
interface UpdateContainerImageParams {
context: ContainerUpdateContext;
stacks: Stack[];
pullImage?: boolean;
}
/**
* Single-container image-update mutation built on the shared apply primitive.
* Used by the details-view "Update now" button; the bulk action drives the same
* primitive directly (see useBulkUpdateContainerImages).
*/
export function useUpdateContainerImage() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: ({ context, stacks, pullImage }: UpdateContainerImageParams) =>
applyContainerUpdate(context, stacks, { pullImage }),
onSuccess: (_kind, { context }) => {
invalidateContainerUpdateQueries(queryClient, context);
},
...withError('Unable to update container image'),
});
}