mirror of
https://github.com/redhat-actions/push-to-registry.git
synced 2025-04-19 22:26:18 +02:00
Resolve another set of reviews
Signed-off-by: divyansh42 <diagrawa@redhat.com>
This commit is contained in:
parent
34d200b35d
commit
f2622a46a5
5 changed files with 41 additions and 28 deletions
|
@ -1,3 +1,2 @@
|
|||
node_modules/
|
||||
out/
|
||||
dist/
|
13
README.md
13
README.md
|
@ -120,10 +120,15 @@ jobs:
|
|||
run: echo "New image has been pushed to ${{ steps.push-to-quay.outputs.registry-path }}"
|
||||
```
|
||||
|
||||
**NOTE**:
|
||||
- This action use `Docker` and `Podman` both as the command line tools. Docker and Podman stores image in their respective local image storage's.
|
||||
- If image is present in Docker image storage then image will be pulled into Podman's image storage and will be removed once image is pushed to the desired image registry.
|
||||
- In case image with same name and same version is present in Docker as well as Podman image storage, then this action will push the latest built version amongst the Docker and Podman image storage's.
|
||||
## Note about images built with Docker
|
||||
|
||||
This action uses `Podman` to push, but can also push images built with `Docker`. However, Docker and Podman store their images in different locations, and Podman can only push images in its own storage.
|
||||
|
||||
If the image to push is present in the Docker image storage but not in the Podman image storage, it will be pulled into Podman's storage.
|
||||
|
||||
If the image to push is present in both the Docker and Podman image storage, the action will push the image which was more recently built, and log a warning.
|
||||
|
||||
If an image was pulled from the Docker image storage into the Podman storage, it will be cleaned up from the Podman storage before the action exits.
|
||||
|
||||
## Troubleshooting
|
||||
Note that quay.io repositories are private by default.<br>
|
||||
|
|
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
51
src/index.ts
51
src/index.ts
|
@ -12,6 +12,10 @@ interface ExecResult {
|
|||
|
||||
let podmanPath: string | undefined;
|
||||
|
||||
// boolean value to check if pushed image is from Docker image storage
|
||||
let isPushingDockerImage = false;
|
||||
let imageToPush: string;
|
||||
|
||||
async function getPodmanPath(): Promise<string> {
|
||||
if (podmanPath == null) {
|
||||
podmanPath = await io.which("podman", true);
|
||||
|
@ -32,7 +36,7 @@ async function run(): Promise<void> {
|
|||
const tlsVerify = core.getInput("tls-verify");
|
||||
const digestFileInput = core.getInput("digestfile");
|
||||
|
||||
let imageToPush = `${imageInput}:${tag}`;
|
||||
imageToPush = `${imageInput}:${tag}`;
|
||||
|
||||
// check if image exist in Podman image storage
|
||||
const isPresentInPodman: boolean = await checkImageInPodman(
|
||||
|
@ -49,26 +53,29 @@ async function run(): Promise<void> {
|
|||
throw new Error(`Image ${imageToPush} not found in Podman local storage, or Docker local storage.`);
|
||||
}
|
||||
|
||||
// boolean value to check if pushed image is from Docker image storage
|
||||
let isPushingDockerImage = false;
|
||||
|
||||
if (isPresentInPodman && isPresentInDocker) {
|
||||
const isPodmanImageLatest = await isPodmanLocalImageLatest(
|
||||
imageToPush,
|
||||
);
|
||||
|
||||
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.`);
|
||||
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;
|
||||
}
|
||||
else {
|
||||
core.warning(`The version of ${imageToPush} in the Podman image storage is more recent than the version in the Docker image storage. The image from the Podman image storage will be pushed.`);
|
||||
core.warning(`The version of ${imageToPush} in the Podman image storage is more recent `
|
||||
+ `than the version in the Docker image storage. The image from the Podman image `
|
||||
+ `storage will be pushed.`);
|
||||
}
|
||||
}
|
||||
else if (isPresentInDocker) {
|
||||
imageToPush = `${dockerBaseUrl}/${imageToPush}`;
|
||||
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.`);
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -113,12 +120,6 @@ async function run(): Promise<void> {
|
|||
core.info(`Successfully pushed ${imageToPush} to ${registryPath}.`);
|
||||
core.setOutput("registry-path", registryPath);
|
||||
|
||||
// remove the pulled image from the Podman image storage
|
||||
if (isPushingDockerImage) {
|
||||
core.info(`Removing ${imageToPush} from the Podman image storage`);
|
||||
await execute(await getPodmanPath(), [ "rmi", imageToPush ]);
|
||||
}
|
||||
|
||||
try {
|
||||
const digest = (await fs.promises.readFile(digestFile)).toString();
|
||||
core.info(digest);
|
||||
|
@ -134,11 +135,11 @@ async function pullImageFromDocker(
|
|||
): Promise<boolean> {
|
||||
try {
|
||||
await execute(await getPodmanPath(), [ "pull", `docker-daemon:${imageName}` ]);
|
||||
core.info(`Image ${imageName} found in Docker image storage`);
|
||||
core.info(`${imageName} found in Docker image storage`);
|
||||
return true;
|
||||
}
|
||||
catch (err) {
|
||||
core.info(`Image ${imageName} not found in Docker image storage`);
|
||||
core.info(`${imageName} not found in Docker image storage`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -147,7 +148,7 @@ async function checkImageInPodman(
|
|||
imageName: string,
|
||||
): Promise<boolean> {
|
||||
// check if images exist in Podman's storage
|
||||
core.info("Checking image in Podman image storage");
|
||||
core.info(`Checking if ${imageName} is in Podman image storage`);
|
||||
try {
|
||||
await execute(await getPodmanPath(), [ "image", "exists", imageName ]);
|
||||
core.info(`Image ${imageName} found in Podman image storage`);
|
||||
|
@ -172,8 +173,6 @@ async function isPodmanLocalImageLatest(
|
|||
"{{.Created}}",
|
||||
]);
|
||||
|
||||
core.info(`The image from Podman image storage was last modified at ${podmanLocalImageTimeStamp.stdout}`);
|
||||
|
||||
// get creation time of the image pulled from the Docker image storage
|
||||
// appending 'docker.io/library' infront of image name as pulled image name
|
||||
// from Docker image storage starts with the 'docker.io/library'
|
||||
|
@ -185,8 +184,6 @@ async function isPodmanLocalImageLatest(
|
|||
"{{.Created}}",
|
||||
]);
|
||||
|
||||
core.info(`The image from Docker image storage was last modified at ${pulledImageCreationTimeStamp.stdout}`);
|
||||
|
||||
const podmanImageTime = new Date(podmanLocalImageTimeStamp.stdout).getTime();
|
||||
|
||||
const dockerImageTime = new Date(pulledImageCreationTimeStamp.stdout).getTime();
|
||||
|
@ -194,6 +191,12 @@ async function isPodmanLocalImageLatest(
|
|||
return podmanImageTime > dockerImageTime;
|
||||
}
|
||||
|
||||
// remove the pulled image from the Podman image storage
|
||||
async function removeDockerImage(): Promise<void> {
|
||||
core.info(`Removing ${imageToPush} from the Podman image storage`);
|
||||
await execute(await getPodmanPath(), [ "rmi", imageToPush ]);
|
||||
}
|
||||
|
||||
async function execute(
|
||||
executable: string,
|
||||
args: string[],
|
||||
|
@ -233,4 +236,10 @@ async function execute(
|
|||
};
|
||||
}
|
||||
|
||||
run().catch(core.setFailed);
|
||||
run()
|
||||
.catch(core.setFailed)
|
||||
.finally(() => {
|
||||
if (isPushingDockerImage) {
|
||||
removeDockerImage();
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue