Compare commits
60 commits
Author | SHA1 | Date | |
---|---|---|---|
e0e70e3b67 | |||
1c8452bb3d | |||
61d5d52e28 | |||
a79a47dad9 | |||
47d2f75528 | |||
3579eaef76 | |||
e931a9c514 | |||
57f5df95d6 | |||
0728da8404 | |||
e30de98e6a | |||
f63602e5f4 | |||
51996b4b33 | |||
6a9f799df0 | |||
4a1ee59b85 | |||
ae53dad24b | |||
a6e562e983 | |||
1143dedbb1 | |||
bcab677194 | |||
|
3e77f186b7 | ||
|
e6b2dcfc59 | ||
|
358af5c600 | ||
|
fe7c510b59 | ||
|
43383a67d7 | ||
|
a808c5419d | ||
|
3b7e5e2681 | ||
|
4f65fabd24 | ||
|
7485e8fe25 | ||
|
29813b1169 | ||
|
3de7aa4662 | ||
|
4d955dc997 | ||
|
e7a9a2b25a | ||
|
8279676ac5 | ||
|
a34de16206 | ||
|
f9c1c286e0 | ||
|
f451fad679 | ||
|
6321bad333 | ||
|
4b731f3709 | ||
|
6f0804dd49 | ||
|
e10bcda95f | ||
|
702ff8ec17 | ||
|
e48328783a | ||
|
c0e88e3a9a | ||
|
3cf4359b92 | ||
|
a42f5acd32 | ||
|
23e2be876e | ||
|
faad629471 | ||
|
8bce4aa10a | ||
|
f3a2d182d8 | ||
|
27808d9e5f | ||
|
56a9143b97 | ||
|
68f0bc9ea0 | ||
|
1cd63ec344 | ||
|
32e3e5ab6a | ||
|
e8d1c67284 | ||
|
fca40d5fe6 | ||
|
1d5aeada27 | ||
|
cff4df74be | ||
|
1e284f150e | ||
|
07b07c8cd2 | ||
|
9ad56b3196 |
9 changed files with 223 additions and 66 deletions
39
.gitea/workflows/tests.yml
Normal file
39
.gitea/workflows/tests.yml
Normal file
|
@ -0,0 +1,39 @@
|
|||
name: run tests
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main, master]
|
||||
|
||||
pull_request:
|
||||
branches: [main, master]
|
||||
|
||||
jobs:
|
||||
run-container:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: single-line options
|
||||
uses: https://git.44net.ch/actions/docker-run-action@main
|
||||
with:
|
||||
debug: true
|
||||
image: debian:11-slim
|
||||
volumes: /tmp/:/tmp/
|
||||
options: -e TESTENV=${{ gitea.workspace }}
|
||||
run: env
|
||||
|
||||
- name: multi-line options
|
||||
uses: https://git.44net.ch/actions/docker-run-action@main
|
||||
with:
|
||||
debug: true
|
||||
image: debian:11-slim
|
||||
volumes: >-
|
||||
/tmp/:/tmp/
|
||||
README.md:/README.md
|
||||
options: >-
|
||||
-e TESTENV=${{ gitea.workspace }}
|
||||
-e TESTENV2=TESTENV2
|
||||
run: >-
|
||||
sh -c
|
||||
echo "test"
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1 +1 @@
|
|||
.idea
|
||||
.idea/
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
FROM docker:19.03
|
||||
FROM docker:26.0
|
||||
|
||||
RUN apk add bash
|
||||
|
||||
|
|
21
LICENSE
21
LICENSE
|
@ -1,21 +0,0 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2020 Abdud Dayan Adeeb
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
94
README.md
94
README.md
|
@ -1,37 +1,73 @@
|
|||
# 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.
|
||||
## features:
|
||||
|
||||
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.
|
||||
- run a specific step/command in i docker image
|
||||
- run an image built by a previous step
|
||||
- See [action.yml](action.yml) for all the available inputs
|
||||
|
||||
### Example Usage
|
||||
## Examples
|
||||
|
||||
#### Standard use-case
|
||||
```yaml
|
||||
- uses: addnab/docker-run-action@v1
|
||||
#### Typical Use Case
|
||||
|
||||
```yml
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3 # Required to mount the Github Workspace to a volume
|
||||
|
||||
- uses: git.44net.ch/actions/docker-run-action@v1
|
||||
env:
|
||||
ABC: 123
|
||||
with:
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
registry: ghcr.io
|
||||
image: some-image:latest
|
||||
volumes: >-
|
||||
./testscript.sh:/testscript.sh
|
||||
/abc/def:/tmp
|
||||
options: >-
|
||||
--user abc
|
||||
run: >-
|
||||
/bin/bash
|
||||
/testscript.sh
|
||||
```
|
||||
|
||||
#### run a privately-owned image
|
||||
|
||||
```yml
|
||||
- uses: git.44net.ch/actions/docker-run-action@v1
|
||||
with:
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
registry: gcr.io
|
||||
image: some-image:latest
|
||||
run: echo "hello world"
|
||||
```
|
||||
|
||||
#### run an image built by a previous step
|
||||
|
||||
```yml
|
||||
- uses: docker/build-push-action@v2
|
||||
with:
|
||||
tags: some-image:latest
|
||||
push: false
|
||||
|
||||
- uses: git.44net.ch/actions/docker-run-action@v1
|
||||
with:
|
||||
image: some-image:latest
|
||||
run: echo "hello world"
|
||||
```
|
||||
|
||||
#### use a specific shell (default: sh).
|
||||
|
||||
_Note: The shell must be installed in the container_
|
||||
|
||||
```yml
|
||||
- uses: git.44net.ch/actions/docker-run-action@v1
|
||||
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"
|
||||
```
|
||||
|
|
58
action.yml
58
action.yml
|
@ -1,25 +1,59 @@
|
|||
# action.yml
|
||||
name: 'Docker Run Action'
|
||||
description: 'Run a command in a new container'
|
||||
name: "Docker Run Action"
|
||||
description: "Run a command in a new docker container"
|
||||
|
||||
inputs:
|
||||
image:
|
||||
description: 'Image'
|
||||
description: "Docker image to run"
|
||||
required: true
|
||||
|
||||
workdir:
|
||||
description: "Workdir for the container. Defaults to the repository workspace"
|
||||
required: false
|
||||
default: ${{ github.workspace }}
|
||||
|
||||
volumes:
|
||||
description: "Volumes to mount in the container. The repository workspace is automatically mounted"
|
||||
required: false
|
||||
|
||||
options:
|
||||
description: 'Options'
|
||||
description: "Custom docker run options"
|
||||
required: false
|
||||
command:
|
||||
description: 'Command'
|
||||
|
||||
mount_socket:
|
||||
description: "Mount the docker socket into the container"
|
||||
required: false
|
||||
default: "false"
|
||||
|
||||
run:
|
||||
description: "Command(s) to run in the container"
|
||||
required: false
|
||||
|
||||
entrypoint:
|
||||
description: "Entrypoint for the container"
|
||||
required: false
|
||||
|
||||
registry:
|
||||
description: 'Registry'
|
||||
description: "Container registry URL"
|
||||
required: false
|
||||
|
||||
username:
|
||||
description: 'Username'
|
||||
description: "Container registry username"
|
||||
required: false
|
||||
|
||||
password:
|
||||
description: 'Password'
|
||||
description: "Container registry password/token"
|
||||
required: false
|
||||
|
||||
docker_network:
|
||||
description: "Docker container network to use"
|
||||
required: false
|
||||
default: ${{ job.container.network }}
|
||||
|
||||
debug:
|
||||
description: "Enable debugging"
|
||||
required: false
|
||||
default: "false"
|
||||
|
||||
runs:
|
||||
using: 'docker'
|
||||
image: 'Dockerfile'
|
||||
using: "docker"
|
||||
image: "Dockerfile"
|
||||
|
|
|
@ -1,7 +1,64 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
if [ ! -z $INPUT_USERNAME ];
|
||||
then echo $INPUT_USERNAME | docker login $INPUT_REGISTRY -u $INPUT_PASSWORD --password-stdin
|
||||
set -euo pipefail
|
||||
|
||||
if [ "${INPUT_DEBUG,,}" == "true" ]; then
|
||||
set -x
|
||||
fi
|
||||
|
||||
exec docker run $INPUT_OPTIONS $INPUT_IMAGE $INPUT_COMMAND
|
||||
RUNTIME_OPTIONS=()
|
||||
CUSTOM_OPTIONS=()
|
||||
RUN_COMMAND=()
|
||||
|
||||
env | grep -v -E "^(#|;| |PATH|SHLVL|HOSTNAME|DOCKER_*)" | awk '$1 ~ /^\w+=/' | xargs -0 > "/docker-run-action.env"
|
||||
|
||||
if [ "${INPUT_DEBUG,,}" == "true" ]; then
|
||||
cat "/docker-run-action.env"
|
||||
fi
|
||||
|
||||
# login to container registry
|
||||
if [ -n "${INPUT_USERNAME}" ]; then
|
||||
printf -- '%s' "'${INPUT_PASSWORD}'" | docker login "${INPUT_REGISTRY}" -u "${INPUT_USERNAME}" --password-stdin
|
||||
fi
|
||||
|
||||
# set custom network
|
||||
if [ -n "${INPUT_DOCKER_NETWORK}" ]; then
|
||||
RUNTIME_OPTIONS+=(--network "${INPUT_DOCKER_NETWORK}")
|
||||
fi
|
||||
|
||||
# mount docker socket
|
||||
if [ "${INPUT_MOUNT_SOCKET,,}" == "true" ]; then
|
||||
RUNTIME_OPTIONS+=(--volume "/var/run/docker.sock:/var/run/docker.sock")
|
||||
fi
|
||||
|
||||
# set entrypoint
|
||||
if [ "${INPUT_ENTRYPOINT,,}" == "true" ]; then
|
||||
RUNTIME_OPTIONS+=(--entrypoint="${INPUT_ENTRYPOINT}")
|
||||
fi
|
||||
|
||||
# map volumes
|
||||
mapfile -t -d ' ' TMP_VOLUMES < <(printf -- '%s' "${INPUT_VOLUMES}")
|
||||
for vol in "${TMP_VOLUMES[@]}"; do
|
||||
RUNTIME_OPTIONS+=(--volume "${vol}")
|
||||
done
|
||||
|
||||
# get custom options
|
||||
mapfile -t -d ' ' TMP_OPTIONS < <(printf -- '%s' "${INPUT_OPTIONS}")
|
||||
for opt in "${TMP_OPTIONS[@]}"; do
|
||||
CUSTOM_OPTIONS+=("${opt}")
|
||||
done
|
||||
|
||||
# get run command
|
||||
mapfile -t -d ' ' TMP_RUN < <(printf -- '%s' "${INPUT_RUN}")
|
||||
for cmd in "${TMP_RUN[@]}"; do
|
||||
RUN_COMMAND+=("${cmd}")
|
||||
done
|
||||
|
||||
exec docker run \
|
||||
--volume "${INPUT_WORKDIR}:${INPUT_WORKDIR}" \
|
||||
--workdir "${INPUT_WORKDIR}" \
|
||||
--env-file "/docker-run-action.env" \
|
||||
"${RUNTIME_OPTIONS[@]}" \
|
||||
"${CUSTOM_OPTIONS[@]}" \
|
||||
"${INPUT_IMAGE}" \
|
||||
"${RUN_COMMAND[@]}"
|
||||
|
|
6
renovate.json
Normal file
6
renovate.json
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||
"extends": [
|
||||
"local>44net/renovate"
|
||||
]
|
||||
}
|
6
test.yml
Normal file
6
test.yml
Normal file
|
@ -0,0 +1,6 @@
|
|||
a:
|
||||
b: >-
|
||||
-e test22
|
||||
test
|
||||
test2
|
||||
test3
|
Reference in a new issue