Skip to content

Commit 4826a3c

Browse files
authored
Merge pull request #136 from cirrax/dev_script_evb
add a script evb (=EasyVoxBox) for more comfortable use of VoxBox
2 parents be834ce + 1d7f243 commit 4826a3c

File tree

2 files changed

+171
-0
lines changed

2 files changed

+171
-0
lines changed

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,56 @@ podman run -it --rm -v $PWD:/repo:Z --entrypoint rubocop ghcr.io/voxpupuli/voxbo
320320
podman run -it --rm -v $PWD:/repo:Z --entrypoint rubocop ghcr.io/voxpupuli/voxbox:8 --auto-gen-config
321321
```
322322

323+
## EasyVoxBox (evb)
324+
The [evb script](evb) shortens the commands to be typed for running voxbox. Additionaly, it does not care about the sequence of
325+
options, wich can be usefull for setting shell aliases. To run the command you must change into any subdirectory of a openvox module
326+
(with a metadata.json file) or a control repository (with a Puppetfile).
327+
328+
Display the evb help message:
329+
```shell
330+
$ evb help
331+
Usage: /usr/local/bin/evb [options] [command]
332+
333+
available options:
334+
--noop : print the command to run, but do not run it
335+
--entrypoint : use a different entrypoint
336+
examples for available endpoints are:
337+
onceover, ash, puppet, yamllint, jq, curl, rubocop
338+
default: no entrypoint specified
339+
--image image : use a different image (default ghcr.io/voxpupuli/voxbox:8)
340+
--env VAR=val : specify environment variables (can be used multiple times)
341+
Remark: the term './' in a assignment will be replaced with
342+
the correct path to be used in the container.
343+
Example: if you start the script in ~/openvox-supermodule/spec/classes
344+
and set --env SPEC=./supermodule_spec.rb we will
345+
run VoxBox with -e SPEC=spec/classes/supermodule_spec.rb
346+
--volume vol : specify an additional volume to put into the container
347+
see podman man page how to specify 'vol'. (no path magic is done ;))
348+
--runcmd : this lets you change the program used to start the container
349+
if not set explicit it looks for podman or docker.
350+
351+
available command:
352+
help : print this help message and exit
353+
354+
commands/options not listed here are passed to VoxBox as is.
355+
use the '--noop' option to print the detailed call to VoxBox.
356+
```
357+
358+
See the command that would be executed (dropping the --noop option will run the command):
359+
```shell
360+
evb --noop # for rake -T
361+
evb --noop spec # for rake spec
362+
evb --noop --env SPEC=./example_spec.rb spec # for only a specific spec in the current subdirectory
363+
evb --noop --entrypoint onceover --help # onceover help
364+
365+
# or the release rake task
366+
evb --volume ~/.gitconfig:/etc/gitconfig:ro \
367+
--volume ~/.ssh:/root/.ssh \
368+
--volume ${SSH_AUTH_SOCK}:${SSH_AUTH_SOCK} \
369+
--env SSH_AUTH_SOCK="${SSH_AUTH_SOCK}" \
370+
release --noop
371+
```
372+
323373
## GitLab
324374
325375
### Example GitLab CI configuration

evb

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
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, ash, puppet, yamllint, jq, curl, rubocop
26+
default: no entrypoint specified
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+
--runcmd : this lets you change the program used to start the container
37+
if not set explicit it looks for podman or docker.
38+
39+
available command:
40+
help : print this help message and exit
41+
42+
commands/options not listed here are passed to VoxBox as is.
43+
use the '--noop' option to print the detailed call to VoxBox.
44+
EOF
45+
exit
46+
}
47+
48+
run_container () {
49+
P=$(get_path $PWD)
50+
command="${RUNCMD} run -it --rm $(sed "s|=${P}/|=|g" <<< "${PODENV}") -v ${P}:/repo:Z ${PODOPTIONS} ${PODIMAGE} ${VOXBOXCOMMAND}"
51+
if [ ${NOOP} -eq 0 ] ; then
52+
${command}
53+
else
54+
echo command to run:
55+
echo ${command}
56+
echo
57+
fi
58+
}
59+
60+
61+
# get options
62+
NOOP=0
63+
PODOPTIONS=''
64+
PODENV=''
65+
PODIMAGE='ghcr.io/voxpupuli/voxbox:8'
66+
VOXBOXCOMMAND=''
67+
while [[ $# -gt 0 ]]; do
68+
key="$1"
69+
case $key in
70+
help)
71+
usage
72+
;;
73+
--noop)
74+
NOOP=1
75+
shift
76+
;;
77+
--runcmd)
78+
shift
79+
RUNCMD=${1}
80+
shift
81+
;;
82+
--entrypoint)
83+
shift
84+
PODOPTIONS="--entrypoint ${1} ${PODOPTIONS}"
85+
shift
86+
;;
87+
--image)
88+
shift
89+
PODIMAGE=$1
90+
shift
91+
;;
92+
--volume)
93+
shift
94+
PODOPTIONS="-v ${1} ${PODOPTIONS}"
95+
shift
96+
;;
97+
--env)
98+
shift
99+
PODENV="-e $(sed "s|=./|=${PWD}/|" <<< "${1}") ${PODENV}"
100+
shift
101+
;;
102+
*)
103+
VOXBOXCOMMAND="${VOXBOXCOMMAND} ${key}"
104+
shift
105+
;;
106+
esac
107+
done
108+
109+
# lets see what we have as default runcmd:
110+
if [ -n "${RUNCMD}" ] ; then
111+
true
112+
elif command -v podman >/dev/null 2>&1 ; then
113+
RUNCMD='podman'
114+
elif command -v docker >/dev/null 2>&1 ; then
115+
RUNCMD='docker'
116+
else
117+
echo "ERROR: could not find podman or docker to start container" >&2
118+
exit 200
119+
fi
120+
121+
run_container

0 commit comments

Comments
 (0)