Files
portainer/app/react/docker/containers/queries/useContainerImageStatus.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

71 lines
2.2 KiB
TypeScript

import { useQuery } from '@tanstack/react-query';
import axios, { parseAxiosError } from '@/portainer/services/axios/axios';
import { EnvironmentId } from '@/react/portainer/environments/types';
import { buildDockerUrl } from '../../queries/utils/buildDockerUrl';
import { ContainerId } from '../types';
import { queryKeys } from './query-keys';
/**
* Status of a running container image as reported by the CE detection engine.
*
* - `outdated`: a newer image is available in the registry.
* - `updated`: the local image matches the remote registry digest.
* - `skipped`: detection is not applicable (digest-pinned or local-only image).
* - `processing` / `preparing`: detection is in progress (mostly relevant for services).
* - `error`: detection failed (registry unreachable, auth failure, ...).
*/
export type ContainerImageStatusValue =
| 'outdated'
| 'updated'
| 'skipped'
| 'processing'
| 'preparing'
| 'error';
export interface ContainerImageStatus {
Status: ContainerImageStatusValue;
Message?: string;
}
// Client-side staleTime for image-status badges: long enough to avoid hammering
// the endpoint when many rows are visible at once, short enough that a freshly
// pushed upstream image surfaces reasonably soon. Exported as the single source of
// truth so the bulk-update action reuses the same window instead of redefining it.
export const STALE_TIME = 5 * 60 * 1000; // 5 minutes
export async function getContainerImageStatus(
environmentId: EnvironmentId,
containerId: ContainerId,
nodeName?: string
) {
try {
const { data } = await axios.get<ContainerImageStatus>(
buildDockerUrl(environmentId, 'containers', containerId, 'image_status'),
{ params: nodeName ? { nodeName } : undefined }
);
return data;
} catch (err) {
throw parseAxiosError(err as Error, 'Unable to retrieve image status');
}
}
export function useContainerImageStatus(
environmentId: EnvironmentId,
containerId: ContainerId,
nodeName?: string,
enabled = true
) {
return useQuery(
queryKeys.imageStatus(environmentId, containerId, nodeName),
() => getContainerImageStatus(environmentId, containerId, nodeName),
{
enabled,
staleTime: STALE_TIME,
refetchOnWindowFocus: false,
}
);
}