Skip to content

Modern Docker Management, Designed for Everyone

1.7 KB
Raw Blame
/**
 * Auto-update exclusion helpers shared by the environment jobs tab, the
 * container detail page and the updates table. The backend stores exclusions
 * as a CSV of container *names* in `autoUpdateExcludedContainers`, and the
 * Docker label `com.getarcaneapp.arcane.updater=false` overrides that setting.
 * Container responses carry the resolved `autoUpdateEnabled` status. Both
 * controls only stop automatic installation; update checks and notifications
 * are opted out separately with `UPDATE_CHECK_LABEL`.
 */

const AUTO_UPDATE_LABEL = 'com.getarcaneapp.arcane.updater';
/** Setting this label to a false-like value disables update checks and notifications. */
export const UPDATE_CHECK_LABEL = 'com.getarcaneapp.arcane.update-check';
/** Overrides the environment's auto-update delay, in hours, for one container. */
export const UPDATE_DELAY_LABEL = 'com.getarcaneapp.arcane.updater.delay';
const DISABLED_LABEL_VALUES = ['false', '0', 'no', 'off'];

/** Strips the leading slashes Docker puts on container names. */
export function normalizeContainerName(name: string): string {
	return name.replace(/^\/+/, '');
}

/** True when the Docker label opts the container out of auto-updates. */
export function isAutoUpdateLabelDisabled(labels?: Record<string, string>): boolean {
	if (!labels) return false;
	const value = Object.entries(labels).find(([key]) => key.toLowerCase() === AUTO_UPDATE_LABEL)?.[1];
	return !!value && DISABLED_LABEL_VALUES.includes(value.trim().toLowerCase());
}

/** Parses an `autoUpdateExcludedContainers`-style CSV into normalized names. */
export function parseExcludedContainerSet(csv?: string): Set<string> {
	return new Set(
		(csv || '')
			.split(',')
			.map((entry) => normalizeContainerName(entry.trim()))
			.filter(Boolean)
	);
}