Repository navigation
Expand file tree
/
Copy pathinit.sh
More file actions
278 lines (223 loc) Β· 5.94 KB
/
Copy pathinit.sh
File metadata and controls
278 lines (223 loc) Β· 5.94 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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
#!/bin/bash
# Fixed Protocol Buffer compilation for Go + Python integration
cd ~/distributed-systems
# Create proper directory structure for protocol buffers
mkdir -p shared-protocols/proto
mkdir -p go-services/pkg/proto
mkdir -p python-services/proto
# Create the common.proto file in the correct location
cat > shared-protocols/proto/common.proto << 'EOF'
syntax = "proto3";
package common;
option go_package = "./common";
// Common request/response patterns
message HealthCheckRequest {}
message HealthCheckResponse {
string status = 1;
int64 timestamp = 2;
}
// Distributed caching service
service CacheService {
rpc Get(GetRequest) returns (GetResponse);
rpc Put(PutRequest) returns (PutResponse);
rpc Delete(DeleteRequest) returns (DeleteResponse);
rpc HealthCheck(HealthCheckRequest) returns (HealthCheckResponse);
}
message GetRequest {
string key = 1;
}
message GetResponse {
string value = 1;
bool found = 2;
int64 timestamp = 3;
}
message PutRequest {
string key = 1;
string value = 2;
int32 ttl_seconds = 3;
}
message PutResponse {
bool success = 1;
string message = 2;
}
message DeleteRequest {
string key = 1;
}
message DeleteResponse {
bool success = 1;
string message = 2;
}
// Analytics service for cross-language communication
service AnalyticsService {
rpc RecordEvent(EventRequest) returns (EventResponse);
rpc GetMetrics(MetricsRequest) returns (MetricsResponse);
}
message EventRequest {
string event_type = 1;
string user_id = 2;
map<string, string> properties = 3;
int64 timestamp = 4;
}
message EventResponse {
bool success = 1;
string event_id = 2;
}
message MetricsRequest {
string metric_name = 1;
int64 start_time = 2;
int64 end_time = 3;
}
message MetricsResponse {
repeated MetricPoint points = 1;
}
message MetricPoint {
int64 timestamp = 1;
double value = 2;
}
EOF
# Create build script for protocol compilation
cat > shared-protocols/build.sh << 'EOF'
#!/bin/bash
# Protocol Buffer compilation script
set -e
PROTO_DIR="proto"
GO_OUT="../go-services/pkg/proto"
PYTHON_OUT="../python-services/proto"
echo "π¨ Compiling Protocol Buffers..."
# Create output directories
mkdir -p $GO_OUT
mkdir -p $PYTHON_OUT
# Compile for Go
echo "π¦ Generating Go code..."
protoc \
--proto_path=$PROTO_DIR \
--go_out=$GO_OUT \
--go-grpc_out=$GO_OUT \
--go_opt=paths=source_relative \
--go-grpc_opt=paths=source_relative \
$PROTO_DIR/*.proto
# Compile for Python
echo "π Generating Python code..."
python -m grpc_tools.protoc \
--proto_path=$PROTO_DIR \
--python_out=$PYTHON_OUT \
--grpc_python_out=$PYTHON_OUT \
$PROTO_DIR/*.proto
# Create __init__.py files for Python package
touch $PYTHON_OUT/__init__.py
# Fix Python import issues (common problem with protobuf)
echo "π§ Fixing Python imports..."
for file in $PYTHON_OUT/*_pb2_grpc.py; do
if [ -f "$file" ]; then
sed -i 's/import common_pb2/from . import common_pb2/g' "$file"
fi
done
echo "β
Protocol compilation complete!"
echo "π Go files: $GO_OUT"
echo "π Python files: $PYTHON_OUT"
EOF
chmod +x shared-protocols/build.sh
# Create Makefile for easy development
cat > Makefile << 'EOF'
.PHONY: proto build-go build-python test clean dev-up dev-down
# Protocol buffer compilation
proto:
cd shared-protocols && ./build.sh
# Go development
build-go:
cd go-services && go mod tidy && go build ./...
test-go:
cd go-services && go test ./...
run-cache:
cd go-services && go run cmd/cache-service/main.go
# Python development
build-python:
cd python-services && source venv/bin/activate && pip install -r requirements.txt
test-python:
cd python-services && source venv/bin/activate && python -m pytest
run-orchestrator:
cd python-services && source venv/bin/activate && python -m orchestrator
# Development environment
dev-up:
docker-compose -f docker-compose.dev.yml up -d
dev-down:
docker-compose -f docker-compose.dev.yml down
# Full build
build: proto build-go build-python
# Clean generated files
clean:
rm -rf go-services/pkg/proto/*
rm -rf python-services/proto/*
cd go-services && go clean ./...
# Development workflow
dev: clean proto build dev-up
@echo "π Development environment ready!"
@echo "πΎ Cache service: make run-cache"
@echo "π Python orchestrator: make run-orchestrator"
@echo "π Grafana: http://localhost:3000"
@echo "π Jaeger: http://localhost:16686"
EOF
# Set up Go module properly
cd go-services
if [ ! -f go.mod ]; then
go mod init github.com/yourusername/distributed-systems/go-services
fi
# Add essential Go dependencies
go get google.golang.org/grpc@latest
go get google.golang.org/protobuf@latest
go get github.com/prometheus/client_golang@latest
go get github.com/redis/go-redis/v9@latest
go get github.com/stretchr/testify@latest
# Set up Python requirements
cd ../python-services
cat > requirements.txt << 'EOF'
# gRPC and Protocol Buffers
grpcio==1.59.0
grpcio-tools==1.59.0
protobuf==4.24.4
# Async and networking
aiohttp==3.8.6
asyncio-mqtt==0.13.0
uvloop==0.17.0
# Data processing
redis==5.0.1
kafka-python==2.0.2
pandas==2.1.2
numpy==1.25.2
# Web framework
fastapi==0.104.1
uvicorn==0.24.0
websockets==12.0
# Monitoring and observability
prometheus-client==0.18.0
structlog==23.2.0
# Testing
pytest==7.4.3
pytest-asyncio==0.21.1
httpx==0.25.1
# Database
sqlalchemy==2.0.23
asyncpg==0.29.0
# Development
black==23.10.1
flake8==6.1.0
mypy==1.7.0
EOF
# Install Python dependencies
source venv/bin/activate
pip install -r requirements.txt
# Now compile the protocols
cd ../shared-protocols
./build.sh
echo ""
echo "β
Protocol Buffer setup complete!"
echo ""
echo "π― Quick test - run these commands:"
echo "1. make proto # Compile protocol buffers"
echo "2. make build-go # Build Go services"
echo "3. make build-python # Install Python dependencies"
echo "4. make dev-up # Start development services"
echo ""
echo "π Your generated files:"
echo " - Go: go-services/pkg/proto/"
echo " - Python: python-services/proto/"