-
Notifications
You must be signed in to change notification settings - Fork 55
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
Add Podman option support #135
Open
dabreadman
wants to merge
1
commit into
satackey:main
Choose a base branch
from
dabreadman:dabreadman-podman-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,57 @@ | ||
import * as core from '@actions/core' | ||
import * as exec from 'actions-exec-listener' | ||
import { LayerCache } from './src/LayerCache' | ||
import { ImageDetector } from './src/ImageDetector' | ||
import * as core from "@actions/core"; | ||
import { LayerCache } from "./src/LayerCache"; | ||
import { ImageDetector } from "./src/ImageDetector"; | ||
|
||
const main = async () => { | ||
const primaryKey = core.getInput(`key`, { required: true }) | ||
const restoreKeys = core.getInput(`restore-keys`, { required: false }).split(`\n`).filter(key => key !== ``) | ||
const primaryKey = core.getInput(`key`, { required: true }); | ||
const restoreKeys = core | ||
.getInput(`restore-keys`, { required: false }) | ||
.split(`\n`) | ||
.filter((key) => key !== ``); | ||
|
||
const imageDetector = new ImageDetector() | ||
const imageDetector = new ImageDetector(); | ||
|
||
const alreadyExistingImages = await imageDetector.getExistingImages() | ||
core.saveState(`already-existing-images`, JSON.stringify(alreadyExistingImages)) | ||
const container = core.getInput(`container`).toLowerCase(); | ||
if (container !== "docker" && container !== "podman") { | ||
throw new Error("Wrong container name: " + container); | ||
} | ||
|
||
const layerCache = new LayerCache([]) | ||
layerCache.concurrency = parseInt(core.getInput(`concurrency`, { required: true }), 10) | ||
const restoredKey = await layerCache.restore(primaryKey, restoreKeys) | ||
await layerCache.cleanUp() | ||
const alreadyExistingImages = await imageDetector.getExistingImages( | ||
container | ||
); | ||
core.saveState( | ||
`already-existing-images`, | ||
JSON.stringify(alreadyExistingImages) | ||
); | ||
|
||
core.saveState(`restored-key`, JSON.stringify(restoredKey !== undefined ? restoredKey : '')) | ||
core.saveState(`restored-images`, JSON.stringify(await imageDetector.getImagesShouldSave(alreadyExistingImages))) | ||
} | ||
const layerCache = new LayerCache([]); | ||
layerCache.concurrency = parseInt( | ||
core.getInput(`concurrency`, { required: true }), | ||
10 | ||
); | ||
const restoredKey = await layerCache.restore( | ||
primaryKey, | ||
container, | ||
restoreKeys | ||
); | ||
await layerCache.cleanUp(); | ||
|
||
main().catch(e => { | ||
console.error(e) | ||
core.setFailed(e) | ||
core.saveState( | ||
`restored-key`, | ||
JSON.stringify(restoredKey !== undefined ? restoredKey : "") | ||
); | ||
core.saveState( | ||
`restored-images`, | ||
JSON.stringify( | ||
await imageDetector.getImagesShouldSave(alreadyExistingImages, container) | ||
) | ||
); | ||
}; | ||
|
||
core.saveState(`restored-key`, JSON.stringify(``)) | ||
core.saveState(`restored-images`, JSON.stringify([])) | ||
}) | ||
main().catch((e) => { | ||
console.error(e); | ||
core.setFailed(e); | ||
|
||
core.saveState(`restored-key`, JSON.stringify(``)); | ||
core.saveState(`restored-images`, JSON.stringify([])); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,61 @@ | ||
import * as core from '@actions/core' | ||
import * as core from "@actions/core"; | ||
|
||
import { LayerCache } from './src/LayerCache' | ||
import { ImageDetector } from './src/ImageDetector' | ||
import { assertType } from 'typescript-is' | ||
import { LayerCache } from "./src/LayerCache"; | ||
import { ImageDetector } from "./src/ImageDetector"; | ||
import { assertType } from "typescript-is"; | ||
|
||
const main = async () => { | ||
if (JSON.parse(core.getInput('skip-save', { required: true }))) { | ||
core.info('Skipping save.') | ||
return | ||
if (JSON.parse(core.getInput("skip-save", { required: true }))) { | ||
core.info("Skipping save."); | ||
return; | ||
} | ||
|
||
const primaryKey = core.getInput('key', { required: true }) | ||
const primaryKey = core.getInput("key", { required: true }); | ||
|
||
const restoredKey = JSON.parse(core.getState(`restored-key`)) | ||
const alreadyExistingImages = JSON.parse(core.getState(`already-existing-images`)) | ||
const restoredImages = JSON.parse(core.getState(`restored-images`)) | ||
const restoredKey = JSON.parse(core.getState(`restored-key`)); | ||
const alreadyExistingImages = JSON.parse( | ||
core.getState(`already-existing-images`) | ||
); | ||
const restoredImages = JSON.parse(core.getState(`restored-images`)); | ||
|
||
assertType<string>(restoredKey) | ||
assertType<string[]>(alreadyExistingImages) | ||
assertType<string[]>(restoredImages) | ||
assertType<string>(restoredKey); | ||
assertType<string[]>(alreadyExistingImages); | ||
assertType<string[]>(restoredImages); | ||
|
||
const imageDetector = new ImageDetector() | ||
const imageDetector = new ImageDetector(); | ||
|
||
const existingAndRestoredImages = alreadyExistingImages.concat(restoredImages) | ||
const newImages = await imageDetector.getImagesShouldSave(existingAndRestoredImages) | ||
if (newImages.length < 1) { | ||
core.info(`There is no image to save.`) | ||
return | ||
const container = core.getInput(`container`).toLowerCase(); | ||
if (container !== "docker" && container !== "podman") { | ||
throw new Error("Wrong container name: " + container); | ||
} | ||
|
||
const imagesToSave = await imageDetector.getImagesShouldSave(alreadyExistingImages) | ||
const layerCache = new LayerCache(imagesToSave) | ||
layerCache.concurrency = parseInt(core.getInput(`concurrency`, { required: true }), 10) | ||
|
||
await layerCache.store(primaryKey) | ||
await layerCache.cleanUp() | ||
} | ||
const existingAndRestoredImages = alreadyExistingImages.concat( | ||
restoredImages | ||
); | ||
const newImages = await imageDetector.getImagesShouldSave( | ||
existingAndRestoredImages, | ||
container | ||
); | ||
if (newImages.length < 1) { | ||
core.info(`There is no image to save.`); | ||
return; | ||
} | ||
|
||
main().catch(e => { | ||
console.error(e) | ||
core.setFailed(e) | ||
}) | ||
const imagesToSave = await imageDetector.getImagesShouldSave( | ||
alreadyExistingImages, | ||
container | ||
); | ||
const layerCache = new LayerCache(imagesToSave); | ||
layerCache.concurrency = parseInt( | ||
core.getInput(`concurrency`, { required: true }), | ||
10 | ||
); | ||
|
||
await layerCache.store(primaryKey, container); | ||
await layerCache.cleanUp(); | ||
}; | ||
|
||
main().catch((e) => { | ||
console.error(e); | ||
core.setFailed(e); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,40 @@ | ||
import * as exec from 'actions-exec-listener' | ||
import * as core from '@actions/core' | ||
import * as exec from "actions-exec-listener"; | ||
import * as core from "@actions/core"; | ||
|
||
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 !== ``); | ||
async getExistingImages(container: "docker" | "podman"): Promise<string[]> { | ||
const existingSet = new Set<string>([]); | ||
const ids = ( | ||
await exec.exec(`${container} image ls -q`, [], { | ||
silent: true, | ||
listeners: { stderr: console.warn }, | ||
}) | ||
).stdoutStr | ||
.split(`\n`) | ||
.filter((id) => id !== ``); | ||
const repotags = ( | ||
await exec.exec( | ||
`${container}`, | ||
`image ls --format {{.Repository}}:{{.Tag}} --filter dangling=false`.split( | ||
" " | ||
), | ||
{ silent: true, listeners: { stderr: console.warn } } | ||
) | ||
).stdoutStr | ||
.split(`\n`) | ||
.filter((id) => id !== ``); | ||
core.debug(JSON.stringify({ log: "getExistingImages", ids, repotags })); | ||
([...ids, ...repotags]).forEach(image => existingSet.add(image)) | ||
core.debug(JSON.stringify({ existingSet })) | ||
return Array.from(existingSet) | ||
[...ids, ...repotags].forEach((image) => existingSet.add(image)); | ||
core.debug(JSON.stringify({ existingSet })); | ||
return Array.from(existingSet); | ||
} | ||
|
||
async getImagesShouldSave(alreadRegisteredImages: string[]): Promise<string[]> { | ||
const resultSet = new Set(await this.getExistingImages()) | ||
alreadRegisteredImages.forEach(image => resultSet.delete(image)) | ||
return Array.from(resultSet) | ||
async getImagesShouldSave( | ||
alreadRegisteredImages: string[], | ||
container: "docker" | "podman" | ||
): Promise<string[]> { | ||
const resultSet = new Set(await this.getExistingImages(container)); | ||
alreadRegisteredImages.forEach((image) => resultSet.delete(image)); | ||
return Array.from(resultSet); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What we see is that we have replaced
docker image ls -q
with${container} image ls -q
, in which we can specify${container}
to be eitherdocker
orpodman
.