-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-env.sh
More file actions
executable file
·244 lines (197 loc) · 6.54 KB
/
Copy pathsetup-env.sh
File metadata and controls
executable file
·244 lines (197 loc) · 6.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#!/bin/bash
set -e
echo "=== mni Development Environment Configuration ==="
# Base directories - works from any location
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
MNI_ROOT="$(dirname "$SCRIPT_DIR")"
BACKEND_DIR="${MNI_ROOT}/mni-backend"
FRONTEND_DIR="${MNI_ROOT}/mni-frontend"
CONFIG_FILE="${SCRIPT_DIR}/components.yaml"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
print_status() { echo -e "${GREEN}[INFO]${NC} $1"; }
print_error() { echo -e "${RED}[ERROR]${NC} $1"; }
print_warning() { echo -e "${YELLOW}[WARNING]${NC} $1"; }
# Check prerequisites
check_prerequisites() {
local missing=()
command -v aqua >/dev/null 2>&1 || missing+=("aqua")
command -v direnv >/dev/null 2>&1 || missing+=("direnv")
command -v yq >/dev/null 2>&1 || missing+=("yq")
if [ ${#missing[@]} -gt 0 ]; then
print_error "Missing required tools: ${missing[*]}"
print_warning "Please run './setup-tools.sh' first"
exit 1
fi
if [ ! -f "$CONFIG_FILE" ]; then
print_error "Configuration file not found: $CONFIG_FILE"
exit 1
fi
}
# Get component list from YAML
get_components() {
yq eval '.components[].name' "$CONFIG_FILE"
}
# Create .envrc for each component
create_envrc() {
local component=$1
local component_dir="${BACKEND_DIR}/${component}"
if [ ! -d "$component_dir" ]; then
print_warning "Component directory not found: $component_dir (skipping)"
return
fi
print_status "Creating .envrc for $component..."
cat > "${component_dir}/.envrc" << 'EOF'
# mni development environment variables
export GOPRIVATE=github.com/mNi-Cloud
export TILT_ALLOW_K8S_CONTEXT=kubernetes-admin@kubernetes
export TILT_REGISTRY=localhost:5000
# Add aqua bin to PATH
export AQUA_ROOT_DIR=$HOME/.local/share/aquaproj-aqua
export PATH=$AQUA_ROOT_DIR/bin:$PATH
# Add local bin to PATH (for controller-gen, kustomize, etc.)
export PATH=$(pwd)/bin:$PATH
EOF
print_status ".envrc created for $component"
}
# Create or update aqua.yaml for components that don't have it
ensure_aqua_yaml() {
local component=$1
local component_dir="${BACKEND_DIR}/${component}"
if [ ! -d "$component_dir" ]; then
return
fi
if [ -f "${component_dir}/aqua.yaml" ]; then
print_status "aqua.yaml already exists for $component"
else
print_status "Creating aqua.yaml for $component..."
cat > "${component_dir}/aqua.yaml" << 'EOF'
---
# aqua - Declarative CLI Version Manager
# https://aquaproj.github.io/
registries:
- type: standard
ref: v4.212.0 # renovate: depName=aquaproj/aqua-registry
packages:
- name: kubernetes/kubectl@v1.30.3
- name: tilt-dev/tilt@v0.33.21
EOF
print_status "aqua.yaml created for $component"
fi
}
# Install aqua packages
install_aqua_packages() {
local component=$1
local component_dir="${BACKEND_DIR}/${component}"
if [ ! -d "$component_dir" ]; then
return
fi
if [ -f "${component_dir}/aqua.yaml" ]; then
print_status "Installing aqua packages for $component..."
cd "$component_dir"
# Set AQUA_ROOT_DIR for installation
export AQUA_ROOT_DIR=$HOME/.local/share/aquaproj-aqua
if aqua install -a; then
print_status "aqua packages installed for $component"
else
print_warning "Failed to install some aqua packages for $component"
fi
cd - > /dev/null
fi
}
# Allow direnv for component
allow_direnv() {
local component=$1
local component_dir="${BACKEND_DIR}/${component}"
if [ ! -d "$component_dir" ]; then
return
fi
if [ -f "${component_dir}/.envrc" ]; then
print_status "Allowing direnv for $component..."
cd "$component_dir"
direnv allow . 2>/dev/null || true
cd - > /dev/null
fi
}
# Create global .envrc in project root
create_global_envrc() {
print_status "Creating global .envrc in project root..."
cat > "${MNI_ROOT}/.envrc" << 'EOF'
# mni development global environment
export GOPRIVATE=github.com/mNi-Cloud
export TILT_ALLOW_K8S_CONTEXT=kubernetes-admin@kubernetes
export TILT_REGISTRY=localhost:5000
export VITE_API_BASE_URL=http://localhost:8080
export VITE_API_NAMESPACE=default
# Add aqua bin to PATH
export AQUA_ROOT_DIR=$HOME/.local/share/aquaproj-aqua
export PATH=$AQUA_ROOT_DIR/bin:$PATH
# Add local bin to PATH
export PATH=$HOME/.local/bin:$PATH
# Go settings
export GOPATH=$HOME/go
export PATH=$GOPATH/bin:$PATH
EOF
direnv allow "${MNI_ROOT}" 2>/dev/null || true
print_status "Global .envrc created and allowed"
}
# Main function
main() {
print_status "Configuring environment for mni components..."
if [ ! -d "$BACKEND_DIR" ]; then
print_warning "Backend directory not found: $BACKEND_DIR"
print_status "Run ./clone-repos.sh first to clone repositories"
exit 1
fi
check_prerequisites
# Create global envrc
create_global_envrc
# Get component list
components=$(get_components)
if [ -z "$components" ]; then
print_error "No components found in $CONFIG_FILE"
exit 1
fi
# Process each component
for component in $components; do
print_status "Processing $component..."
create_envrc "$component"
ensure_aqua_yaml "$component"
install_aqua_packages "$component"
allow_direnv "$component"
done
echo ""
print_status "Environment configuration complete!"
echo ""
echo "=== Configuration Summary ==="
echo "GOPRIVATE: github.com/mNi-Cloud"
echo "TILT_ALLOW_K8S_CONTEXT: kubernetes-admin@kubernetes"
echo "TILT_REGISTRY: localhost:5000"
echo "VITE_API_BASE_URL: http://localhost:8080"
echo "VITE_API_NAMESPACE: default"
echo ""
echo "Backend components configured:"
for component in $components; do
if [ -d "${BACKEND_DIR}/${component}" ]; then
echo " ✓ $component"
else
echo " ✗ $component (not cloned)"
fi
done
if [ "$(yq eval '.frontend.enabled // false' "$CONFIG_FILE")" = "true" ]; then
echo ""
echo "Frontend directory:"
if [ -d "$FRONTEND_DIR" ]; then
echo " ✓ $FRONTEND_DIR"
else
echo " ✗ $FRONTEND_DIR (not cloned)"
fi
fi
echo ""
print_warning "If direnv prompts appear, run 'direnv allow' in each directory"
print_status "Next step: Run './setup-registry.sh' to start Docker registry"
}
main "$@"