mirror of
https://github.com/redhat-actions/push-to-registry.git
synced 2025-02-22 18:21:20 +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:
|
||||
description: 'Name of the new image that will be pushed'
|
||||
required: true
|
||||
quay-registry:
|
||||
tag:
|
||||
description: 'Tag of the new image'
|
||||
required: false
|
||||
default: 'latest'
|
||||
registry:
|
||||
description: 'Quay repo where to push the image'
|
||||
required: true
|
||||
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",
|
||||
"description": "Action to push images to quay",
|
||||
"description": "Action to push images to registry",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"compile": "tsc -p .",
|
||||
|
@ -9,7 +9,7 @@
|
|||
"clean": "rm -rf out/ dist/",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "Luca",
|
||||
"author": "Red Hat",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@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> {
|
||||
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 password = core.getInput('password');
|
||||
const password = core.getInput('password');
|
||||
|
||||
// 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
|
||||
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) {
|
||||
return Promise.reject(new Error(push.reason));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async function execute(executable: string, args: string[]): Promise<CommandResult> {
|
||||
let output = '';
|
||||
let error = '';
|
||||
|
||||
const options: exec.ExecOptions = {};
|
||||
options.listeners = {
|
||||
stdout: (data: Buffer): void => {
|
||||
output += data.toString();
|
||||
},
|
||||
stderr: (data: Buffer): void => {
|
||||
error += data.toString();
|
||||
}
|
||||
};
|
||||
const exitCode = await exec.exec(executable, args, options);
|
||||
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);
|
Loading…
Add table
Reference in a new issue