-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-docker-compose-conf.sh
executable file
·82 lines (67 loc) · 1.62 KB
/
generate-docker-compose-conf.sh
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
#!/usr/bin/env bash
INCLUDE=""
EXCLUDE="_template"
ALL=""
WRITE=""
usage() {
RET=$1
shift
MSGS=("$@")
echo ""
if [ "$*" != "" ]; then
for MSG in "${MSGS[@]}"; do
echo "ERROR: ${MSG}"
done
fi
echo ""
echo "USAGE: $(basename "$0") [-w] [-a] [-e pattern]* [-i <compose file>]*"
echo ""
echo "Options:"
printf " -w\t\t\tWrite output to docker-compose.conf.\n"
printf " -a\t\t\tInclude all files.\n"
printf " -e <pattern>\t\tSpecify exclude patterns.\n"
printf " -i <compose file>\tSpecify compose files to include.\n"
echo ""
exit "${RET}"
}
while getopts "awe:i:" ARG; do
case ${ARG} in
a)
ALL="YES"
;;
e)
EXCLUDE="${EXCLUDE}|${OPTARG}"
;;
i)
if [ ! -f "${OPTARG}" ]; then
usage 253 "Compose file ${OPTARG} does not exist"
else
INCLUDE="${INCLUDE} ${OPTARG}"
fi
;;
w)
WRITE="YES"
;;
*)
usage 255
;;
esac
done
if [ "${ALL}" != "YES" ]; then
if [ "${EXCLUDE}" = "" ] || [ "${INCLUDE}" = "" ]; then
usage 254 "When generating a new file, use -a to explicitly use all files or specify -e or -i arguments to customize."
fi
fi
if [ -f docker-compose.override.yml ]; then
INCLUDE="${INCLUDE} docker-compose.override.yml"
fi
OUTPUT=$(
echo docker-compose.yml
find services/* -name 'service.*.yml' | sort | grep -v -E "${EXCLUDE}"
echo "${INCLUDE}" | xargs -r -n 1 echo
)
if [ "${WRITE}" = "YES" ]; then
echo "${OUTPUT}" | tee docker-compose.conf
else
echo "${OUTPUT}"
fi