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.
docker-run-action/entrypoint.sh
Ivan Schaller 4a1ee59b85
Some checks failed
run tests / run-container (push) Failing after 5s
update printf
2023-08-16 11:29:19 +02:00

53 lines
1.4 KiB
Bash
Executable file

#!/usr/bin/env bash
set -euo pipefail
RUNTIME_OPTIONS=()
CUSTOM_OPTIONS=()
RUN_COMMAND=()
env | grep -v -E "^(#|;| |PATH|SHLVL|HOSTNAME|DOCKER_*)" | awk '$1 ~ /^\w+=/' | xargs -0 > "/docker-run-action.env"
# 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
# map volumes
mapfile -t TMP_VOLUMES < <(printf '%b' "${INPUT_VOLUMES}")
for vol in "${TMP_VOLUMES[@]}"; do
RUNTIME_OPTIONS+=(--volume "${vol}")
done
# get custom options
mapfile -t TMP_OPTIONS < <(printf '%b' "${INPUT_OPTIONS}")
for opt in "${TMP_OPTIONS[@]}"; do
CUSTOM_OPTIONS+=("${opt}")
done
# get run command
mapfile -t TMP_RUN < <(printf '%b' "${INPUT_RUN}")
for cmd in "${TMP_RUN[@]}"; do
RUN_COMMAND+=("${cmd}")
done
exec docker run \
--rm \
--volume "${INPUT_WORKDIR}:${INPUT_WORKDIR}" \
--workdir "${INPUT_WORKDIR}" \
--entrypoint="${INPUT_SHELL}" \
--env-file "/docker-run-action.env" \
"${RUNTIME_OPTIONS[@]}" \
"${CUSTOM_OPTIONS[@]}" \
"${INPUT_IMAGE}" \
"${RUN_COMMAND[@]}"