mirror of
https://github.com/redhat-actions/push-to-registry.git
synced 2025-04-20 15:21:23 +00:00
Resolve reviews
Signed-off-by: divyansh42 <diagrawa@redhat.com>
This commit is contained in:
parent
260181aca3
commit
82f1760c2f
3 changed files with 22 additions and 35 deletions
2
dist/index.js
vendored
2
dist/index.js
vendored
File diff suppressed because one or more lines are too long
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
53
src/index.ts
53
src/index.ts
|
@ -13,7 +13,7 @@ interface ExecResult {
|
|||
let podmanPath: string | undefined;
|
||||
|
||||
// boolean value to check if pushed image is from Docker image storage
|
||||
let isPushingDockerImage = false;
|
||||
let isImageFromDocker = false;
|
||||
let imageToPush: string;
|
||||
|
||||
async function getPodmanPath(): Promise<string> {
|
||||
|
@ -39,14 +39,10 @@ async function run(): Promise<void> {
|
|||
imageToPush = `${imageInput}:${tag}`;
|
||||
|
||||
// check if image exist in Podman image storage
|
||||
const isPresentInPodman: boolean = await checkImageInPodman(
|
||||
imageToPush,
|
||||
);
|
||||
const isPresentInPodman: boolean = await checkImageInPodman();
|
||||
|
||||
// check if image exist in Docker image storage and if exist pull the image to Podman
|
||||
const isPresentInDocker: boolean = await pullImageFromDocker(
|
||||
imageToPush,
|
||||
);
|
||||
const isPresentInDocker: boolean = await pullImageFromDocker();
|
||||
|
||||
// failing if image is not found in Docker as well as Podman
|
||||
if (!isPresentInDocker && !isPresentInPodman) {
|
||||
|
@ -54,16 +50,13 @@ async function run(): Promise<void> {
|
|||
}
|
||||
|
||||
if (isPresentInPodman && isPresentInDocker) {
|
||||
const isPodmanImageLatest = await isPodmanLocalImageLatest(
|
||||
imageToPush,
|
||||
);
|
||||
|
||||
const isPodmanImageLatest = await isPodmanLocalImageLatest();
|
||||
if (!isPodmanImageLatest) {
|
||||
core.warning(`The version of ${imageToPush} in the Docker image storage is more recent `
|
||||
+ `than the version in the Podman image storage. The image from the Docker image storage `
|
||||
+ `will be pushed.`);
|
||||
imageToPush = `${dockerBaseUrl}/${imageToPush}`;
|
||||
isPushingDockerImage = true;
|
||||
isImageFromDocker = true;
|
||||
}
|
||||
else {
|
||||
core.warning(`The version of ${imageToPush} in the Podman image storage is more recent `
|
||||
|
@ -76,7 +69,7 @@ async function run(): Promise<void> {
|
|||
core.info(`Image ${imageToPush} was found in the Docker image storage, but not in the Podman `
|
||||
+ `image storage. The image will be pulled into Podman image storage, pushed, and then `
|
||||
+ `removed from the Podman image storage.`);
|
||||
isPushingDockerImage = true;
|
||||
isImageFromDocker = true;
|
||||
}
|
||||
|
||||
let pushMsg = `Pushing ${imageToPush} to ${registry}`;
|
||||
|
@ -130,45 +123,39 @@ async function run(): Promise<void> {
|
|||
}
|
||||
}
|
||||
|
||||
async function pullImageFromDocker(
|
||||
imageName: string,
|
||||
): Promise<boolean> {
|
||||
async function pullImageFromDocker(): Promise<boolean> {
|
||||
try {
|
||||
await execute(await getPodmanPath(), [ "pull", `docker-daemon:${imageName}` ]);
|
||||
core.info(`${imageName} found in Docker image storage`);
|
||||
await execute(await getPodmanPath(), [ "pull", `docker-daemon:${imageToPush}` ]);
|
||||
core.info(`${imageToPush} found in Docker image storage`);
|
||||
return true;
|
||||
}
|
||||
catch (err) {
|
||||
core.info(`${imageName} not found in Docker image storage`);
|
||||
core.info(`${imageToPush} not found in Docker image storage`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async function checkImageInPodman(
|
||||
imageName: string,
|
||||
): Promise<boolean> {
|
||||
async function checkImageInPodman(): Promise<boolean> {
|
||||
// check if images exist in Podman's storage
|
||||
core.info(`Checking if ${imageName} is in Podman image storage`);
|
||||
core.info(`Checking if ${imageToPush} is in Podman image storage`);
|
||||
try {
|
||||
await execute(await getPodmanPath(), [ "image", "exists", imageName ]);
|
||||
core.info(`Image ${imageName} found in Podman image storage`);
|
||||
await execute(await getPodmanPath(), [ "image", "exists", imageToPush ]);
|
||||
core.info(`Image ${imageToPush} found in Podman image storage`);
|
||||
return true;
|
||||
}
|
||||
catch (err) {
|
||||
core.info(`Image ${imageName} not found in Podman image storage`);
|
||||
core.info(`Image ${imageToPush} not found in Podman image storage`);
|
||||
core.debug(err);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async function isPodmanLocalImageLatest(
|
||||
imageName: string,
|
||||
): Promise<boolean> {
|
||||
async function isPodmanLocalImageLatest(): Promise<boolean> {
|
||||
// get creation time of the image present in the Podman image storage
|
||||
const podmanLocalImageTimeStamp = await execute(await getPodmanPath(), [
|
||||
"image",
|
||||
"inspect",
|
||||
imageName,
|
||||
imageToPush,
|
||||
"--format",
|
||||
"{{.Created}}",
|
||||
]);
|
||||
|
@ -179,7 +166,7 @@ async function isPodmanLocalImageLatest(
|
|||
const pulledImageCreationTimeStamp = await execute(await getPodmanPath(), [
|
||||
"image",
|
||||
"inspect",
|
||||
`${dockerBaseUrl}/${imageName}`,
|
||||
`${dockerBaseUrl}/${imageToPush}`,
|
||||
"--format",
|
||||
"{{.Created}}",
|
||||
]);
|
||||
|
@ -193,7 +180,7 @@ async function isPodmanLocalImageLatest(
|
|||
|
||||
// remove the pulled image from the Podman image storage
|
||||
async function removeDockerImage(): Promise<void> {
|
||||
if (!imageToPush) {
|
||||
if (imageToPush) {
|
||||
core.info(`Removing ${imageToPush} from the Podman image storage`);
|
||||
await execute(await getPodmanPath(), [ "rmi", imageToPush ]);
|
||||
}
|
||||
|
@ -241,7 +228,7 @@ async function execute(
|
|||
run()
|
||||
.catch(core.setFailed)
|
||||
.finally(() => {
|
||||
if (isPushingDockerImage) {
|
||||
if (isImageFromDocker) {
|
||||
removeDockerImage();
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue