mirror of
https://github.com/addnab/docker-run-action.git
synced 2025-07-19 07:11:32 +03:00
Compare commits
22 Commits
Author | SHA1 | Date | |
---|---|---|---|
4d955dc997 | |||
e7a9a2b25a | |||
8279676ac5 | |||
a34de16206 | |||
f9c1c286e0 | |||
f451fad679 | |||
6321bad333 | |||
4b731f3709 | |||
6f0804dd49 | |||
e10bcda95f | |||
702ff8ec17 | |||
e48328783a | |||
c0e88e3a9a | |||
3cf4359b92 | |||
a42f5acd32 | |||
23e2be876e | |||
faad629471 | |||
8bce4aa10a | |||
f3a2d182d8 | |||
27808d9e5f | |||
56a9143b97 | |||
68f0bc9ea0 |
72
.github/workflows/tests.yml
vendored
Normal file
72
.github/workflows/tests.yml
vendored
Normal 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
|
42
README.md
42
README.md
@ -1,35 +1,27 @@
|
||||
# Docker Run Action
|
||||
|
||||
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)).
|
||||
- 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.
|
||||
|
||||
### 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
|
||||
#### Typical Use Case
|
||||
|
||||
### Example Usage
|
||||
|
||||
#### single-line command
|
||||
```yaml
|
||||
- uses: addnab/docker-run-action@v1
|
||||
- uses: addnab/docker-run-action@v2
|
||||
with:
|
||||
image: docker:latest
|
||||
run: echo "hello world"
|
||||
```
|
||||
|
||||
#### multi-line commands
|
||||
```yaml
|
||||
- uses: addnab/docker-run-action@v1
|
||||
with:
|
||||
image: docker:latest
|
||||
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 "first line"
|
||||
echo "second line"
|
||||
echo "Running Script"
|
||||
/work/run-script
|
||||
```
|
||||
|
||||
#### run on a privately-owned image
|
||||
#### run a privately-owned image
|
||||
```yaml
|
||||
- uses: addnab/docker-run-action@v1
|
||||
- uses: addnab/docker-run-action@v2
|
||||
with:
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
@ -38,13 +30,13 @@ Github Workflows already supports running on public docker images out-of-the-box
|
||||
run: echo "hello world"
|
||||
```
|
||||
|
||||
#### run on an image built by a previous step
|
||||
#### 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@v1
|
||||
- uses: addnab/docker-run-action@v2
|
||||
with:
|
||||
image: test-image:latest
|
||||
run: echo "hello world"
|
||||
@ -54,7 +46,7 @@ Github Workflows already supports running on public docker images out-of-the-box
|
||||
#### use a specific shell (default: sh).
|
||||
*Note: The shell must be installed in the container*
|
||||
```yaml
|
||||
- uses: addnab/docker-run-action@v1
|
||||
- uses: addnab/docker-run-action@v2
|
||||
with:
|
||||
image: docker:latest
|
||||
shell: bash
|
||||
|
10
RELEASES.md
Normal file
10
RELEASES.md
Normal 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
|
@ -24,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'
|
||||
|
@ -6,4 +6,8 @@ fi
|
||||
|
||||
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`"
|
||||
|
Reference in New Issue
Block a user