mirror of
https://github.com/redhat-actions/push-to-registry.git
synced 2025-02-23 02:21:22 +01:00
fix docker issue
Signed-off-by: Luca Stocchi <lstocchi@redhat.com>
This commit is contained in:
parent
671216bac8
commit
19ea479591
5 changed files with 39 additions and 13 deletions
|
@ -8,7 +8,11 @@ inputs:
|
||||||
image-to-push:
|
image-to-push:
|
||||||
description: 'Name of the new image that will be pushed'
|
description: 'Name of the new image that will be pushed'
|
||||||
required: true
|
required: true
|
||||||
quay-registry:
|
tag:
|
||||||
|
description: 'Tag of the new image'
|
||||||
|
required: false
|
||||||
|
default: 'latest'
|
||||||
|
registry:
|
||||||
description: 'Quay repo where to push the image'
|
description: 'Quay repo where to push the image'
|
||||||
required: true
|
required: true
|
||||||
username:
|
username:
|
||||||
|
|
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
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "push-to-quay-action",
|
"name": "push-to-registry",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"description": "Action to push images to quay",
|
"description": "Action to push images to registry",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"compile": "tsc -p .",
|
"compile": "tsc -p .",
|
||||||
|
@ -9,7 +9,7 @@
|
||||||
"clean": "rm -rf out/ dist/",
|
"clean": "rm -rf out/ dist/",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
"author": "Luca",
|
"author": "Red Hat",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.2.6",
|
"@actions/core": "^1.2.6",
|
||||||
|
|
36
src/index.ts
36
src/index.ts
|
@ -5,35 +5,57 @@ import { CommandResult } from './types';
|
||||||
|
|
||||||
export async function run(): Promise<void> {
|
export async function run(): Promise<void> {
|
||||||
const imageToPush = core.getInput('image-to-push');
|
const imageToPush = core.getInput('image-to-push');
|
||||||
const quayRegistry = core.getInput('quay-registry');
|
const tag = core.getInput('tag') || 'latest';
|
||||||
|
const registry = core.getInput('registry');
|
||||||
const username = core.getInput('username');
|
const username = core.getInput('username');
|
||||||
const password = core.getInput('password');
|
const password = core.getInput('password');
|
||||||
|
|
||||||
// get podman cli
|
// get podman cli
|
||||||
const podman = await io.which('podman', true);
|
const podman = await io.which('podman', true);
|
||||||
|
|
||||||
|
//check if images exist in podman's local storage
|
||||||
|
const checkImages: CommandResult = await execute(podman, ['images', '--format', 'json']);
|
||||||
|
if (checkImages.succeeded === false) {
|
||||||
|
return Promise.reject(new Error(checkImages.reason));
|
||||||
|
}
|
||||||
|
const parsedCheckImages = JSON.parse(checkImages.output);
|
||||||
|
const imagesFound = parsedCheckImages.
|
||||||
|
filter(image => image.names && image.names.find(name => name.includes("alpine:latewst"))).
|
||||||
|
map(image => image.names);
|
||||||
|
if (imagesFound.length === 0) {
|
||||||
|
//check inside the docker daemon local storage
|
||||||
|
const pullFromDocker: CommandResult = await execute(podman, ['pull', `docker-daemon:${imageToPush}:${tag}`]);
|
||||||
|
if (pullFromDocker.succeeded === false) {
|
||||||
|
return Promise.reject(new Error(`Unable to find the image to push`));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// push image
|
// push image
|
||||||
const push: CommandResult = await execute(podman, ['push', '--creds', `${username}:${password}`, `${imageToPush}`, `${quayRegistry}`]);
|
const registryUrl = `${registry.replace(/\/$/, '')}:${tag}`;
|
||||||
|
const push: CommandResult = await execute(podman, ['push', '--creds', `${username}:${password}`, `${imageToPush}`, `${registryUrl}`]);
|
||||||
if (push.succeeded === false) {
|
if (push.succeeded === false) {
|
||||||
return Promise.reject(new Error(push.reason));
|
return Promise.reject(new Error(push.reason));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function execute(executable: string, args: string[]): Promise<CommandResult> {
|
async function execute(executable: string, args: string[]): Promise<CommandResult> {
|
||||||
|
let output = '';
|
||||||
let error = '';
|
let error = '';
|
||||||
|
|
||||||
const options: exec.ExecOptions = {};
|
const options: exec.ExecOptions = {};
|
||||||
options.listeners = {
|
options.listeners = {
|
||||||
|
stdout: (data: Buffer): void => {
|
||||||
|
output += data.toString();
|
||||||
|
},
|
||||||
stderr: (data: Buffer): void => {
|
stderr: (data: Buffer): void => {
|
||||||
error += data.toString();
|
error += data.toString();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const exitCode = await exec.exec(executable, args, options);
|
const exitCode = await exec.exec(executable, args, options);
|
||||||
if (exitCode === 1) {
|
if (exitCode === 1) {
|
||||||
return Promise.resolve({ succeeded: false, error: error });
|
return Promise.resolve({ succeeded: false, error });
|
||||||
}
|
}
|
||||||
return Promise.resolve({ succeeded: true });
|
return Promise.resolve({ succeeded: true, output });
|
||||||
}
|
}
|
||||||
|
|
||||||
run().catch(core.setFailed);
|
run().catch(core.setFailed);
|
Loading…
Add table
Reference in a new issue