mirror of
https://github.com/addnab/docker-run-action.git
synced 2025-07-19 07:11:32 +03:00
Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
1cd63ec344 | |||
32e3e5ab6a | |||
e8d1c67284 | |||
fca40d5fe6 | |||
1d5aeada27 | |||
cff4df74be | |||
1e284f150e | |||
07b07c8cd2 | |||
9ad56b3196 |
73
README.md
73
README.md
@ -1,37 +1,64 @@
|
||||
# Docker Run Action
|
||||
|
||||
This action targets a very specific use-case that is not currently supported by Github Workflows. This action gives you the capability to run built containers.
|
||||
Github Workflows already supports running on public docker images out-of-the-box (See [jobs.<jobs_id>.container](https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idcontainer)).
|
||||
|
||||
Docker already supports running commands inside a docker image. See [jobs.<jobs_id>.container](https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idcontainer). But it doesn't give you a clean way to run an image from a private repo or an image built on a previous step.
|
||||
### Why use docker-run-action?
|
||||
- run on a privately-owned image.
|
||||
- run on an image built by a previous step.
|
||||
- run a specific step in docker
|
||||
|
||||
### Example Usage
|
||||
|
||||
#### Standard use-case
|
||||
#### single-line command
|
||||
```yaml
|
||||
- uses: addnab/docker-run-action@v1
|
||||
with:
|
||||
image: docker:latest
|
||||
command: echo "hello world"
|
||||
run: echo "hello world"
|
||||
```
|
||||
|
||||
### Supported Inputs
|
||||
#### multi-line commands
|
||||
```yaml
|
||||
image:
|
||||
description: 'Image'
|
||||
required: true
|
||||
options:
|
||||
description: 'Options'
|
||||
required: false
|
||||
command:
|
||||
description: 'Command'
|
||||
required: false
|
||||
registry:
|
||||
description: 'Registry'
|
||||
required: false
|
||||
username:
|
||||
description: 'Username'
|
||||
required: false
|
||||
password:
|
||||
description: 'Password'
|
||||
required: false
|
||||
- uses: addnab/docker-run-action@v1
|
||||
with:
|
||||
image: docker:latest
|
||||
run: |
|
||||
echo "first line"
|
||||
echo "second line"
|
||||
```
|
||||
|
||||
#### run on a privately-owned image
|
||||
```yaml
|
||||
- uses: addnab/docker-run-action@v1
|
||||
with:
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
registry: gcr.io
|
||||
image: test-image:latest
|
||||
run: echo "hello world"
|
||||
```
|
||||
|
||||
#### run on an image built by a previous step
|
||||
```yaml
|
||||
- uses: docker/build-push-action@v1
|
||||
with:
|
||||
repository: test-image
|
||||
push: false
|
||||
- uses: addnab/docker-run-action@v1
|
||||
with:
|
||||
image: test-image:latest
|
||||
run: echo "hello world"
|
||||
```
|
||||
|
||||
|
||||
#### use a specific shell (default: sh).
|
||||
*Note: The shell must be installed in the container*
|
||||
```yaml
|
||||
- uses: addnab/docker-run-action@v1
|
||||
with:
|
||||
image: docker:latest
|
||||
shell: bash
|
||||
run: |
|
||||
echo "first line"
|
||||
echo "second line"
|
||||
```
|
||||
|
@ -8,9 +8,13 @@ inputs:
|
||||
options:
|
||||
description: 'Options'
|
||||
required: false
|
||||
command:
|
||||
description: 'Command'
|
||||
run:
|
||||
description: 'Run command in container'
|
||||
required: false
|
||||
shell:
|
||||
description: 'Use a specific shell'
|
||||
required: false
|
||||
default: sh
|
||||
registry:
|
||||
description: 'Registry'
|
||||
required: false
|
||||
|
@ -1,7 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
if [ ! -z $INPUT_USERNAME ];
|
||||
then echo $INPUT_USERNAME | docker login $INPUT_REGISTRY -u $INPUT_PASSWORD --password-stdin
|
||||
then echo $INPUT_PASSWORD | docker login $INPUT_REGISTRY -u $INPUT_USERNAME --password-stdin
|
||||
fi
|
||||
|
||||
exec docker run $INPUT_OPTIONS $INPUT_IMAGE $INPUT_COMMAND
|
||||
echo "$INPUT_RUN" | sed -e 's/\\n/;/g' > semicolon_delimited_script
|
||||
|
||||
exec docker run -v "/var/run/docker.sock":"/var/run/docker.sock" $INPUT_OPTIONS --entrypoint=$INPUT_SHELL $INPUT_IMAGE -c "`cat semicolon_delimited_script`"
|
||||
|
Reference in New Issue
Block a user