-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-contract-events-pipeline.sh
More file actions
executable file
Β·173 lines (150 loc) Β· 5.29 KB
/
setup-contract-events-pipeline.sh
File metadata and controls
executable file
Β·173 lines (150 loc) Β· 5.29 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
#!/bin/bash
set -e
echo "π Contract Events Pipeline Setup"
echo "=================================="
echo ""
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Configuration
DB_NAME="contract_events"
DB_USER="${POSTGRES_USER:-postgres}"
SCHEMA_FILE="contract-events-postgres-consumer/config/schema/contract_events.sql"
# Check prerequisites
echo "π Checking prerequisites..."
# Check PostgreSQL
if ! command -v psql &> /dev/null; then
echo -e "${RED}β PostgreSQL client not found${NC}"
echo " Install with: sudo apt install postgresql-client"
exit 1
fi
echo -e "${GREEN}β PostgreSQL client found${NC}"
# Check Docker
if ! command -v docker &> /dev/null; then
echo -e "${RED}β Docker not found${NC}"
echo " Install from: https://docs.docker.com/get-docker/"
exit 1
fi
echo -e "${GREEN}β Docker found${NC}"
# Check if we're using datalake source (needs GCS)
if [ "$1" == "datalake" ]; then
echo ""
echo "ποΈ Datalake mode selected - checking GCS credentials..."
# Check for GCS credentials
if [ -f "$HOME/.config/gcloud/application_default_credentials.json" ]; then
echo -e "${GREEN}β GCS credentials found${NC}"
else
echo -e "${YELLOW}β GCS credentials not found${NC}"
echo " Run: gcloud auth application-default login"
read -p "Continue anyway? (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
fi
fi
# Database setup
echo ""
echo "ποΈ Setting up PostgreSQL database..."
# Check if database exists
if psql -U "$DB_USER" -lqt | cut -d \| -f 1 | grep -qw "$DB_NAME"; then
echo -e "${YELLOW}β Database '$DB_NAME' already exists${NC}"
read -p "Drop and recreate? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "Dropping database..."
dropdb -U "$DB_USER" "$DB_NAME" || true
echo "Creating database..."
createdb -U "$DB_USER" "$DB_NAME"
echo -e "${GREEN}β Database recreated${NC}"
else
echo "Using existing database"
fi
else
echo "Creating database..."
createdb -U "$DB_USER" "$DB_NAME"
echo -e "${GREEN}β Database created${NC}"
fi
# Initialize schema
echo "Initializing schema..."
if [ ! -f "$SCHEMA_FILE" ]; then
echo -e "${RED}β Schema file not found: $SCHEMA_FILE${NC}"
exit 1
fi
psql -U "$DB_USER" -d "$DB_NAME" -f "$SCHEMA_FILE" > /dev/null 2>&1
echo -e "${GREEN}β Schema initialized${NC}"
# Verify schema
echo "Verifying schema..."
TABLE_COUNT=$(psql -U "$DB_USER" -d "$DB_NAME" -t -c "SELECT COUNT(*) FROM information_schema.tables WHERE table_name = 'contract_events'" | tr -d ' ')
if [ "$TABLE_COUNT" -eq "1" ]; then
echo -e "${GREEN}β Schema verified${NC}"
else
echo -e "${RED}β Schema verification failed${NC}"
exit 1
fi
# Build Docker images
echo ""
echo "π³ Building Docker images..."
BUILD_IMAGES="${BUILD_IMAGES:-true}"
if [ "$BUILD_IMAGES" == "false" ]; then
echo "Skipping Docker image builds (BUILD_IMAGES=false)"
else
# Determine which source to build
if [ "$1" == "datalake" ]; then
SOURCE_DIR="stellar-live-source-datalake"
else
SOURCE_DIR="stellar-live-source"
fi
if [ -d "$SOURCE_DIR" ]; then
echo "Building $SOURCE_DIR..."
(cd "$SOURCE_DIR" && make docker-build) > /dev/null 2>&1 || echo -e "${YELLOW}β Failed to build $SOURCE_DIR${NC}"
else
echo -e "${YELLOW}β $SOURCE_DIR not found, skipping${NC}"
fi
echo "Building contract-events-processor..."
(cd contract-events-processor && make docker-build) > /dev/null 2>&1 || echo -e "${YELLOW}β Failed to build contract-events-processor${NC}"
echo "Building contract-events-postgres-consumer..."
(cd contract-events-postgres-consumer && make docker-build) > /dev/null 2>&1 || echo -e "${YELLOW}β Failed to build contract-events-postgres-consumer${NC}"
echo -e "${GREEN}β Docker images built${NC}"
fi
# List Docker images
echo ""
echo "π¦ Available Docker images:"
docker images | grep -E "withobsrvr/(stellar-live-source|contract-events)" | head -10
# Summary
echo ""
echo "β
Setup complete!"
echo ""
echo "Next steps:"
echo ""
if [ "$1" == "datalake" ]; then
echo " 1. Review configuration in: contract-events-flowctl-pipeline.secret.yaml"
echo " 2. Update GCS bucket settings if needed"
echo " 3. Run the pipeline:"
echo " flowctl run contract-events-flowctl-pipeline.secret.yaml"
else
echo " 1. Review configuration in: contract-events-flowctl-pipeline-live.yaml"
echo " 2. Update RPC endpoint if needed"
echo " 3. Run the pipeline:"
echo " flowctl run contract-events-flowctl-pipeline-live.yaml"
fi
echo ""
echo " Or run services manually:"
if [ "$1" == "datalake" ]; then
echo " cd stellar-live-source-datalake && make run"
else
echo " cd stellar-live-source && make run"
fi
echo " cd contract-events-processor && make run"
echo " cd contract-events-postgres-consumer && ./run.sh 1000 0"
echo ""
echo " Monitor health:"
echo " curl http://localhost:8081/health # Source"
echo " curl http://localhost:8089/health # Processor"
echo " curl http://localhost:8090/health # Consumer"
echo ""
echo " Query events:"
echo " psql -d $DB_NAME -c 'SELECT COUNT(*) FROM contract_events'"
echo ""