mirror of
https://github.com/replicatedhq/ttl.sh.git
synced 2026-07-10 22:59:19 +00:00
Continue evaluating/reaping images even if one of them fails (#95)
This commit is contained in:
@@ -39,51 +39,55 @@ async function main(argv): Promise<any> {
|
||||
const images = await smembersAsync("current.images");
|
||||
console.log(` there are ${images.length} total images to evaluate`);
|
||||
for (const image of images) {
|
||||
const expireAt = await hgetAsync(image, "expires");
|
||||
try {
|
||||
const expireAt = await hgetAsync(image, "expires");
|
||||
|
||||
if (+expireAt > now) {
|
||||
const minutesLeft = (+expireAt - now) / 1000 / 60;
|
||||
console.log(`not expiring ${image} for another ~${Math.round(minutesLeft)} minute(s)`);
|
||||
continue;
|
||||
}
|
||||
|
||||
const imageAndTag = image.split(":");
|
||||
const headers = {
|
||||
"Accept": "application/vnd.docker.distribution.manifest.v2+json",
|
||||
};
|
||||
|
||||
// Get the manifest from the tag
|
||||
const getOptions = {
|
||||
method: "HEAD",
|
||||
uri: `https://ttl.sh/v2/${imageAndTag[0]}/manifests/${imageAndTag[1]}`,
|
||||
headers,
|
||||
resolveWithFullResponse: true,
|
||||
simple: false,
|
||||
}
|
||||
const getResponse = await rp(getOptions);
|
||||
|
||||
if (getResponse.statusCode == 404) {
|
||||
if (+expireAt > now) {
|
||||
const minutesLeft = (+expireAt - now) / 1000 / 60;
|
||||
console.log(`not expiring ${image} for another ~${Math.round(minutesLeft)} minute(s)`);
|
||||
continue;
|
||||
}
|
||||
|
||||
const imageAndTag = image.split(":");
|
||||
const headers = {
|
||||
"Accept": "application/vnd.docker.distribution.manifest.v2+json",
|
||||
};
|
||||
|
||||
// Get the manifest from the tag
|
||||
const getOptions = {
|
||||
method: "HEAD",
|
||||
uri: `https://ttl.sh/v2/${imageAndTag[0]}/manifests/${imageAndTag[1]}`,
|
||||
headers,
|
||||
resolveWithFullResponse: true,
|
||||
simple: false,
|
||||
}
|
||||
const getResponse = await rp(getOptions);
|
||||
|
||||
if (getResponse.statusCode == 404) {
|
||||
await sremAsync("current.images", image);
|
||||
await delAsync(image);
|
||||
continue;
|
||||
}
|
||||
|
||||
const deleteURI = `https://ttl.sh/v2/${imageAndTag[0]}/manifests/${getResponse.headers.etag.replace(/"/g,"")}`;
|
||||
|
||||
// Remove from the registry
|
||||
const options = {
|
||||
method: "DELETE",
|
||||
uri: deleteURI,
|
||||
headers,
|
||||
resolveWithFullResponse: true,
|
||||
simple: false,
|
||||
}
|
||||
|
||||
await rp(options);
|
||||
|
||||
console.log(`expiring ${image}`);
|
||||
await sremAsync("current.images", image);
|
||||
await delAsync(image);
|
||||
continue;
|
||||
} catch(err) {
|
||||
console.log(`failed to evaluate image ${image}:`, err);
|
||||
}
|
||||
|
||||
const deleteURI = `https://ttl.sh/v2/${imageAndTag[0]}/manifests/${getResponse.headers.etag.replace(/"/g,"")}`;
|
||||
|
||||
// Remove from the registry
|
||||
const options = {
|
||||
method: "DELETE",
|
||||
uri: deleteURI,
|
||||
headers,
|
||||
resolveWithFullResponse: true,
|
||||
simple: false,
|
||||
}
|
||||
|
||||
await rp(options);
|
||||
|
||||
console.log(`expiring ${image}`);
|
||||
await sremAsync("current.images", image);
|
||||
await delAsync(image);
|
||||
}
|
||||
},
|
||||
start: true,
|
||||
|
||||
Reference in New Issue
Block a user