Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support saving images which are identified by SHA rather than tag #140

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/ImageDetector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,29 @@ export class ImageDetector {
async getExistingImages(): Promise<string[]> {
const existingSet = new Set<string>([])
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<string[]> {
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 == '<none>' ? id : `${repository}:${tag}`)
})
}

async getImagesShouldSave(alreadRegisteredImages: string[]): Promise<string[]> {
const resultSet = new Set(await this.getExistingImages())
alreadRegisteredImages.forEach(image => resultSet.delete(image))
Expand Down