31 Commits
develop ... v2

Author SHA1 Message Date
4d955dc997 feat: upgrade to v2 2021-02-15 17:26:10 -05:00
e7a9a2b25a Merge pull request #7 from addnab/tests
tests: setup tests
2021-02-15 17:15:51 -05:00
8279676ac5 test: add container network test 2021-02-15 17:13:07 -05:00
a34de16206 test: adding volume mount test 2021-02-15 16:52:12 -05:00
f9c1c286e0 test: test docker version 2021-02-15 16:45:41 -05:00
f451fad679 fix: check if network exists 2021-02-15 16:21:09 -05:00
6321bad333 fix: remove unused workflow 2021-02-15 15:59:37 -05:00
4b731f3709 tests: setup tests 2021-02-15 15:58:29 -05:00
6f0804dd49 docs: using github variables instead of env 2021-02-15 09:26:29 -05:00
e10bcda95f Update README.md 2021-02-15 01:27:21 -05:00
702ff8ec17 Update README.md 2021-02-15 01:12:38 -05:00
e48328783a Merge pull request #3 from heyman/docker-networks
Docker networks
2021-02-15 00:49:24 -05:00
c0e88e3a9a Remove whitespace change 2021-01-28 17:13:38 +01:00
3cf4359b92 Remove debug logging 2021-01-28 17:01:59 +01:00
a42f5acd32 Revert "Use env variable for docker network id, instead of github action input"
This reverts commit 23e2be876e.
2021-01-28 17:00:10 +01:00
23e2be876e Use env variable for docker network id, instead of github action input 2021-01-28 16:54:08 +01:00
faad629471 Connect container to github job docker network 2021-01-28 16:44:05 +01:00
8bce4aa10a Add docker_network input 2021-01-28 16:39:33 +01:00
f3a2d182d8 Debug 2021-01-28 16:22:09 +01:00
27808d9e5f Update README.md 2021-01-09 15:29:20 -05:00
56a9143b97 Update README.md 2021-01-04 16:09:39 -05:00
68f0bc9ea0 docs: options (fixes #1) 2021-01-04 15:54:00 -05:00
1cd63ec344 fix: exposing docker socket for DinD 2020-06-24 15:16:56 -04:00
32e3e5ab6a Update README.md 2020-06-19 20:36:37 -04:00
e8d1c67284 fix login 2020-06-17 22:21:03 -04:00
fca40d5fe6 override entrypoint 2020-06-17 21:53:32 -04:00
1d5aeada27 docs for privately owned image 2020-06-17 21:39:34 -04:00
cff4df74be run on specific shell 2020-06-17 21:21:47 -04:00
1e284f150e fix run variable name 2020-06-17 21:04:51 -04:00
07b07c8cd2 update README 2020-06-17 21:02:26 -04:00
9ad56b3196 multiline support 2020-06-17 21:00:26 -04:00
5 changed files with 148 additions and 33 deletions

72
.github/workflows/tests.yml vendored Normal file
View File

@ -0,0 +1,72 @@
name: Docker Run Action Tests
on:
push:
branches:
- main
pull_request:
jobs:
smoke-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run docker action and set output for testing
uses: ./
id: run-docker
with:
image: docker:20.10.3
run: |
echo "::set-output name=docker-version::`echo $DOCKER_VERSION`"
- name: Test the output
uses: actions/github-script@v3
with:
script: |
const dockerVersion = '${{ steps.run-docker.outputs.docker-version }}';
if (dockerVersion !== '20.10.3') {
core.setFailed(`Smoke Test Failed`);
}
volume-mount-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Create File to be mounted
run: echo "some text" > someFile
- name: Run docker action with mounted workspace
uses: ./
id: run-docker
with:
image: docker
options: -v ${{ github.workspace }}:/work
run: |
echo "::set-output name=file-contents::`cat /work/someFile`"
- name: Check if file contents match
uses: actions/github-script@v3
with:
script: |
const fileContents = '${{ steps.run-docker.outputs.file-contents }}';
if (fileContents !== 'some text') {
core.setFailed(`Unable to mount workspace volume`);
}
container-network-test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: test
POSTGRES_USER: test
POSTGRES_DB: test
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 5s --health-timeout 5s --health-retries 10
steps:
- uses: actions/checkout@v2
- name: Run docker action and test network connection
uses: ./
with:
image: postgres
run: >
pg_isready -d test -U test -h postgres -p ${{ job.services.postgres.ports[5432] }}
options: >
-e PGPASSWORD=test

View File

@ -1,37 +1,56 @@
# 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.
- run a specific step in docker.
- run an image built by a previous step.
- See https://github.com/addnab/docker-run-action/blob/main/action.yml for all the available inputs.
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.
#### Typical Use Case
### Example Usage
#### Standard use-case
```yaml
- uses: addnab/docker-run-action@v1
- uses: addnab/docker-run-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
registry: gcr.io
image: private-image:latest
options: -v ${{ github.workspace }}:/work -e ABC=123
run: |
echo "Running Script"
/work/run-script
```
#### run a privately-owned image
```yaml
- uses: addnab/docker-run-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
registry: gcr.io
image: test-image:latest
run: echo "hello world"
```
#### run 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@v2
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@v2
with:
image: docker:latest
command: echo "hello world"
```
### Supported Inputs
```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
shell: bash
run: |
echo "first line"
echo "second line"
```

10
RELEASES.md Normal file
View File

@ -0,0 +1,10 @@
# addnab/docker-run-action Releases
### 2.0.0
- Added support for networking with other containers [#3](https://github.com/addnab/docker-run-action/pull/3) [#7](https://github.com/addnab/docker-run-action/pull/7)
- Added tests [#7](https://github.com/addnab/docker-run-action/pull/7)
### 1.0.0
- Initial release

View File

@ -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
@ -20,6 +24,10 @@ inputs:
password:
description: 'Password'
required: false
docker_network:
description: 'Docker Network ID'
default: ${{ job.container.network }}
retuired: false
runs:
using: 'docker'
image: 'Dockerfile'

View File

@ -1,7 +1,13 @@
#!/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
if [ ! -z $INPUT_DOCKER_NETWORK ];
then INPUT_OPTIONS="$INPUT_OPTIONS --network $INPUT_DOCKER_NETWORK"
fi
exec docker run -v "/var/run/docker.sock":"/var/run/docker.sock" $INPUT_OPTIONS --entrypoint=$INPUT_SHELL $INPUT_IMAGE -c "`cat semicolon_delimited_script`"