fix issue with pushing docker image

Signed-off-by: Luca Stocchi <lstocchi@redhat.com>
This commit is contained in:
Luca Stocchi 2020-11-16 14:06:29 +01:00
parent 9f4af4759e
commit e335d23f38
No known key found for this signature in database
GPG key ID: 930BB00F3FCF30A4
5 changed files with 50 additions and 8 deletions

View file

@ -24,7 +24,7 @@ Push-to-registry is a GitHub Action for pushing an OCI-compatible image to any r
<tr>
<td>registry</td>
<td>(Required) Registry where to push the image. E.g https://quay.io/yourusername/yourrepo</td>
<td>(Required) Registry where to push the image. E.g https://quay.io/username</td>
</tr>
<tr>
@ -38,6 +38,47 @@ Push-to-registry is a GitHub Action for pushing an OCI-compatible image to any r
</tr>
</table>
## Examples
The example below shows how the `push-to-registry` action can be used to push an image created by the [`buildah-action`](https://github.com/redhat-actions/buildah-action) in an early step.
```
name: CI
on: [push]
jobs:
build:
name: Build image
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Maven
run: |
cd ${GITHUB_WORKSPACE}
mvn package
- name: Build Action
uses: redhat-actions/buildah-action@0.0.1
with:
new-image-name: petclinic
content: |
target/spring-petclinic-2.3.0.BUILD-SNAPSHOT.jar
entrypoint: |
java
-jar
spring-petclinic-2.3.0.BUILD-SNAPSHOT.jar
port: 8080
- name: Push To Quay
uses: redhat-actions/push-to-registry@0.0.1
with:
image-to-push: petclinic
registry: ${{ secrets.QUAY_REPO }}
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}
```
## Contributing

View file

@ -13,7 +13,7 @@ inputs:
required: false
default: 'latest'
registry:
description: 'Quay repo where to push the image'
description: 'Registry where to push the image (e.g quay.io/username)'
required: true
username:
description: 'Username to use as credential to authenticate to the registry'

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View file

@ -4,7 +4,7 @@ import * as io from '@actions/io';
import { CommandResult } from './types';
export async function run(): Promise<void> {
const imageToPush = core.getInput('image-to-push');
let imageToPush = core.getInput('image-to-push');
const tag = core.getInput('tag') || 'latest';
const registry = core.getInput('registry');
const username = core.getInput('username');
@ -13,6 +13,7 @@ export async function run(): Promise<void> {
// get podman cli
const podman = await io.which('podman', true);
imageToPush = `${imageToPush}:${tag}`;
//check if images exist in podman's local storage
const checkImages: CommandResult = await execute(podman, ['images', '--format', 'json']);
if (checkImages.succeeded === false) {
@ -22,18 +23,18 @@ export async function run(): Promise<void> {
// this is to temporarily solve an issue with the case-sensitive of the property field name. i.e it is Names or names??
const nameKeyMixedCase = parsedCheckImages[0] && Object.keys(parsedCheckImages[0]).find(key => 'names' === key.toLowerCase());
const imagesFound = parsedCheckImages.
filter(image => image[nameKeyMixedCase] && image[nameKeyMixedCase].find(name => name.includes(`${imageToPush}:${tag}`))).
filter(image => image[nameKeyMixedCase] && image[nameKeyMixedCase].find(name => name.includes(`${imageToPush}`))).
map(image => image[nameKeyMixedCase]);
if (imagesFound.length === 0) {
//check inside the docker daemon local storage
const pullFromDocker: CommandResult = await execute(podman, ['pull', `docker-daemon:${imageToPush}:${tag}`]);
const pullFromDocker: CommandResult = await execute(podman, ['pull', `docker-daemon:${imageToPush}`]);
if (pullFromDocker.succeeded === false) {
return Promise.reject(new Error(`Unable to find the image to push`));
}
}
// push image
const registryUrl = `${registry.replace(/\/$/, '')}:${tag}`;
const registryUrl = `${registry.replace(/\/$/, '')}/${imageToPush}`;
const push: CommandResult = await execute(podman, ['push', '--creds', `${username}:${password}`, `${imageToPush}`, `${registryUrl}`]);
if (push.succeeded === false) {
return Promise.reject(new Error(push.reason));