diff --git a/src/ImageDetector.ts b/src/ImageDetector.ts index 905881ac..44993903 100644 --- a/src/ImageDetector.ts +++ b/src/ImageDetector.ts @@ -5,13 +5,29 @@ export class ImageDetector { async getExistingImages(): Promise { const existingSet = new Set([]) const ids = (await exec.exec(`docker image ls -q`, [], { silent: true, listeners: { stderr: console.warn }})).stdoutStr.split(`\n`).filter(id => id !== ``) - const repotags = (await exec.exec(`docker`, `image ls --format {{.Repository}}:{{.Tag}} --filter dangling=false`.split(' '), { silent: true, listeners: { stderr: console.warn }})).stdoutStr.split(`\n`).filter(id => id !== ``); + const repotags = await this.getExistingImageIdentifiers() core.debug(JSON.stringify({ log: "getExistingImages", ids, repotags })); ([...ids, ...repotags]).forEach(image => existingSet.add(image)) core.debug(JSON.stringify({ existingSet })) return Array.from(existingSet) } + async getExistingImageIdentifiers(): Promise { + return ( + await exec.exec( + `docker`, `image ls --format {{.Repository}}:{{.Tag}}:{{.ID}} --filter dangling=false`.split(' '), + { silent: true, listeners: { stderr: console.warn }} + ) + ) + .stdoutStr + .split(`\n`) + .filter(img => img !== ``) + .map(img => { + const [repository, tag, id] = img.split(':') + return (tag == '' ? id : `${repository}:${tag}`) + }) + } + async getImagesShouldSave(alreadRegisteredImages: string[]): Promise { const resultSet = new Set(await this.getExistingImages()) alreadRegisteredImages.forEach(image => resultSet.delete(image))