This repository has been archived by the owner on Jan 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild
executable file
·86 lines (69 loc) · 1.82 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
#!/usr/bin/env bash
stack=${1:-example}
env=${2:-staging}
group=${3:-"$env"}
stacks="$(find services/* -maxdepth 1 -type d | awk -F/ '{print $NF}')"
prepare_stack () {
source <(find "services/$stack" -type f -name '.env' -exec sed -E -n 's/[^#]+/export &/ p' {} +)
service=".*\\/$stack"
conf="\\.$env"
child=".*"
regex="$service\\/\\($child\\)?docker-compose\\($conf\\)?\\.yml$"
if [[ "$OSTYPE" == "darwin"* ]]; then
cmd="find -E services/ -regex $regex"
else
cmd="find services/ -regextype posix-extended -regex $regex"
fi
files=$(sh -c "$cmd | xargs -I \"%\" echo '-f' \"%\" | tr '\\n' ' '")
# WARNING: Don't quote $files
docker-compose $files config > docker-compose.yml
}
sync_stack () {
git="$(find "services/$stack" -name '.git*')"
if [ -n "$git" ]; then
git submodule update --init --remote --merge "services/$stack"
fi
}
cleanup () {
rm -f docker-compose.yml
}
build () {
sync_stack
prepare_stack
time ansible-playbook ansible/playbooks/build.yml -i "ansible/environments/$env" \
-e "{\"project_path\": \"$(pwd)\", \"env\": \"$env\", \"group\": \"$group\", \"stack\": \"$stack\"}"
status_code="$?"
[ "$status_code" != 0 ] && exit 1
cleanup
}
help () {
echo "Usage: $0"
echo 'Default: *'
echo 'Stacks: *example'
echo ''
echo "$stacks"
echo ''
echo 'Environments: *staging'
exit 1
}
if [ ! -d "services/$stack" ]; then
help
fi
# WARNING: Don't delete quotes $stacks
for i in "$stacks"; do
case "$i" in
*$stack*)
case "$env" in
'staging'|'test')
build
;;
*)
help
;;
esac
;;
*)
help
;;
esac
done