-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·67 lines (58 loc) · 1.8 KB
/
run.sh
File metadata and controls
executable file
·67 lines (58 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
#
# This script allows you to launch several images
# from this repository once they're built.
#
# Make sure you add the `docker run` command
# in the header of the Dockerfile so the script
# can find it and execute it.
#
# Use pulseaudio/Dockerfile and skype/Dockerfile as examples.
set -e
if [ $# -eq 0 ]; then
echo "Usage: $0 [--test] image1 image2 ..."
exit 1
fi
if [ "$1" = "--test" ]; then
TEST=1
shift
fi
for name in "$@"; do
if [[ ${name} =~ ^*:*$ ]]; then
image_name=${name%:*}
tag_name=${name#*:}
else
image_name=${name}
tag_name=
fi
if [[ ! -z ${tag_name} && ${tag_name} != latest ]]; then
dockerfile=$(find ./${image_name} -path "*${tag_name}*" -name Dockerfile -type f)
else
if [[ ${image_name} =~ ^.*-.*$ ]]; then
dockerfile=$(find ./${image_name%%-*} -path "*${image_name##*-}*" -name Dockerfile -type f)
else
dockerfile=$(find ./${image_name} -name Dockerfile -type f)
fi
fi
if [[ -z ${dockerfile} ]]; then
echo "unable to find container configuration with name ${name}"
exit 1
elif [[ ${dockerfile} =~ .*Dockerfile.*Dockerfile ]]; then
echo "find multipul container configuration with name ${name}"
echo "${dockerfile}"
exit 1
fi
prehook=`sed -n '/prehook:/,/^#$/p' ${dockerfile} | head -n -1 | sed -e 's/\#//' -e 's/\\\//' -e 's/prehook:'//`
posthook=`sed -n '/posthook:/,/^#$/p' ${dockerfile} | head -n -1 | sed -e 's/\#//' -e 's/\\\//' -e 's/posthook:'//`
script=`sed -n '/docker run/,/^#$/p' ${dockerfile} | head -n -1 | sed -e 's/\#//' -e 's/\\\//'`
if [ ${TEST} ]; then
echo prehook: ${prehook}
echo script: ${script}
echo posthook: ${posthook}
else
[ "${prehook}" != "" ] && eval ${prehook}
eval ${script}
[ "${posthook}" != "" ] && eval ${posthook}
fi
shift
done