-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild
executable file
·103 lines (83 loc) · 1.99 KB
/
build
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash
PROGRAM=$(basename $0)
function usage() {
echo "Usage: $PROGRAM --config config_file --name image_name"
echo "-------------------------------------------------------------------------------------"
echo "Example: $PROGRAM --config dev.conf --name dev"
}
function error() {
echo $1
echo ""
usage
exit 1
}
check_args() {
if [ -z "$CONFIG" ]
then
error "Error: {config} argument is missed!"
fi
if [ ! -f "$CONFIG" ]
then
error "Error: $CONFIG file does not exist!"
fi
if [ -z "$NAME" ]
then
error "Error: {name} argument is missed!"
fi
_configLastString=$(cat -e $CONFIG)
if [ ${_configLastString: -1} != "$" ]
then
error "Configuration file \"$CONFIG\" must end with an empty line"
fi
lineNumber=0
_files=$(cat $CONFIG)
for _file in $_files
do
if [ ! -f "./$_file" ]
then
error "Invalid configuration file \"$CONFIG\" at line $lineNumber: \"$_file\" not found"
fi
((lineNumber=lineNumber+1))
done
}
function cleanup() {
rm -f $1
}
while true; do
case $1 in
--config) CONFIG="$2" ; shift ;;
--name) NAME="$2" ; shift ;;
--dryrun) DEBUG=true ;;
--help) usage ; exit 0; shift ;;
(--) shift;;
(-*) error "$PROGRAM: unrecognized option \"$1\"";;
(*) break;;
esac
shift
done
check_args
TMP_DOCKER_FILE="./$(uuidgen).Dockerfile"
touch $TMP_DOCKER_FILE
cat $CONFIG | while read line
do
echo "Merging from $line"
echo "# [ $line ]--------------------------------------------------------" >> $TMP_DOCKER_FILE
cat $line >> $TMP_DOCKER_FILE
echo "" >> $TMP_DOCKER_FILE
echo "" >> $TMP_DOCKER_FILE
done
CMD="docker build -t $NAME -f $TMP_DOCKER_FILE ."
if [ "$DEBUG" = true ] ; then
echo "Resulting config:"
cat $TMP_DOCKER_FILE
echo "Resulting command to execute:"
echo "$CMD"
exit 0
fi
eval $CMD
if [ $? -eq 0 ]; then
echo "OK"
else
echo "FAIL"
fi
echo "Resulting Dockerfile located here: $TMP_DOCKER_FILE"