-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·119 lines (97 loc) · 2.53 KB
/
build.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/bash
PROGNAME=$(basename $0)
SUBCOMMAND=$1
ENVIRONMENTS=()
MAIN="\e[94m"
ERR="\e[31m"
_TEXT="\e[4m"
ENDCOLOR="\e[0m"
log() {
echo -e "$_TEXT$MAIN$@$ENDCOLOR"
}
logerr() {
echo -e "$_TEXT$ERR$@$ENDCOLOR"
}
# GOVERS="1.18.3"
# if [[ $(go env GOVERSION) != "go$GOVERS" ]]; then
# echo "Bad version of go '$(go env GOVERSION)'"
# exit 1
# fi
envExists() {
[ ! -f "./environments/$1.go" ] && logerr "Missing environments/$1.go" && return 1
lang="$(cut -d'-' -f1 <<<$1)"
# Le proxy n'as pas de fichier de langage
[ ! -f "./languages/$lang.go" ] && [ $1 != "proxy" ] && logerr "Missing languages/$lang.go" && return 1
return 0
}
to_underscore() {
echo "$1" | tr '-' '_'
}
to_dash() {
echo "$1" | tr '_' '-'
}
sub_help() {
echo "Usage: $PROGNAME (container|bin) -l <environment> [-l <environment2> ...]"
echo "e.g.: $PROGNAME bin -l python-generic -l java-generic"
}
sub_container() {
for complete_env in ${ENVIRONMENTS[@]}; do
lang="$(cut -d'-' -f1 <<<$complete_env)"
env="$(cut -d'-' -f2- <<<$complete_env)"
[ ! -f "./dockerfiles/$complete_env.dockerfile" ] && logerr "./dockerfiles/$complete_env.dockerfile doesn't exists!" && exit 1
log "Building container for ${complete_env}..."
docker build \
-t srvexec:${complete_env} \
--build-arg EXEC_ENV=${complete_env} \
-f dockerfiles/$complete_env.dockerfile \
. || ( logerr "ERROR" && exit 1)
done
}
sub_bin() {
log "Downloading module..."
go mod download && go mod verify
for complete_env in ${ENVIRONMENTS[@]}; do
lang="$(cut -d'-' -f1 <<<$complete_env)"
log "Building binary for environment ${complete_env}..."
CGO_ENABLED=0 go build -v -o srvexec-$complete_env -tags $(to_underscore $complete_env),lib$lang .
done
log "Done"
}
case $SUBCOMMAND in
"" | "-h" | "--help" | "help")
sub_help
;;
*)
shift
RUN="sub_${SUBCOMMAND}"
;;
esac
while getopts hl: flag
do
case "${flag}" in
l)
envExists "$OPTARG" || exit 1
ENVIRONMENTS+=("$OPTARG");;
h)
sub_help
exit 0
;;
*)
sub_help
exit 1
;;
esac
done
if [ ${#ENVIRONMENTS[@]} -gt 0 ]; then
log "Environments: ${ENVIRONMENTS[@]}"
else
logerr "No environment!"
exit 1
fi
$RUN
if [ $? = 127 ]; then
logerr "Error: '$SUBCOMMAND' is not a known subcommand." >&2
echo
sub_help
exit 1
fi