Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
940e86ea21 | ||
|
|
b1bd71bac3 | ||
|
|
cf18d277e1 | ||
|
|
a0a75b001b | ||
|
|
d94e0f37db |
72
.github/workflows/tests.yml
vendored
72
.github/workflows/tests.yml
vendored
@@ -1,72 +0,0 @@
|
|||||||
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
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
FROM docker:20.10
|
FROM docker:19.03
|
||||||
|
|
||||||
RUN apk add bash
|
RUN apk add bash
|
||||||
|
|
||||||
|
|||||||
79
README.md
79
README.md
@@ -1,60 +1,37 @@
|
|||||||
# Docker Run Action
|
# Docker Run Action
|
||||||
|
|
||||||
- run a specific step in docker.
|
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 an image built by a previous step.
|
|
||||||
- See https://github.com/addnab/docker-run-action/blob/main/action.yml for all the available inputs.
|
|
||||||
|
|
||||||
## Examples
|
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
|
```yaml
|
||||||
- name: Checkout
|
- uses: addnab/docker-run-action@v1
|
||||||
uses: actions/checkout@v2 # Required to mount the Github Workspace to a volume
|
|
||||||
- uses: addnab/docker-run-action@v3
|
|
||||||
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@v3
|
|
||||||
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@v2
|
|
||||||
with:
|
|
||||||
tags: test-image:latest
|
|
||||||
push: false
|
|
||||||
- uses: addnab/docker-run-action@v3
|
|
||||||
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@v3
|
|
||||||
with:
|
with:
|
||||||
image: docker:latest
|
image: docker:latest
|
||||||
shell: bash
|
command: echo "hello world"
|
||||||
run: |
|
```
|
||||||
echo "first line"
|
|
||||||
echo "second line"
|
### 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
|
||||||
```
|
```
|
||||||
|
|||||||
14
RELEASES.md
14
RELEASES.md
@@ -1,14 +0,0 @@
|
|||||||
# addnab/docker-run-action Releases
|
|
||||||
|
|
||||||
### 3.0.0
|
|
||||||
|
|
||||||
- Upgrade to docker 20.10 https://github.com/addnab/docker-run-action/pull/12
|
|
||||||
|
|
||||||
### 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
|
|
||||||
15
action.yml
15
action.yml
@@ -2,22 +2,15 @@
|
|||||||
name: 'Docker Run Action'
|
name: 'Docker Run Action'
|
||||||
description: 'Run a command in a new container'
|
description: 'Run a command in a new container'
|
||||||
inputs:
|
inputs:
|
||||||
tarball:
|
|
||||||
description: 'Image tarball'
|
|
||||||
required: false
|
|
||||||
image:
|
image:
|
||||||
description: 'Image'
|
description: 'Image'
|
||||||
required: true
|
required: true
|
||||||
options:
|
options:
|
||||||
description: 'Options'
|
description: 'Options'
|
||||||
required: false
|
required: false
|
||||||
run:
|
command:
|
||||||
description: 'Run command in container'
|
description: 'Command'
|
||||||
required: false
|
required: false
|
||||||
shell:
|
|
||||||
description: 'Use a specific shell'
|
|
||||||
required: false
|
|
||||||
default: sh
|
|
||||||
registry:
|
registry:
|
||||||
description: 'Registry'
|
description: 'Registry'
|
||||||
required: false
|
required: false
|
||||||
@@ -27,10 +20,6 @@ inputs:
|
|||||||
password:
|
password:
|
||||||
description: 'Password'
|
description: 'Password'
|
||||||
required: false
|
required: false
|
||||||
docker_network:
|
|
||||||
description: 'Docker Network ID'
|
|
||||||
default: ${{ job.container.network }}
|
|
||||||
required: false
|
|
||||||
runs:
|
runs:
|
||||||
using: 'docker'
|
using: 'docker'
|
||||||
image: 'Dockerfile'
|
image: 'Dockerfile'
|
||||||
|
|||||||
@@ -1,16 +1,9 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
if [ ! -z $INPUT_USERNAME ];
|
if [ ! -z $INPUT_USERNAME ];
|
||||||
then echo $INPUT_PASSWORD | docker login $INPUT_REGISTRY -u $INPUT_USERNAME --password-stdin
|
then echo $INPUT_USERNAME | docker login $INPUT_REGISTRY -u $INPUT_PASSWORD --password-stdin
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -z $INPUT_DOCKER_NETWORK ];
|
echo "$INPUT_COMMAND" | sed -e 's/\\n/;/g' > semicolon_delimited_script
|
||||||
then INPUT_OPTIONS="$INPUT_OPTIONS --network $INPUT_DOCKER_NETWORK"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! -z $INPUT_TARBALL ];
|
exec docker run $INPUT_OPTIONS $INPUT_IMAGE /bin/sh -c "`cat semicolon_delimited_script`"
|
||||||
then echo "loading image from $INPUT_TARBALL"
|
|
||||||
docker load --input $INPUT_TARBALL
|
|
||||||
fi
|
|
||||||
|
|
||||||
exec docker run -v "/var/run/docker.sock":"/var/run/docker.sock" $INPUT_OPTIONS --entrypoint=$INPUT_SHELL $INPUT_IMAGE -c "${INPUT_RUN//$'\n'/;}"
|
|
||||||
|
|||||||
Reference in New Issue
Block a user