|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +get_path () { |
| 5 | + # calculates the 'root' path to run the container |
| 6 | + if [ "${1}" == '' ] ; then |
| 7 | + echo "ERROR: ensure you start this script either in a openvox control or a module directory" >&2 |
| 8 | + exit 200 |
| 9 | + elif [ -f "${1}/metadata.json" ] || [ -f "${1}/Puppetfile" ] ; then |
| 10 | + echo $1 |
| 11 | + else |
| 12 | + get_path $(echo $1|sed 's|/[^/]*$||') |
| 13 | + fi |
| 14 | +} |
| 15 | + |
| 16 | +usage() { |
| 17 | + # print usage of this script and exit |
| 18 | + cat << EOF |
| 19 | +Usage: ${0} [options] [command] |
| 20 | +
|
| 21 | +available options: |
| 22 | + --noop : print the command to run, but do not run it |
| 23 | + --entrypoint : use a different entrypoint |
| 24 | + examples for available endpoints are: |
| 25 | + onceover, |
| 26 | + default: no entrypoint sepcified |
| 27 | + --image image : use a different image (default ${PODIMAGE}) |
| 28 | + --env VAR=val : specify environment variables (can be used multiple times) |
| 29 | + Remark: the term './' in a assignment will be replaced with |
| 30 | + the correct path to be used in the container. |
| 31 | + Example: if you start the script in ~/openvox-supermodule/spec/classes |
| 32 | + and set --env SPEC=./supermodule_spec.rb we will |
| 33 | + run VoxBox with -e SPEC=spec/classes/supermodule_spec.rb |
| 34 | + --volume vol : specify an additional volume to put into the container |
| 35 | + see podman man page how to specify 'vol'. (no path magic is done ;)) |
| 36 | +
|
| 37 | +available command: |
| 38 | + help : print this help message and exit |
| 39 | + |
| 40 | +Commands/Options no listed here are passed to voxbox as is. |
| 41 | +use the '--noop' option to print the detailed call to VoxBox. |
| 42 | +EOF |
| 43 | + exit |
| 44 | +} |
| 45 | + |
| 46 | +run_container () { |
| 47 | + P=$(get_path $PWD) |
| 48 | + command="podman run -it --rm $(sed "s|=${P}/|=|g" <<< "${PODENV}") -v ${P}:/repo:Z ${PODOPTIONS} ${PODIMAGE} ${VOXBOXCOMMAND}" |
| 49 | + if [ ${NOOP} -eq 0 ] ; then |
| 50 | + ${command} |
| 51 | + else |
| 52 | + echo command to run: |
| 53 | + echo ${command} |
| 54 | + echo |
| 55 | + fi |
| 56 | +} |
| 57 | + |
| 58 | +# get options |
| 59 | +NOOP=0 |
| 60 | +PODOPTIONS='' |
| 61 | +PODENV='' |
| 62 | +PODIMAGE='ghcr.io/voxpupuli/voxbox:8' |
| 63 | +VOXBOXCOMMAND='' |
| 64 | +while [[ $# -gt 0 ]] do |
| 65 | + key="$1" |
| 66 | + case $key in |
| 67 | + help) |
| 68 | + usage |
| 69 | + ;; |
| 70 | + --noop) |
| 71 | + NOOP=1 |
| 72 | + shift |
| 73 | + ;; |
| 74 | + --entrypoint) |
| 75 | + shift |
| 76 | + PODOPTIONS="--entrypoint ${1} ${PODOPTIONS}" |
| 77 | + shift |
| 78 | + ;; |
| 79 | + --image) |
| 80 | + shift |
| 81 | + PODIMAGE=$1 |
| 82 | + shift |
| 83 | + ;; |
| 84 | + --volume) |
| 85 | + shift |
| 86 | + PODOPTIONS="-v ${1} ${PODOPTIONS}" |
| 87 | + shift |
| 88 | + ;; |
| 89 | + --env) |
| 90 | + shift |
| 91 | + PODENV="-e $(sed "s|=./|=${PWD}/|" <<< "${1}") ${PODENV}" |
| 92 | + shift |
| 93 | + ;; |
| 94 | + *) |
| 95 | + VOXBOXCOMMAND="${VOXBOXCOMMAND} ${key}" |
| 96 | + shift |
| 97 | + ;; |
| 98 | + esac |
| 99 | +done |
| 100 | + |
| 101 | +run_container |
0 commit comments