-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigure
More file actions
executable file
·155 lines (121 loc) · 5.54 KB
/
configure
File metadata and controls
executable file
·155 lines (121 loc) · 5.54 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
145
146
147
148
149
150
151
152
153
154
155
#!/bin/bash
set -euo pipefail
# Colors
GREEN="\033[0;32m"
BLUE="\033[0;34m"
YELLOW="\033[1;33m"
RED="\033[0;31m"
NC="\033[0m"
# Spinner state
SPINNER_PID=""
SPINNER_MSG=""
start_spinner() {
SPINNER_MSG="$1"
echo -ne "${BLUE}==>${NC} $SPINNER_MSG..."
(
while true; do
for c in / - \\ \|; do
echo -ne "\r${BLUE}==>${NC} $SPINNER_MSG... $c"
sleep 0.1
done
done
) &
SPINNER_PID=$!
disown
}
stop_spinner_success() {
kill "$SPINNER_PID" >/dev/null 2>&1 || true
wait "$SPINNER_PID" 2>/dev/null || true
echo -ne "\r\033[K"
echo -e "${GREEN}✔${NC} $SPINNER_MSG"
}
stop_spinner_error() {
kill "$SPINNER_PID" >/dev/null 2>&1 || true
wait "$SPINNER_PID" 2>/dev/null || true
echo -ne "\r\033[K"
echo -e "${RED}✖${NC} $SPINNER_MSG"
exit 1
}
# --- Step 1: Environment Validation ---
start_spinner "Validating that the NRN has been loaded into the environment."
if [ -z "${NRN:-}" ]; then
stop_spinner_error "NRN is not set. Please export the NRN environment variable before running this script."
fi
stop_spinner_success "NRN found and loaded successfully."
start_spinner "Validating that the SERVICE_PATH has been loaded into the environment."
if [ -z "${SERVICE_PATH:-}" ]; then
stop_spinner_error "SERVICE_PATH is not set. Please export the SERVICE_PATH environment variable before running this script."
fi
stop_spinner_success "SERVICE_PATH found and loaded successfully."
start_spinner "Validating that the ENVIRONMENT has been loaded into the environment."
if [ -z "${ENVIRONMENT:-}" ]; then
stop_spinner_error "ENVIRONMENT is not set. Please export the ENVIRONMENT environment variable before running this script."
fi
stop_spinner_success "ENVIRONMENT found and loaded successfully."
start_spinner "Validating that the REPO_PATH has been loaded into the environment."
if [ -z "${REPO_PATH:-}" ]; then
stop_spinner_error "REPO_PATH is not set. Please export the REPO_PATH environment variable before running this script."
fi
stop_spinner_success "REPO_PATH found and loaded successfully."
# --- Step 2: Generate and Create Service Specification ---
SERVICE_SPEC_PATH="$SERVICE_PATH/specs/service-spec.json"
ACTION_DIR="$SERVICE_PATH/specs/actions"
SCOPE_TYPE_DEFINITION_PATH="$SERVICE_PATH/specs/scope-type-definition.json"
gomplate --file "$SERVICE_SPEC_PATH.tpl" --out "$SERVICE_SPEC_PATH"
start_spinner "Creating the service specification in the platform."
{
SERVICE_SPEC_BODY=$(cat "$SERVICE_SPEC_PATH")
SERVICE_SPEC=$(np service specification create --body "$SERVICE_SPEC_BODY" --format json)
SERVICE_SPECIFICATION_ID=$(echo "$SERVICE_SPEC" | jq -r .id)
SERVICE_SLUG=$(echo "$SERVICE_SPEC" | jq -r .slug)
} || stop_spinner_error "Failed to create or parse the service specification."
stop_spinner_success "Service specification created successfully (id=$SERVICE_SPECIFICATION_ID, slug=$SERVICE_SLUG)."
rm "$SERVICE_SPEC_PATH"
export SERVICE_SPECIFICATION_ID
export SERVICE_SLUG
# --- Step 3: Create Action Specifications ---
find "$ACTION_DIR" -type f -name "*.tpl" | while read -r TEMPLATE_FILE; do
REL_PATH="${TEMPLATE_FILE#$ACTION_DIR/}"
OUTPUT_PATH="$ACTION_DIR/${REL_PATH%.tpl}"
gomplate --file "$TEMPLATE_FILE" --out "$OUTPUT_PATH"
ACTION_SPEC_BODY=$(cat "$OUTPUT_PATH")
start_spinner "Registering action specification: ${REL_PATH%.json.tpl}."
{
ACTION_SPEC=$(np service specification action specification create \
--serviceSpecificationId "$SERVICE_SPECIFICATION_ID" \
--body "$ACTION_SPEC_BODY" \
--format json)
ACTION_SPEC_ID=$(echo "$ACTION_SPEC" | jq -r .id)
} || stop_spinner_error "Failed to create action specification: $REL_PATH."
rm "$OUTPUT_PATH"
stop_spinner_success "Action specification created successfully (id=$ACTION_SPEC_ID)."
done
# --- Step 4: Register Scope Type ---
gomplate --file "$SCOPE_TYPE_DEFINITION_PATH.tpl" --out "$SCOPE_TYPE_DEFINITION_PATH"
SCOPE_TYPE_BODY=$(cat "$SCOPE_TYPE_DEFINITION_PATH")
SCOPE_TYPE_NAME=$(echo "$SCOPE_TYPE_BODY" | jq -r .name)
start_spinner "Creating the scope type: $SCOPE_TYPE_NAME."
{
SCOPE_TYPE=$(np scope type create --body "$SCOPE_TYPE_BODY" --format json)
SCOPE_TYPE_ID=$(echo "$SCOPE_TYPE" | jq -r .id)
} || stop_spinner_error "Failed to create the scope type: $SCOPE_TYPE_NAME."
stop_spinner_success "Scope type created successfully (id=$SCOPE_TYPE_ID)."
rm "$SCOPE_TYPE_DEFINITION_PATH"
# --- Step 5: Create Notification Channel ---
NOTIFICATION_CHANNEL_PATH="$SERVICE_PATH/specs/notification-channel.json"
gomplate --file "$NOTIFICATION_CHANNEL_PATH.tpl" --out "$NOTIFICATION_CHANNEL_PATH"
start_spinner "Creating the notification channel."
{
NOTIFICATION_CHANNEL_BODY=$(cat "$NOTIFICATION_CHANNEL_PATH")
NOTIFICATION_CHANNEL=$(np notification channel create --format json --body "$NOTIFICATION_CHANNEL_BODY")
NOTIFICATION_CHANNEL_ID=$(echo "$NOTIFICATION_CHANNEL" | jq -r .id)
} || stop_spinner_error "Failed to create the notification channel."
rm "$NOTIFICATION_CHANNEL_PATH"
stop_spinner_success "Notification channel created successfully (id=$NOTIFICATION_CHANNEL_ID)."
# --- Step 6: Patch NRN ---
start_spinner "Configuring the NRN to use the external provider for logs and metrics."
{
np nrn patch --nrn "$NRN" --body "{\"global.${SERVICE_SLUG}_metric_provider\": \"externalmetrics\", \"global.${SERVICE_SLUG}_log_provider\": \"external\"}" >/dev/null 2>&1
} || stop_spinner_error "Failed to patch the NRN with external provider configuration."
stop_spinner_success "NRN updated to use the external provider."
echo -e "${GREEN}✔${NC} The custom scope setup process completed successfully."