From b85fa3ba01dd4f518fada4693449e567ae00c2b1 Mon Sep 17 00:00:00 2001 From: Cliffano Subagio Date: Tue, 16 Jul 2024 22:26:03 +1000 Subject: [PATCH] Add shell input support. --- Dockerfile | 6 ++---- README.md | 1 + action.yml | 12 +++++++++--- entrypoint.sh => entrypoint-bash.sh | 0 entrypoint-sh.sh | 8 ++++++++ 5 files changed, 20 insertions(+), 7 deletions(-) rename entrypoint.sh => entrypoint-bash.sh (100%) create mode 100755 entrypoint-sh.sh diff --git a/Dockerfile b/Dockerfile index b02a640..e9a163c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,5 @@ ARG IMAGE=alpine:3.20 +ARG SHELL=sh FROM ${IMAGE} -COPY entrypoint.sh /entrypoint.sh -RUN ls -al -RUN pwd -RUN ls -al /entrypoint.sh +COPY entrypoint-${SHELL}.sh /entrypoint.sh ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/README.md b/README.md index d6cd97e..e9bdf7a 100644 --- a/README.md +++ b/README.md @@ -38,3 +38,4 @@ Configuration |-------|------|-------------|----------|---------|---------| | command | string | Shell command to be executed via a Docker container | Yes | - | `cat /etc/*-release` | | image | string | Docker image to be used for running the container | No | `alpine:3.20` | `ubuntu:22.04` | +| shell | string | Shell to be used for running the command | No | `sh` | `bash` | diff --git a/action.yml b/action.yml index 923d99d..a3e464c 100644 --- a/action.yml +++ b/action.yml @@ -18,14 +18,20 @@ inputs: type: string required: false default: 'alpine:3.20' + shell: + description: | + Shell to be used for running the command + type: string + required: false + default: 'sh' runs: using: 'composite' steps: - name: Build Docker image - shell: bash + shell: sh run: | - docker build -f Dockerfile --build-arg IMAGE=${{ inputs.image }} -t local_image:8.8.8 . + docker build -f Dockerfile --build-arg IMAGE=${{ inputs.image }} --build-arg SHELL=${{ inputs.shell }} -t local_image:8.8.8 . - name: Run Docker container - shell: bash + shell: sh run: | docker run --rm -v /var/run/docker.sock:/var/run/docker.sock --name local_container local_image:8.8.8 "${{ inputs.command }}" diff --git a/entrypoint.sh b/entrypoint-bash.sh similarity index 100% rename from entrypoint.sh rename to entrypoint-bash.sh diff --git a/entrypoint-sh.sh b/entrypoint-sh.sh new file mode 100755 index 0000000..a29671e --- /dev/null +++ b/entrypoint-sh.sh @@ -0,0 +1,8 @@ +#!/bin/sh +set -o errexit +set -o nounset + +COMMAND="${1}" + +echo "Executing command: ${COMMAND}" +sh -c "${COMMAND}"