-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMakefile
More file actions
278 lines (254 loc) · 13.7 KB
/
Makefile
File metadata and controls
278 lines (254 loc) · 13.7 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
# Makefile for Incident Management Project Setup
# Automates installation steps as documented in README.md
#
# Every target is independently runnable — no implicit prerequisite chains.
# Use 'make install FROM=<step>' to resume from a specific step.
.PHONY: help install setup-snowflake generate-yaml setup-dbt-stack only-dbt setup-accountadmin setup-sysadmin-objects setup-slack-connector setup-tasks setup-procs-funcs deploy-streamlit load-test-data redeploy-dbt teardown check-prereqs
# Step numbering (used by FROM= parameter)
# 1 generate-yaml
# 2 setup-accountadmin
# 3 setup-sysadmin-objects
# 4 setup-slack-connector
# 5 setup-tasks
# 6 setup-procs-funcs
FROM ?= 1
ENV_FILE ?= .env
# Default target
help:
@echo "Incident Management Project - Installation Automation"
@echo ""
@echo "Installation steps (in order):"
@echo " Step 1 generate-yaml Generate snowflake.yml from template"
@echo " Step 2 setup-accountadmin Account-level infra (ACCOUNTADMIN)"
@echo " Step 3 setup-sysadmin-objects DB-level objects & ownership (SYSADMIN)"
@echo " Step 4 setup-slack-connector Slack connector infrastructure"
@echo " Step 5 setup-tasks Snowflake tasks"
@echo " Step 6 setup-procs-funcs Procedures and functions"
@echo ""
@echo "Composite targets:"
@echo " install Run steps 1-6 (or resume with FROM=<step>)"
@echo " setup-snowflake Alias for install"
@echo " setup-dbt-stack Run steps 2+3 together"
@echo " only-dbt Run steps 1+2+3+5+6 (skip Slack connector)"
@echo ""
@echo "Optional (not included in 'install'):"
@echo " deploy-streamlit Deploy Streamlit app (run separately after install)"
@echo " load-test-data Load CSV test data into bronze & gold tables"
@echo " redeploy-dbt Fetch latest git and redeploy dbt project"
@echo ""
@echo "Other:"
@echo " teardown Teardown all project-owned Snowflake resources"
@echo " check-prereqs Verify required tools are installed"
@echo ""
@echo "Usage:"
@echo " make install CONN=myconn # Full setup (uses .env by default)"
@echo " make install CONN=myconn FROM=3 # Resume from step 3"
@echo " make install CONN=myconn ENV_FILE=prod.env # Use a custom env file"
@echo " make setup-accountadmin CONN=myconn # Run a single step"
@echo " make setup-dbt-stack CONN=myconn # Steps 2+3 only"
@echo " make only-dbt CONN=myconn # Steps 1+2+3+5+6 (no Slack)"
@echo " make deploy-streamlit CONN=myconn # Optional Streamlit"
@echo " make teardown CONN=myconn # Teardown resources"
@echo ""
@echo "Prerequisites:"
@echo " - Snowflake CLI installed"
@echo " - .env file configured (copy from .env.template)"
@echo " - Snowflake connection configured in ~/.snowflake/config.toml"
# ---------------------------------------------------------------------------
# Composite targets
# ---------------------------------------------------------------------------
# Complete installation with optional resume
install:
@if [ -z "$(CONN)" ]; then \
echo "❌ Error: CONN parameter required"; \
echo "Usage: make install CONN=<connection-name>"; \
echo " make install CONN=<connection-name> FROM=3 # resume from step 3"; \
echo " (ENV_FILE defaults to .env; override with ENV_FILE=<path>)"; \
exit 1; \
fi
@echo "================================================================================================================"
@echo "🚀 Starting Snowflake infrastructure setup (from step $(FROM))..."
@echo "================================================================================================================"
@if [ $(FROM) -le 1 ]; then $(MAKE) generate-yaml ENV_FILE=$(ENV_FILE); fi
@if [ $(FROM) -le 2 ]; then $(MAKE) setup-accountadmin CONN=$(CONN); fi
@if [ $(FROM) -le 3 ]; then $(MAKE) setup-sysadmin-objects CONN=$(CONN); fi
@if [ $(FROM) -le 4 ]; then $(MAKE) setup-slack-connector CONN=$(CONN); fi
@if [ $(FROM) -le 5 ]; then $(MAKE) setup-tasks CONN=$(CONN); fi
@if [ $(FROM) -le 6 ]; then $(MAKE) setup-procs-funcs CONN=$(CONN); fi
@echo ""
@echo "✅ Installation complete!"
@echo ""
@echo "Optional next steps:"
@echo " make deploy-streamlit CONN=$(CONN) # Deploy Streamlit app"
@echo " See README 'Running the Dashboard' section for Python setup instructions"
# Alias
setup-snowflake: install
# Run accountadmin + sysadmin-objects together
setup-dbt-stack:
@if [ -z "$(CONN)" ]; then \
echo "❌ Error: CONN parameter required"; \
echo "Usage: make setup-dbt-stack CONN=<connection-name>"; \
exit 1; \
fi
@$(MAKE) setup-accountadmin CONN=$(CONN)
@$(MAKE) setup-sysadmin-objects CONN=$(CONN)
@echo "✅ dbt Projects infrastructure setup complete!"
# Run generate-yaml + dbt-stack + tasks + procs-funcs (skips Slack connector)
only-dbt:
@if [ -z "$(CONN)" ]; then \
echo "❌ Error: CONN parameter required"; \
echo "Usage: make only-dbt CONN=<connection-name>"; \
echo " (ENV_FILE defaults to .env; override with ENV_FILE=<path>)"; \
exit 1; \
fi
@echo "================================================================================================================"
@echo "🚀 Running dbt-only setup (steps 1+2+3+5+6, skipping Slack connector)..."
@echo "================================================================================================================"
@$(MAKE) generate-yaml ENV_FILE=$(ENV_FILE)
@$(MAKE) setup-dbt-stack CONN=$(CONN)
@$(MAKE) setup-tasks CONN=$(CONN)
@$(MAKE) setup-procs-funcs CONN=$(CONN)
@$(MAKE) load-test-data CONN=$(CONN)
@echo ""
@echo "✅ dbt-only setup complete!"
# ---------------------------------------------------------------------------
# Individual steps (each independently runnable)
# ---------------------------------------------------------------------------
# Shared validation fragments
define check_conn
@if [ -z "$(CONN)" ]; then \
echo "❌ Error: CONN parameter required"; \
echo "Usage: make $@ CONN=<connection-name>"; \
echo "Connection should be defined in ~/.snowflake/config.toml"; \
exit 1; \
fi
@if ! command -v snow >/dev/null 2>&1; then \
echo "❌ Error: Snowflake CLI (snow) is not installed"; \
echo "Please install it first: https://docs.snowflake.com/en/developer-guide/snowflake-cli/installation/installation"; \
exit 1; \
fi
endef
# Step 1: Generate snowflake.yml file
generate-yaml:
@if [ ! -f "$(ENV_FILE)" ]; then \
echo "❌ Error: Environment file $(ENV_FILE) not found"; \
echo "Please copy .env.template to $(ENV_FILE) and configure it"; \
exit 1; \
fi
@echo "================================================================================================================"
@echo "🔧 [Step 1] Generating snowflake.yml configuration..."
@echo "================================================================================================================"
cd src/scripts && ./create_snowflake_yaml.sh -e ../../$(ENV_FILE)
@if [ -f "src/sql/snowflake.yml" ]; then \
echo "✅ snowflake.yml generated successfully in src/sql/"; \
else \
echo "❌ Error: snowflake.yml generation failed"; \
exit 1; \
fi
# Step 2: Account-level infrastructure (ACCOUNTADMIN)
setup-accountadmin:
$(check_conn)
@echo "================================================================================================================"
@echo "❄️ [Step 2] Setting up account-level infrastructure (ACCOUNTADMIN)..."
@echo "================================================================================================================"
@echo "⚠️ Note: This requires ACCOUNTADMIN privileges"
cd src/sql && snow sql --connection $(CONN) -f 01a_accountadmin_setup.sql
@echo "✅ Account-level infrastructure setup complete!"
# Step 3: Database-level objects & ownership transfer (SYSADMIN)
setup-sysadmin-objects:
$(check_conn)
@echo "================================================================================================================"
@echo "❄️ [Step 3] Setting up database-level objects (SYSADMIN)..."
@echo "================================================================================================================"
@echo "⚠️ Note: This requires SYSADMIN privileges. Assumes step 2 (setup-accountadmin) has been run."
cd src/sql && snow sql --connection $(CONN) -f 01b_sysadmin_objects.sql
@echo "✅ Database-level objects & ownership transfer complete!"
# Step 4: Slack connector infrastructure
setup-slack-connector:
$(check_conn)
@echo "================================================================================================================"
@echo "💬 [Step 4] Setting up Slack connector backend infrastructure..."
@echo "================================================================================================================"
cd src/sql && snow sql --connection $(CONN) -f 02_slack_connector.sql
@echo "✅ Slack connector backend infrastructure setup complete!"
@echo ""
@echo "🔗 Next steps for Slack connector:"
@echo "1. Login to your OpenFlow SPCS runtime"
@echo "2. Create a Slack app in your workspace"
@echo "3. Configure the connector with database and role parameters"
@echo "4. Start the connector and add the Slack app to your channel"
@echo "5. Verify tables are created: SLACK_MEMBERS, SLACK_MESSAGES, etc."
# Step 5: Snowflake tasks
setup-tasks:
$(check_conn)
@echo "================================================================================================================"
@echo "⏰ [Step 5] Setting up Snowflake tasks..."
@echo "================================================================================================================"
cd src/sql && snow sql --connection $(CONN) -f 04_tasks.sql
@echo "✅ Snowflake tasks setup complete!"
# Step 6: Procedures and functions
setup-procs-funcs:
$(check_conn)
@echo "================================================================================================================"
@echo "⚙️ [Step 6] Setting up procedures and functions..."
@echo "================================================================================================================"
cd src/sql && snow sql --connection $(CONN) -f 03_procs_and_funcs.sql
@echo "✅ Procedures and functions setup complete!"
# ---------------------------------------------------------------------------
# Optional / utility targets
# ---------------------------------------------------------------------------
# Deploy Streamlit app (optional, not part of 'install')
deploy-streamlit:
$(check_conn)
@echo "================================================================================================================"
@echo "🎨 Deploying Streamlit app..."
@echo "================================================================================================================"
cd src/sql && snow sql --connection $(CONN) -f 05_streamlit_app.sql
@echo "✅ Streamlit app deployment complete!"
@echo ""
@echo "📱 Access your Streamlit app in Snowsight:"
@echo " Navigate to: Data Products > Streamlit > INCIDENT_MANAGEMENT_DASHBOARD"
# Load test data (optional, not part of 'install')
load-test-data:
$(check_conn)
@echo "================================================================================================================"
@echo "📦 Loading test data into bronze & gold tables..."
@echo "================================================================================================================"
@echo "⚠️ Note: This will truncate existing data before loading. Requires step 3 (setup-sysadmin-objects) to have been run."
cd src/sql && snow sql --connection $(CONN) -f 07_load_test_data.sql
@echo "✅ Test data loaded successfully!"
# Redeploy dbt project (fetch latest git, add new version)
redeploy-dbt:
$(check_conn)
@echo "================================================================================================================"
@echo "🔄 Redeploying dbt project from latest git..."
@echo "================================================================================================================"
cd src/sql && snow sql --connection $(CONN) -f 08_dbt_redeploy.sql
@echo "✅ dbt project redeployed successfully!"
# Teardown: Remove all project-owned Snowflake resources
teardown:
$(check_conn)
@echo "================================================================================================================"
@echo "🗑️ Tearing down project-owned Snowflake resources..."
@echo "================================================================================================================"
@echo "⚠️ WARNING: This will drop all objects owned by dbt_project_admin_role"
@echo " (tasks, cortex services, streamlit app, dbt project, tables, schemas, etc.)"
@echo " ACCOUNTADMIN-owned resources (database, warehouses, roles) are NOT affected."
@echo ""
@read -p "Are you sure you want to proceed? (y/N): " confirm && [ "$$confirm" = "y" ] || { echo "Teardown cancelled."; exit 1; }
cd src/sql && snow sql --connection $(CONN) -f 06_teardown.sql
@echo "✅ Teardown complete! Project-owned resources have been removed."
@echo ""
@echo "📝 Note: ACCOUNTADMIN-owned resources (database, warehouses, integrations, roles)"
@echo " were NOT dropped. See src/sql/06_teardown.sql for optional manual cleanup steps."
# Check prerequisites
check-prereqs:
@echo "🔍 Checking prerequisites..."
@echo -n "uv: "
@if command -v uv >/dev/null 2>&1; then echo "✅ installed"; else echo "❌ not found"; fi
@echo -n "snow CLI: "
@if command -v snow >/dev/null 2>&1; then echo "✅ installed"; else echo "❌ not found"; fi
@echo -n ".env file: "
@if [ -f ".env" ]; then echo "✅ found"; else echo "⚠️ not found (copy from .env.template)"; fi
@echo -n "requirements.txt: "
@if [ -f "requirements.txt" ]; then echo "✅ found"; else echo "❌ not found"; fi