Skip to content

Commit

Permalink
Docker json config parameter + linting (#86)
Browse files Browse the repository at this point in the history
* lint + added parameter
* updated package json
* updated licenses.txt file
* README linting
* Updating action.yml
  • Loading branch information
rnsc authored Jul 2, 2021
1 parent 646e5fc commit 0b1ac42
Show file tree
Hide file tree
Showing 8 changed files with 527 additions and 235 deletions.
29 changes: 23 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
# tag-push-action

## About

Github action to retag and push multiplatform images to multiple registries

> :bulb: See also:
>
> * [login](https://github.com/docker/login-action) action
> * [docker-meta](https://github.com/crazy-max/ghaction-docker-meta) action
This action heavily relies on work done by [@tonistiigi](https://github.com/tonistiigi/repo-copy) and [@crazymax](https://github.com/docker/metadata-action)

## Usage

#### Basic
### Basic

```yaml
name: Push-Image

Expand Down Expand Up @@ -42,16 +46,15 @@ jobs:
quay.io/akhilerm/node-disk-manager-amd64:ci
```
1. Login to all the registries from which you want to pull and push the multiplatform image.
1. Login to all the registries from which you want to pull and push the multiplatform image.
**NOTE: The source registry should be logged in after all destination regisries are logged in.**
**NOTE: The source registry should be logged in after all destination registries are logged in.**
2. Specify the `src` and `dst` registry, both of which are mandatory fields. The action allows multiple destination
registries specified as a yaml string.
2. Specify the `src` and `dst` registry, both of which are mandatory fields. The action allows multiple destination registries specified as a yaml string.

**NOTE: If dockerhub is used, make sure that `docker.io` is specified in the image name**

#### Using with `docker/metadata-action`
### Using with `docker/metadata-action`

The action can be used alongside [metadata-action](https://github.com/docker/metadata-action) to generate
tags easily.
Expand Down Expand Up @@ -87,3 +90,17 @@ jobs:
```

The output tags from the `meta` step can be used as destination tags for this github action.

### Use a custom docker config file

The standard docker config path on GitHub runner is `/home/runner/.docker/config.json`. In case you're running on a custom GitHub runner, and your config path is not standard, then the `docker-config-path` can be used.

```yaml
- name: Push image
uses: akhilerm/[email protected]
with:
docker-config-path: /home/myuser/.docker/config.json
src: docker.io/akhilerm/node-disk-manager:ci
dst: |
quay.io/akhilerm/node-disk-manager-amd64:ci
```
47 changes: 29 additions & 18 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,43 @@
import * as main from '../src/main';
import * as main from '../src/main'

describe('getDestinationTags', () => {
it('single image', async () => {
await setInput('dst', 'akhilerm/linux-utils:ci');
const res = await main.getDestinationTags();
expect(res).toEqual(['akhilerm/linux-utils:ci']);
});
await setInput('dst', 'akhilerm/linux-utils:ci')
const res = await main.getDestinationTags()
expect(res).toEqual(['akhilerm/linux-utils:ci'])
})

it('multiple images', async () => {
await setInput('dst', 'akhilerm/linux-utils:ci\nquay.io/akhilerm/linux-utils:ci');
const res = await main.getDestinationTags();
expect(res).toEqual(['akhilerm/linux-utils:ci', 'quay.io/akhilerm/linux-utils:ci']);
});
await setInput(
'dst',
'akhilerm/linux-utils:ci\nquay.io/akhilerm/linux-utils:ci'
)
const res = await main.getDestinationTags()
expect(res).toEqual([
'akhilerm/linux-utils:ci',
'quay.io/akhilerm/linux-utils:ci'
])
})

it('multiline images', async () => {
await setInput('dst', `akhilerm/linux-utils:ci
quay.io/akhilerm/linux-utils:ci`);
const res = await main.getDestinationTags();
expect(res).toEqual(['akhilerm/linux-utils:ci', 'quay.io/akhilerm/linux-utils:ci']);
});
});
await setInput(
'dst',
`akhilerm/linux-utils:ci
quay.io/akhilerm/linux-utils:ci`
)
const res = await main.getDestinationTags()
expect(res).toEqual([
'akhilerm/linux-utils:ci',
'quay.io/akhilerm/linux-utils:ci'
])
})
})

function setInput(name: string, value: string): void {
process.env[getInputName(name)] = value;
process.env[getInputName(name)] = value
}

// See: https://github.com/actions/toolkit/blob/master/packages/core/src/core.ts#L67
function getInputName(name: string): string {
return `INPUT_${name.replace(/ /g, '_').toUpperCase()}`;
return `INPUT_${name.replace(/ /g, '_').toUpperCase()}`
}

3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ inputs:
dst:
required: true
description: 'Destination tags'
docker-config-path:
required: false
description: 'Docker config file path'
runs:
using: 'node12'
main: 'dist/index.js'
Loading

0 comments on commit 0b1ac42

Please sign in to comment.