-
Notifications
You must be signed in to change notification settings - Fork 73
/
docker-entrypoint.sh
executable file
·63 lines (50 loc) · 2.06 KB
/
docker-entrypoint.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
#!/usr/bin/env sh
set -e
executeYeomanCommand() {
command_with_params=$1
# cleanup yeoman files after execution
# shellcheck disable=SC2064
trap "rm -rf \"$yeoman_target_dir/.cache\" \"$yeoman_target_dir/.config\" \"$yeoman_target_dir/.npm\"" EXIT
if [ "$(id -u)" = 0 ]; then
# root user detected, running as yeoman user
sudo chown -R yeoman:yeoman "$yeoman_target_dir"
# shellcheck disable=SC2086
(cd "$yeoman_target_dir" && sudo -E -u yeoman yo --no-insight $command_with_params)
sudo chown -R root:root "$yeoman_target_dir"
else
# shellcheck disable=SC2086
(cd "$yeoman_target_dir" && yo --no-insight $command_with_params)
fi
}
formatGeneratedFiles() {
# Additional script and yaml formatting
#
# Why? Yeoman output may contain some additional whitespaces or the formatting
# might not be ideal. Keeping those whitespaces, however, might be useful
# in templates to improve the brevity. That's why we need additional formatting.
# Since the templates should obey good practices, we don't use linters here
# (i.e. shellcheck and yamllint).
echo "Formatting generated files"
shfmt -i=2 -l -w "$yeoman_target_dir" >/dev/null
for yaml in "$yeoman_target_dir"/**/*.yaml; do
# the expansion failed, no yaml files found
if [ "$yaml" = "$yeoman_target_dir/**/*.yaml" ]; then
break
fi
# remove trailing spaces
sed --in-place 's/[ \t]*$//' "$yaml"
# remove duplicated empty/blank lines
content="$(awk -v RS= -v ORS='\n\n' '1' "$yaml")"
echo "$content" >"$yaml"
done
}
yeoman_target_dir="/network/workspace"
yeoman_command=${1:-Fablo:setup-network}
# This part of output will be replaces with empty line. It breaks parsing of yeoman generator output.
# See also: https://github.com/yeoman/generator/issues/1294
annoying_yeoman_info="No change to package.json was detected. No package manager install will be executed."
# Execute the command
executeYeomanCommand "$yeoman_command" 2>&1 | sed "s/$annoying_yeoman_info//g"
if echo "$yeoman_command" | grep "setup-network"; then
formatGeneratedFiles
fi