-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinit.sh
More file actions
executable file
·144 lines (125 loc) · 2.98 KB
/
init.sh
File metadata and controls
executable file
·144 lines (125 loc) · 2.98 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
export GOCACHE="${GOCACHE:-$ROOT_DIR/.cache/go-build}"
export GOMODCACHE="${GOMODCACHE:-$ROOT_DIR/.cache/go-mod}"
SERVICES=(
"compute-agent"
"persys-scheduler"
"persysctl"
"persys-gateway"
"persys-federation"
"persys-forgery"
"persys-operator"
"vault-mtls-mock"
)
SELECTED_SERVICES=("${SERVICES[@]}")
SKIP_DEPS=0
SKIP_CERTS=0
SKIP_BUILD=0
usage() {
cat <<'EOF'
Usage: ./init.sh [options]
Options:
--skip-deps Skip dependency download
--skip-certs Skip certificate generation
--skip-build Skip service build
--services a,b,c Limit operations to specific services
-h, --help Show this help
Examples:
./init.sh
./init.sh --services persys-scheduler,persys-gateway
./init.sh --skip-build
EOF
}
contains_service() {
local wanted="$1"
local item
for item in "${SERVICES[@]}"; do
if [[ "$item" == "$wanted" ]]; then
return 0
fi
done
return 1
}
parse_services_arg() {
local raw="$1"
local parsed=()
IFS=',' read -r -a parsed <<<"$raw"
if [[ "${#parsed[@]}" -eq 0 ]]; then
echo "No services were provided to --services" >&2
exit 1
fi
SELECTED_SERVICES=()
local service
for service in "${parsed[@]}"; do
if ! contains_service "$service"; then
echo "Unknown service: $service" >&2
echo "Allowed services: ${SERVICES[*]}" >&2
exit 1
fi
SELECTED_SERVICES+=("$service")
done
}
while [[ $# -gt 0 ]]; do
case "$1" in
--skip-deps)
SKIP_DEPS=1
shift
;;
--skip-certs)
SKIP_CERTS=1
shift
;;
--skip-build)
SKIP_BUILD=1
shift
;;
--services)
[[ $# -lt 2 ]] && { echo "--services requires a value" >&2; exit 1; }
parse_services_arg "$2"
shift 2
;;
-h|--help)
usage
exit 0
;;
*)
echo "Unknown option: $1" >&2
usage
exit 1
;;
esac
done
if ! command -v go >/dev/null 2>&1; then
echo "Go is required but was not found in PATH." >&2
exit 1
fi
echo "==> Persys Cloud initialization"
echo "Root: $ROOT_DIR"
echo "Services: ${SELECTED_SERVICES[*]}"
echo "GOCACHE: $GOCACHE"
echo "GOMODCACHE: $GOMODCACHE"
mkdir -p "$GOCACHE" "$GOMODCACHE"
if [[ -d "$ROOT_DIR/.git" ]] && command -v git >/dev/null 2>&1; then
echo "==> Syncing git submodules"
git -C "$ROOT_DIR" submodule update --init --recursive
fi
if [[ "$SKIP_DEPS" -eq 0 ]]; then
echo "==> Downloading dependencies"
for service in "${SELECTED_SERVICES[@]}"; do
echo " - $service"
(cd "$ROOT_DIR/$service" && go mod download)
done
fi
if [[ "$SKIP_CERTS" -eq 0 ]]; then
echo "==> Generating certificates"
"$ROOT_DIR/generate-certs.sh"
fi
if [[ "$SKIP_BUILD" -eq 0 ]]; then
echo "==> Building services"
for service in "${SELECTED_SERVICES[@]}"; do
make -C "$ROOT_DIR" --no-print-directory "build-$service"
done
fi
echo "Initialization complete."