Compare commits

..

1 commit
main ... debug

Author SHA1 Message Date
Abdud Dayan Adeeb
d94e0f37db debug 2020-06-17 19:15:51 -04:00
9 changed files with 68 additions and 223 deletions

View file

@ -1,39 +0,0 @@
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
View file

@ -1 +1 @@
.idea/ .idea

View file

@ -1,4 +1,4 @@
FROM docker:26.0 FROM docker:19.03
RUN apk add bash RUN apk add bash

21
LICENSE Normal file
View file

@ -0,0 +1,21 @@
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.

View file

@ -1,73 +1,37 @@
# Docker Run Action # Docker Run Action
## features: 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/command in i docker image 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 an image built by a previous step
- See [action.yml](action.yml) for all the available inputs
## Examples ### Example Usage
#### Typical Use Case #### Standard use-case
```yaml
```yml - uses: addnab/docker-run-action@v1
- 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: 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
``` ```

View file

@ -1,59 +1,25 @@
name: "Docker Run Action" # action.yml
description: "Run a command in a new docker container" name: 'Docker Run Action'
description: 'Run a command in a new container'
inputs: inputs:
image: image:
description: "Docker image to run" description: 'Image'
required: true 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: options:
description: "Custom docker run options" description: 'Options'
required: false required: false
command:
mount_socket: description: 'Command'
description: "Mount the docker socket into the container"
required: false required: false
default: "false"
run:
description: "Command(s) to run in the container"
required: false
entrypoint:
description: "Entrypoint for the container"
required: false
registry: registry:
description: "Container registry URL" description: 'Registry'
required: false required: false
username: username:
description: "Container registry username" description: 'Username'
required: false required: false
password: password:
description: "Container registry password/token" description: 'Password'
required: false 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: runs:
using: "docker" using: 'docker'
image: "Dockerfile" image: 'Dockerfile'

View file

@ -1,64 +1,9 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -euo pipefail if [ ! -z $INPUT_USERNAME ];
then echo $INPUT_USERNAME | docker login $INPUT_REGISTRY -u $INPUT_PASSWORD --password-stdin
if [ "${INPUT_DEBUG,,}" == "true" ]; then
set -x
fi fi
RUNTIME_OPTIONS=() echo $INPUT_COMMAND
CUSTOM_OPTIONS=() echo "running"
RUN_COMMAND=() exec docker run $INPUT_OPTIONS $INPUT_IMAGE $INPUT_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[@]}"

View file

@ -1,6 +0,0 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"local>44net/renovate"
]
}

View file

@ -1,6 +0,0 @@
a:
b: >-
-e test22
test
test2
test3