Skip to content

Commit

Permalink
Add docker-run-args option (#794)
Browse files Browse the repository at this point in the history
  • Loading branch information
int128 authored Oct 12, 2024
1 parent 974e6e5 commit 8d7b0bf
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 11 deletions.
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,19 @@ See also the flags of [Kaniko executor](https://github.com/GoogleContainerTools/
| `executor` | Image of Kaniko executor. Default to `gcr.io/kaniko-project/executor:v1.23.2` | - |
| `context` <sup>\*1</sup> | Path to the build context. Default to the workspace | - |
| `file` <sup>\*1</sup> | Path to the Dockerfile. Default to `Dockerfile`. It must be in the context. If set, this action passes the relative path to Kaniko, same as the behavior of [`docker build`](https://docs.docker.com/engine/reference/commandline/build/) | `--dockerfile` |
| `build-args` <sup>\*1</sup> | List of build args | `--build-arg` |
| `labels` <sup>\*1</sup> | List of metadata for an image | `--label` |
| `build-args` <sup>\*1</sup> | List of build args (multiline) | `--build-arg` |
| `labels` <sup>\*1</sup> | List of metadata for an image (multiline) | `--label` |
| `push` <sup>\*1</sup> | Push an image to the registry. Default to false | `--no-push` |
| `tags` <sup>\*1</sup> | List of tags | `--destination` |
| `tags` <sup>\*1</sup> | List of tags (multiline) | `--destination` |
| `target` <sup>\*1</sup> | Target stage to build | `--target` |
| `cache` | Enable caching layers | `--cache` |
| `cache-repository` | Repository for storing cached layers | `--cache-repo` |
| `cache-ttl` | Cache timeout | `--cache-ttl` |
| `push-retry` | Number of retries for the push of an image | `--push-retry` |
| `registry-mirror` | Use registry mirror(s) | `--registry-mirror` |
| `registry-mirror` | Use registry mirror(s) (multiline) | `--registry-mirror` |
| `verbosity` | Set the logging level | `--verbosity` |
| `kaniko-args` | Extra args to Kaniko executor (multiline string) | - |
| `kaniko-args` | Extra args to Kaniko executor (multiline) | - |
| `docker-run-args` | Extra args to docker run (multiline) | - |

<sup>\*1</sup> These inputs are compatible with [docker/build-push-action](https://github.com/docker/build-push-action).

Expand Down Expand Up @@ -167,7 +168,7 @@ jobs:

### Pass extra args to Kaniko executor

You can pass extra arguments in a multiline string.
You can pass extra arguments to Kaniko executor in a multiline string.

```yaml
- uses: int128/kaniko-action@v1
Expand All @@ -176,3 +177,15 @@ You can pass extra arguments in a multiline string.
--key=value
--key
```
### Pass extra args to docker run
You can pass extra arguments to `docker run` command in a multiline string.

```yaml
- uses: int128/kaniko-action@v1
with:
docker-run-args: |
-v
/secrets:/secrets:ro
```
13 changes: 8 additions & 5 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,21 @@ inputs:
description: Number of retries for the push of an image
required: false
registry-mirror:
description: Use registry mirror(s)
description: Use registry mirror(s) (multiline)
required: false
verbosity:
description: Set the logging level
required: false
kaniko-args:
description: Extra args to Kaniko executor
description: Extra args to Kaniko executor (multiline)
required: false
docker-run-args:
description: Extra args to docker run (multiline)
required: false

# compatible with https://github.com/docker/build-push-action
build-args:
description: List of build args
description: List of build args (multiline)
required: false
context:
description: Path to the build context
Expand All @@ -40,14 +43,14 @@ inputs:
description: Path to the Dockerfile
required: false
labels:
description: List of metadata for an image
description: List of metadata for an image (multiline)
required: false
push:
description: Push an image to the registry
required: true
default: 'false'
tags:
description: List of tags
description: List of tags (multiline)
required: false
target:
description: Target stage to build
Expand Down
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const main = async (): Promise<void> => {
registryMirrors: core.getMultilineInput('registry-mirror'),
verbosity: core.getInput('verbosity'),
kanikoArgs: core.getMultilineInput('kaniko-args'),
dockerRunArgs: core.getMultilineInput('docker-run-args'),
buildArgs: core.getMultilineInput('build-args'),
context: core.getInput('context'),
file: core.getInput('file'),
Expand Down
3 changes: 3 additions & 0 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Inputs = {
push: boolean
tags: string[]
target: string
dockerRunArgs: string[]
}

type Outputs = {
Expand Down Expand Up @@ -65,6 +66,8 @@ export const generateArgs = (inputs: Inputs, outputsDir: string): string[] => {
// https://github.com/GoogleContainerTools/kaniko/issues/1542#issuecomment-1066028047
'-e',
'container=docker',
...inputs.dockerRunArgs,
// executor
inputs.executor,
// kaniko args
'--context',
Expand Down
5 changes: 5 additions & 0 deletions tests/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const defaultInputs = {
push: false,
tags: [],
target: '',
dockerRunArgs: [],
}

test('default args', () => {
Expand Down Expand Up @@ -61,6 +62,7 @@ test('full args', () => {
push: false,
tags: ['helloworld:latest', 'ghcr.io/int128/kaniko-action/example:v1.0.0'],
target: 'server',
dockerRunArgs: ['-v', '/secrets:/secrets:ro'],
},
'/tmp/kaniko-action',
)
Expand All @@ -76,6 +78,9 @@ test('full args', () => {
`${os.homedir()}/.docker/:/kaniko/.docker/:ro`,
'-e',
'container=docker',
'-v',
'/secrets:/secrets:ro',
// executor
'gcr.io/kaniko-project/executor:latest',
// kaniko args
'--context',
Expand Down

0 comments on commit 8d7b0bf

Please sign in to comment.