mirror of
https://github.com/redhat-actions/push-to-registry.git
synced 2025-05-02 03:09:54 +02:00
Warn user if input image and registry both have /
(#39)
Signed-off-by: divyansh42 <diagrawa@redhat.com>
This commit is contained in:
parent
6a46770abc
commit
984901b4bb
10 changed files with 260 additions and 123 deletions
|
@ -16,7 +16,7 @@ export enum Inputs {
|
|||
*/
|
||||
EXTRA_ARGS = "extra-args",
|
||||
/**
|
||||
* Name of the image to push
|
||||
* Name of the image to push (e.g. username/imagename or imagename)
|
||||
* Required: true
|
||||
* Default: None.
|
||||
*/
|
||||
|
@ -28,7 +28,7 @@ export enum Inputs {
|
|||
*/
|
||||
PASSWORD = "password",
|
||||
/**
|
||||
* Registry where to push the image (eg. quay.io/username)
|
||||
* Hostname and optional namespace to push the image to (eg. quay.io/username or quay.io)
|
||||
* Required: true
|
||||
* Default: None.
|
||||
*/
|
||||
|
|
41
src/index.ts
41
src/index.ts
|
@ -44,7 +44,7 @@ async function run(): Promise<void> {
|
|||
tagsList = tags.split(" ");
|
||||
|
||||
// info message if user doesn't provides any tag
|
||||
if (!tagsList.length) {
|
||||
if (tagsList.length === 0) {
|
||||
core.info(`Input "${Inputs.TAGS}" is not provided, using default tag "${DEFAULT_TAG}"`);
|
||||
tagsList.push(DEFAULT_TAG);
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ async function run(): Promise<void> {
|
|||
// failing if image with any of the tag is not found in Docker as well as Podman
|
||||
if (podmanMissingTags.length > 0 && dockerMissingTags.length > 0) {
|
||||
throw new Error(
|
||||
`All tags for "${imageToPush}" were not found in either Podman image storage, or Docker image storage. `
|
||||
`❌ All tags for "${imageToPush}" were not found in either Podman image storage, or Docker image storage. `
|
||||
+ `Tag${podmanMissingTags.length !== 1 ? "s" : ""} "${podmanMissingTags.join(", ")}" `
|
||||
+ `not found in Podman image storage, and tag${dockerMissingTags.length !== 1 ? "s" : ""} `
|
||||
+ `"${dockerMissingTags.join(", ")}" not found in Docker image storage.`
|
||||
|
@ -149,15 +149,13 @@ async function run(): Promise<void> {
|
|||
);
|
||||
}
|
||||
|
||||
let pushMsg = `Pushing "${imageToPush}" with tag${tagsList.length !== 1 ? "s" : ""} `
|
||||
let pushMsg = `⏳ Pushing "${imageToPush}" with tag${tagsList.length !== 1 ? "s" : ""} `
|
||||
+ `"${tagsList.join(", ")}" to "${registry}"`;
|
||||
if (username) {
|
||||
pushMsg += ` as "${username}"`;
|
||||
}
|
||||
core.info(pushMsg);
|
||||
|
||||
const registryWithoutTrailingSlash = registry.replace(/\/$/, "");
|
||||
|
||||
let creds = "";
|
||||
if (username && !password) {
|
||||
core.warning("Username is provided, but password is missing");
|
||||
|
@ -178,18 +176,27 @@ async function run(): Promise<void> {
|
|||
)}_digest.txt`;
|
||||
}
|
||||
|
||||
const registryWithoutTrailingSlash = registry.replace(/\/$/, "");
|
||||
const registryPath = `${registryWithoutTrailingSlash}/${imageInput}`;
|
||||
core.info(`Combining image name "${imageInput}" and registry "${registry}" `
|
||||
+ `to form registry path "${registryPath}"`);
|
||||
|
||||
if (imageInput.indexOf("/") > -1 && registry.indexOf("/") > -1) {
|
||||
core.warning(`"${registryPath}" does not seem to be a valid registry path. `
|
||||
+ `The registry path should not contain more than 2 slashes. `
|
||||
+ `Refer to the Inputs section of the readme for naming image and registry.`);
|
||||
}
|
||||
|
||||
// push the image
|
||||
for (const tag of tagsList) {
|
||||
const imageWithTag = `${imageToPush}:${tag}`;
|
||||
const registryPath = `${registryWithoutTrailingSlash}/${imageInput}:${tag}`;
|
||||
|
||||
const args = [
|
||||
"push",
|
||||
"--quiet",
|
||||
"--digestfile",
|
||||
digestFile,
|
||||
imageWithTag,
|
||||
registryPath,
|
||||
`${registryPath}:${tag}`,
|
||||
];
|
||||
|
||||
if (podmanExtraArgs.length > 0) {
|
||||
|
@ -207,7 +214,7 @@ async function run(): Promise<void> {
|
|||
}
|
||||
|
||||
await execute(await getPodmanPath(), args);
|
||||
core.info(`Successfully pushed "${imageWithTag}" to "${registryPath}"`);
|
||||
core.info(`✅ Successfully pushed "${imageWithTag}" to "${registryPath}"`);
|
||||
|
||||
registryPathList.push(registryPath);
|
||||
|
||||
|
@ -228,7 +235,7 @@ async function run(): Promise<void> {
|
|||
}
|
||||
|
||||
async function pullImageFromDocker(): Promise<ImageStorageCheckResult> {
|
||||
core.info(`Checking if "${imageToPush}" with tag${tagsList.length !== 1 ? "s" : ""} `
|
||||
core.info(`🔍 Checking if "${imageToPush}" with tag${tagsList.length !== 1 ? "s" : ""} `
|
||||
+ `"${tagsList.join(", ")}" is present in Docker image storage`);
|
||||
let imageWithTag;
|
||||
const foundTags: string[] = [];
|
||||
|
@ -241,7 +248,7 @@ async function pullImageFromDocker(): Promise<ImageStorageCheckResult> {
|
|||
[ "pull", `docker-daemon:${imageWithTag}` ],
|
||||
{ ignoreReturnCode: true, failOnStdErr: false, group: true }
|
||||
);
|
||||
if (!commandResult.exitCode) {
|
||||
if (commandResult.exitCode === 0) {
|
||||
foundTags.push(tag);
|
||||
}
|
||||
else {
|
||||
|
@ -261,7 +268,7 @@ async function pullImageFromDocker(): Promise<ImageStorageCheckResult> {
|
|||
|
||||
async function checkImageInPodman(): Promise<ImageStorageCheckResult> {
|
||||
// check if images exist in Podman's storage
|
||||
core.info(`Checking if "${imageToPush}" with tag${tagsList.length !== 1 ? "s" : ""} `
|
||||
core.info(`🔍 Checking if "${imageToPush}" with tag${tagsList.length !== 1 ? "s" : ""} `
|
||||
+ `"${tagsList.join(", ")}" is present in Podman image storage`);
|
||||
let imageWithTag;
|
||||
const foundTags: string[] = [];
|
||||
|
@ -274,7 +281,7 @@ async function checkImageInPodman(): Promise<ImageStorageCheckResult> {
|
|||
[ "image", "exists", imageWithTag ],
|
||||
{ ignoreReturnCode: true }
|
||||
);
|
||||
if (!commandResult.exitCode) {
|
||||
if (commandResult.exitCode === 0) {
|
||||
foundTags.push(tag);
|
||||
}
|
||||
else {
|
||||
|
@ -388,9 +395,11 @@ async function execute(
|
|||
}
|
||||
|
||||
run()
|
||||
.catch(core.setFailed)
|
||||
.finally(() => {
|
||||
.then(async () => {
|
||||
if (isImageFromDocker) {
|
||||
removeDockerImage();
|
||||
await removeDockerImage();
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
core.setFailed(err.message);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue