mirror of
https://github.com/redhat-actions/push-to-registry.git
synced 2025-04-20 23:31:22 +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;
|
let podmanPath: string | undefined;
|
||||||
|
|
||||||
// boolean value to check if pushed image is from Docker image storage
|
// boolean value to check if pushed image is from Docker image storage
|
||||||
let isPushingDockerImage = false;
|
let isImageFromDocker = false;
|
||||||
let imageToPush: string;
|
let imageToPush: string;
|
||||||
|
|
||||||
async function getPodmanPath(): Promise<string> {
|
async function getPodmanPath(): Promise<string> {
|
||||||
|
@ -39,14 +39,10 @@ async function run(): Promise<void> {
|
||||||
imageToPush = `${imageInput}:${tag}`;
|
imageToPush = `${imageInput}:${tag}`;
|
||||||
|
|
||||||
// check if image exist in Podman image storage
|
// check if image exist in Podman image storage
|
||||||
const isPresentInPodman: boolean = await checkImageInPodman(
|
const isPresentInPodman: boolean = await checkImageInPodman();
|
||||||
imageToPush,
|
|
||||||
);
|
|
||||||
|
|
||||||
// check if image exist in Docker image storage and if exist pull the image to Podman
|
// check if image exist in Docker image storage and if exist pull the image to Podman
|
||||||
const isPresentInDocker: boolean = await pullImageFromDocker(
|
const isPresentInDocker: boolean = await pullImageFromDocker();
|
||||||
imageToPush,
|
|
||||||
);
|
|
||||||
|
|
||||||
// failing if image is not found in Docker as well as Podman
|
// failing if image is not found in Docker as well as Podman
|
||||||
if (!isPresentInDocker && !isPresentInPodman) {
|
if (!isPresentInDocker && !isPresentInPodman) {
|
||||||
|
@ -54,16 +50,13 @@ async function run(): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isPresentInPodman && isPresentInDocker) {
|
if (isPresentInPodman && isPresentInDocker) {
|
||||||
const isPodmanImageLatest = await isPodmanLocalImageLatest(
|
const isPodmanImageLatest = await isPodmanLocalImageLatest();
|
||||||
imageToPush,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!isPodmanImageLatest) {
|
if (!isPodmanImageLatest) {
|
||||||
core.warning(`The version of ${imageToPush} in the Docker image storage is more recent `
|
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 `
|
+ `than the version in the Podman image storage. The image from the Docker image storage `
|
||||||
+ `will be pushed.`);
|
+ `will be pushed.`);
|
||||||
imageToPush = `${dockerBaseUrl}/${imageToPush}`;
|
imageToPush = `${dockerBaseUrl}/${imageToPush}`;
|
||||||
isPushingDockerImage = true;
|
isImageFromDocker = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
core.warning(`The version of ${imageToPush} in the Podman image storage is more recent `
|
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 `
|
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 `
|
+ `image storage. The image will be pulled into Podman image storage, pushed, and then `
|
||||||
+ `removed from the Podman image storage.`);
|
+ `removed from the Podman image storage.`);
|
||||||
isPushingDockerImage = true;
|
isImageFromDocker = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
let pushMsg = `Pushing ${imageToPush} to ${registry}`;
|
let pushMsg = `Pushing ${imageToPush} to ${registry}`;
|
||||||
|
@ -130,45 +123,39 @@ async function run(): Promise<void> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function pullImageFromDocker(
|
async function pullImageFromDocker(): Promise<boolean> {
|
||||||
imageName: string,
|
|
||||||
): Promise<boolean> {
|
|
||||||
try {
|
try {
|
||||||
await execute(await getPodmanPath(), [ "pull", `docker-daemon:${imageName}` ]);
|
await execute(await getPodmanPath(), [ "pull", `docker-daemon:${imageToPush}` ]);
|
||||||
core.info(`${imageName} found in Docker image storage`);
|
core.info(`${imageToPush} found in Docker image storage`);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
core.info(`${imageName} not found in Docker image storage`);
|
core.info(`${imageToPush} not found in Docker image storage`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkImageInPodman(
|
async function checkImageInPodman(): Promise<boolean> {
|
||||||
imageName: string,
|
|
||||||
): Promise<boolean> {
|
|
||||||
// check if images exist in Podman's storage
|
// 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 {
|
try {
|
||||||
await execute(await getPodmanPath(), [ "image", "exists", imageName ]);
|
await execute(await getPodmanPath(), [ "image", "exists", imageToPush ]);
|
||||||
core.info(`Image ${imageName} found in Podman image storage`);
|
core.info(`Image ${imageToPush} found in Podman image storage`);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (err) {
|
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);
|
core.debug(err);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function isPodmanLocalImageLatest(
|
async function isPodmanLocalImageLatest(): Promise<boolean> {
|
||||||
imageName: string,
|
|
||||||
): Promise<boolean> {
|
|
||||||
// get creation time of the image present in the Podman image storage
|
// get creation time of the image present in the Podman image storage
|
||||||
const podmanLocalImageTimeStamp = await execute(await getPodmanPath(), [
|
const podmanLocalImageTimeStamp = await execute(await getPodmanPath(), [
|
||||||
"image",
|
"image",
|
||||||
"inspect",
|
"inspect",
|
||||||
imageName,
|
imageToPush,
|
||||||
"--format",
|
"--format",
|
||||||
"{{.Created}}",
|
"{{.Created}}",
|
||||||
]);
|
]);
|
||||||
|
@ -179,7 +166,7 @@ async function isPodmanLocalImageLatest(
|
||||||
const pulledImageCreationTimeStamp = await execute(await getPodmanPath(), [
|
const pulledImageCreationTimeStamp = await execute(await getPodmanPath(), [
|
||||||
"image",
|
"image",
|
||||||
"inspect",
|
"inspect",
|
||||||
`${dockerBaseUrl}/${imageName}`,
|
`${dockerBaseUrl}/${imageToPush}`,
|
||||||
"--format",
|
"--format",
|
||||||
"{{.Created}}",
|
"{{.Created}}",
|
||||||
]);
|
]);
|
||||||
|
@ -193,7 +180,7 @@ async function isPodmanLocalImageLatest(
|
||||||
|
|
||||||
// remove the pulled image from the Podman image storage
|
// remove the pulled image from the Podman image storage
|
||||||
async function removeDockerImage(): Promise<void> {
|
async function removeDockerImage(): Promise<void> {
|
||||||
if (!imageToPush) {
|
if (imageToPush) {
|
||||||
core.info(`Removing ${imageToPush} from the Podman image storage`);
|
core.info(`Removing ${imageToPush} from the Podman image storage`);
|
||||||
await execute(await getPodmanPath(), [ "rmi", imageToPush ]);
|
await execute(await getPodmanPath(), [ "rmi", imageToPush ]);
|
||||||
}
|
}
|
||||||
|
@ -241,7 +228,7 @@ async function execute(
|
||||||
run()
|
run()
|
||||||
.catch(core.setFailed)
|
.catch(core.setFailed)
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
if (isPushingDockerImage) {
|
if (isImageFromDocker) {
|
||||||
removeDockerImage();
|
removeDockerImage();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue