Compare commits

...
This repository has been archived on 2024-09-20. You can view files and clone it, but cannot push or open issues or pull requests.

60 commits
debug ... main

Author SHA1 Message Date
e0e70e3b67 Merge pull request 'chore(deps): update docker docker tag to v26' (#6) from renovate/docker-26.x into main
All checks were successful
run tests / run-container (push) Successful in 12s
Reviewed-on: #6
2024-04-16 12:37:58 +02:00
1c8452bb3d chore(deps): update docker docker tag to v26
All checks were successful
run tests / run-container (pull_request) Successful in 17s
2024-03-21 08:12:44 +01:00
61d5d52e28 update renovate path
All checks were successful
run tests / run-container (push) Successful in 15s
2023-12-05 13:38:37 +01:00
a79a47dad9 Merge pull request 'chore(deps): update docker docker tag to v24' (#2) from renovate/docker-24.x into main
All checks were successful
run tests / run-container (push) Successful in 5s
Reviewed-on: #2
2023-08-16 19:29:53 +02:00
47d2f75528 chore(deps): update docker docker tag to v24
All checks were successful
run tests / run-container (pull_request) Successful in 40s
2023-08-16 19:25:55 +02:00
3579eaef76 Merge pull request 'Configure Renovate' (#1) from renovate/configure into main
All checks were successful
run tests / run-container (push) Successful in 8s
Reviewed-on: #1
2023-08-16 18:51:47 +02:00
e931a9c514 Add renovate.json
All checks were successful
run tests / run-container (pull_request) Successful in 19s
2023-08-16 12:24:38 +00:00
57f5df95d6
fix debug
All checks were successful
run tests / run-container (push) Successful in 7s
2023-08-16 12:25:43 +02:00
0728da8404
add debug for env vars
All checks were successful
run tests / run-container (push) Successful in 7s
2023-08-16 12:16:35 +02:00
e30de98e6a
make entrypoint optional
Some checks failed
run tests / run-container (push) Failing after 6s
2023-08-16 12:10:20 +02:00
f63602e5f4
fix entrypoint
Some checks failed
run tests / run-container (push) Failing after 5s
2023-08-16 12:05:57 +02:00
51996b4b33
add debug and fix printf
Some checks failed
run tests / run-container (push) Failing after 5s
2023-08-16 11:56:27 +02:00
6a9f799df0
fix multiline
Some checks failed
run tests / run-container (push) Failing after 5s
2023-08-16 11:44:42 +02:00
4a1ee59b85
update printf
Some checks failed
run tests / run-container (push) Failing after 5s
2023-08-16 11:29:19 +02:00
ae53dad24b
fix docker socket
Some checks failed
run tests / run-container (push) Failing after 9s
2023-08-16 11:25:20 +02:00
a6e562e983
fix image url
Some checks failed
run tests / run-container (push) Failing after 5s
2023-08-16 11:23:07 +02:00
1143dedbb1
change imag ever
Some checks failed
run tests / run-container (push) Failing after 2s
2023-08-16 11:22:10 +02:00
bcab677194
update image
Some checks failed
run tests / run-container (push) Failing after 2s
2023-08-16 11:20:10 +02:00
Abdud Dayan Adeeb
3e77f186b7
Merge pull request #18 from rlancer/main
Updated docs
2021-05-30 16:29:20 -04:00
Robert Lancer
e6b2dcfc59
Updated docs
Demonstrates the need to checkout in order to mount a volume
2021-05-30 14:48:01 -04:00
Abdud Dayan Adeeb
358af5c600
Merge pull request #17 from lextira/bugfix/remove-command-file
Remove temporary "semicolon_delimited_script"
2021-04-07 16:56:13 -04:00
Dominik Kohler
fe7c510b59 use bash "shell parameter expansion" 2021-04-07 14:41:21 +02:00
Abdud Dayan Adeeb
43383a67d7
docs: example with latest docker build action
Closes #13
2021-03-21 22:12:44 -04:00
Abdud Dayan Adeeb
a808c5419d
docs: update to v3 2021-03-17 20:49:17 -04:00
Abdud Dayan Adeeb
3b7e5e2681
Update RELEASES.md 2021-03-17 13:00:15 -04:00
Abdud Dayan Adeeb
4f65fabd24
Merge pull request #12 from rossettistone/docker-upgrade
Upgrade to more recent image of Docker
2021-03-17 10:43:43 -04:00
Mark Rossetti
7485e8fe25 Upgrade to more recent image of Docker 2021-03-16 10:40:17 -04:00
Abdud Dayan Adeeb
29813b1169
Merge pull request #8 from mdpye/patch-1
fix: typo in required field of action metadata
2021-03-03 18:01:38 -05:00
Mike Pye
3de7aa4662
fix: typo in required field of action metadata 2021-02-26 17:51:48 +00:00
Abdud Dayan Adeeb
4d955dc997 feat: upgrade to v2 2021-02-15 17:26:10 -05:00
Abdud Dayan Adeeb
e7a9a2b25a
Merge pull request #7 from addnab/tests
tests: setup tests
2021-02-15 17:15:51 -05:00
Abdud Dayan Adeeb
8279676ac5 test: add container network test 2021-02-15 17:13:07 -05:00
Abdud Dayan Adeeb
a34de16206 test: adding volume mount test 2021-02-15 16:52:12 -05:00
Abdud Dayan Adeeb
f9c1c286e0 test: test docker version 2021-02-15 16:45:41 -05:00
Abdud Dayan Adeeb
f451fad679 fix: check if network exists 2021-02-15 16:21:09 -05:00
Abdud Dayan Adeeb
6321bad333 fix: remove unused workflow 2021-02-15 15:59:37 -05:00
Abdud Dayan Adeeb
4b731f3709 tests: setup tests 2021-02-15 15:58:29 -05:00
Abdud Dayan Adeeb
6f0804dd49
docs: using github variables instead of env 2021-02-15 09:26:29 -05:00
Abdud Dayan Adeeb
e10bcda95f
Update README.md 2021-02-15 01:27:21 -05:00
Abdud Dayan Adeeb
702ff8ec17
Update README.md 2021-02-15 01:12:38 -05:00
Abdud Dayan Adeeb
e48328783a
Merge pull request #3 from heyman/docker-networks
Docker networks
2021-02-15 00:49:24 -05:00
Jonatan Heyman
c0e88e3a9a Remove whitespace change 2021-01-28 17:13:38 +01:00
Jonatan Heyman
3cf4359b92 Remove debug logging 2021-01-28 17:01:59 +01:00
Jonatan Heyman
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
Jonatan Heyman
23e2be876e Use env variable for docker network id, instead of github action input 2021-01-28 16:54:08 +01:00
Jonatan Heyman
faad629471 Connect container to github job docker network 2021-01-28 16:44:05 +01:00
Jonatan Heyman
8bce4aa10a Add docker_network input 2021-01-28 16:39:33 +01:00
Jonatan Heyman
f3a2d182d8 Debug 2021-01-28 16:22:09 +01:00
Abdud Dayan Adeeb
27808d9e5f
Update README.md 2021-01-09 15:29:20 -05:00
Abdud Dayan Adeeb
56a9143b97
Update README.md 2021-01-04 16:09:39 -05:00
Abdud Dayan Adeeb
68f0bc9ea0 docs: options (fixes #1) 2021-01-04 15:54:00 -05:00
Abdud Dayan Adeeb
1cd63ec344 fix: exposing docker socket for DinD 2020-06-24 15:16:56 -04:00
Abdud Dayan Adeeb
32e3e5ab6a
Update README.md 2020-06-19 20:36:37 -04:00
Abdud Dayan Adeeb
e8d1c67284 fix login 2020-06-17 22:21:03 -04:00
Abdud Dayan Adeeb
fca40d5fe6 override entrypoint 2020-06-17 21:53:32 -04:00
Abdud Dayan Adeeb
1d5aeada27
docs for privately owned image 2020-06-17 21:39:34 -04:00
Abdud Dayan Adeeb
cff4df74be run on specific shell 2020-06-17 21:21:47 -04:00
Abdud Dayan Adeeb
1e284f150e fix run variable name 2020-06-17 21:04:51 -04:00
Abdud Dayan Adeeb
07b07c8cd2 update README 2020-06-17 21:02:26 -04:00
Abdud Dayan Adeeb
9ad56b3196 multiline support 2020-06-17 21:00:26 -04:00
9 changed files with 223 additions and 66 deletions

View 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
View file

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

View file

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

21
LICENSE
View file

@ -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.

View file

@ -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"
```

View file

@ -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"

View file

@ -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
View file

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

6
test.yml Normal file
View file

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