-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathMakefile
More file actions
474 lines (427 loc) · 21.7 KB
/
Makefile
File metadata and controls
474 lines (427 loc) · 21.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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
# Makefile for code quality and formatting
#
# Run 'make help' to see all available targets.
# Define color codes
RED := \033[0;31m
GREEN := \033[0;32m
YELLOW := \033[1;33m
CYAN := \033[0;36m
BOLD := \033[1m
NC := \033[0m # No Color
# Virtual environment configuration
VENV_DIR := .venv
# Use the venv python/pip if the venv exists, otherwise fall back to system
ifeq ($(wildcard $(VENV_DIR)/bin/python),)
PYTHON := $(shell command -v python3 2>/dev/null || pyenv which python 2>/dev/null || echo python)
PIP := $(shell command -v pip3 2>/dev/null || echo pip)
else
PYTHON := $(CURDIR)/$(VENV_DIR)/bin/python
PIP := $(CURDIR)/$(VENV_DIR)/bin/pip
endif
# idp-cli invocation — uses `python -m idp_cli.cli` so it works whether or not
# the virtualenv is activated (picks up $(PYTHON) which prefers .venv).
IDP_CLI := $(PYTHON) -m idp_cli.cli
##@ General
.PHONY: help
help: ## Show this help message
@echo ""
@echo "Usage: make [target]"
@echo ""
@awk 'BEGIN {FS = ":.*##"; section=""} \
/^##@/ { section=substr($$0, 5); next } \
/^[a-zA-Z_-]+:.*?## / { \
if (section != "" && section != last_section) { \
printf "\n \033[1m%s\033[0m\n", section; \
last_section = section \
}; \
printf " \033[36m%-25s\033[0m %s\n", $$1, $$2 \
}' $(MAKEFILE_LIST)
@echo ""
# Default target - run both lint and test
.DEFAULT_GOAL := all
all: lint test ## Run lint + test (default)
##@ Setup
setup: ## Install all packages into current Python environment (no venv)
@# Always use the current shell's pip, ignoring .venv even if it exists
@SETUP_PIP=$$(python3 -m pip --version >/dev/null 2>&1 && echo "python3 -m pip" || echo "pip3"); \
SETUP_PYTHON=$$(command -v python3 2>/dev/null || echo python); \
echo "Installing packages into current Python environment..."; \
echo "Python: $$($$SETUP_PYTHON --version) at $$(which $$SETUP_PYTHON)"; \
echo "Pip: $$SETUP_PIP"; \
echo ""; \
echo "Upgrading pip..."; \
$$SETUP_PIP install --upgrade pip && \
echo "Installing idp_common package with all dependencies (including test)..." && \
$$SETUP_PIP install -e "lib/idp_common_pkg[all,dev,test]" && \
echo "Installing idp-cli package..." && \
$$SETUP_PIP install -e lib/idp_cli_pkg && \
echo "Installing idp_sdk package..." && \
$$SETUP_PIP install -e lib/idp_sdk && \
echo "Installing idp_mcp_connector package..." && \
$$SETUP_PIP install -e lib/idp_mcp_connector_pkg && \
echo "Installing capacity planning test dependencies..." && \
$$SETUP_PIP install -r src/lambda/calculate_capacity/requirements-test.txt && \
echo "Installing cfn-lint for CloudFormation template validation..." && \
$$SETUP_PIP install cfn-lint && \
echo "" && \
echo -e "$(GREEN)✅ Setup complete! idp_common, idp-cli, idp_sdk, idp_mcp_connector, and test dependencies are now installed.$(NC)" && \
echo -e "$(YELLOW) Tip: Use 'make setup-venv' instead to install into an isolated virtual environment.$(NC)"
setup-venv: ## Create .venv and install all packages into it
@echo "Creating virtual environment in $(VENV_DIR)..."
@PYENV_PYTHON=$$(pyenv which python 2>/dev/null); \
SYS_PYTHON=$$(command -v python3 2>/dev/null); \
BASE_PYTHON=$${PYENV_PYTHON:-$$SYS_PYTHON}; \
if [ -z "$$BASE_PYTHON" ]; then \
echo -e "$(RED)ERROR: No python3 or pyenv python found. Install Python 3.12+ first.$(NC)"; \
exit 1; \
fi; \
echo "Using base Python: $$BASE_PYTHON ($$($$BASE_PYTHON --version))"; \
$$BASE_PYTHON -m venv $(VENV_DIR)
@echo "Upgrading pip..."
$(VENV_DIR)/bin/pip install --upgrade pip
@echo "Installing idp_common package with all dependencies (including test)..."
$(VENV_DIR)/bin/pip install -e "lib/idp_common_pkg[all,dev,test]"
@echo "Installing idp-cli package..."
$(VENV_DIR)/bin/pip install -e lib/idp_cli_pkg
@echo "Installing idp_sdk package..."
$(VENV_DIR)/bin/pip install -e lib/idp_sdk
@echo "Installing idp_mcp_connector package..."
$(VENV_DIR)/bin/pip install -e lib/idp_mcp_connector_pkg
@echo "Installing capacity planning test dependencies..."
$(VENV_DIR)/bin/pip install -r src/lambda/calculate_capacity/requirements-test.txt
@echo "Installing cfn-lint for CloudFormation template validation..."
$(VENV_DIR)/bin/pip install cfn-lint
@echo ""
@echo -e "$(GREEN)✅ Setup complete! Virtual environment created at $(VENV_DIR)$(NC)"
@echo -e "$(GREEN) idp_common, idp-cli, idp_sdk, idp_mcp_connector, and test dependencies are now installed.$(NC)"
@echo -e "$(YELLOW) All 'make' targets will automatically use $(VENV_DIR)/bin/python.$(NC)"
@echo -e "$(YELLOW) To activate manually: source $(VENV_DIR)/bin/activate$(NC)"
##@ Code Quality
lint: ruff-lint format check-arn-partitions validate-buildspec ui-lint codegen-check ## Run all linting (ruff, format, ARN checks, buildspec, UI, codegen). Use FORCE=1 to force UI lint re-run despite checksum match.
fastlint: ruff-lint format check-arn-partitions validate-buildspec ## Quick lint without UI checks
ruff-lint: ## Run ruff linting with auto-fix
ruff check --fix
format: ## Format Python code with ruff
ruff format
lint-cicd: ## CI/CD lint — checks only, no modifications
@echo "Running code quality checks..."
@if ! ruff check; then \
echo -e "$(RED)ERROR: Ruff linting failed!$(NC)"; \
echo -e "$(YELLOW)Please run 'make ruff-lint' locally to fix these issues.$(NC)"; \
exit 1; \
fi
@if ! ruff format --check; then \
echo -e "$(RED)ERROR: Code formatting check failed!$(NC)"; \
echo -e "$(YELLOW)Please run 'make format' locally to fix these issues.$(NC)"; \
exit 1; \
fi; \
echo "All checks passed!"
@echo "Frontend checks"
@if ! make ui-lint; then \
echo -e "$(RED)ERROR: UI lint failed$(NC)"; \
exit 1; \
fi
@if ! make ui-build; then \
echo -e "$(RED)ERROR: UI build failed$(NC)"; \
exit 1; \
fi
@if ! make codegen-check; then \
echo -e "$(RED)ERROR: GraphQL codegen check failed$(NC)"; \
exit 1; \
fi
@echo -e "$(GREEN)All code quality checks passed!$(NC)"
validate-buildspec: ## Validate AWS CodeBuild buildspec files
@echo "Validating buildspec files..."
@$(PYTHON) scripts/sdlc/validate_buildspec.py patterns/*/buildspec.yml || \
(echo -e "$(RED)ERROR: Buildspec validation failed!$(NC)" && exit 1)
@echo -e "$(GREEN)✅ All buildspec files are valid!$(NC)"
check-arn-partitions: ## Check CloudFormation templates for hardcoded ARN partitions
@echo "Checking CloudFormation templates for hardcoded ARN partitions and service principals..."
@FOUND_ISSUES=0; \
for template in template.yaml patterns/*/template.yaml patterns/*/sagemaker_classifier_endpoint.yaml options/*/template.yaml; do \
if [ -f "$$template" ]; then \
echo "Checking $$template..."; \
ARN_MATCHES=$$(grep -n "arn:aws:" "$$template" | grep -v "arn:\$${AWS::Partition}:" || true); \
if [ -n "$$ARN_MATCHES" ]; then \
echo -e "$(RED)ERROR: Found hardcoded 'arn:aws:' references in $$template:$(NC)"; \
echo "$$ARN_MATCHES" | sed 's/^/ /'; \
echo -e "$(YELLOW) These should use 'arn:\$${AWS::Partition}:' instead for GovCloud compatibility$(NC)"; \
FOUND_ISSUES=1; \
fi; \
SERVICE_MATCHES=$$(grep -n "\.amazonaws\.com" "$$template" | grep -v "\$${AWS::URLSuffix}" | grep -v "^[[:space:]]*#" | grep -v "Description:" | grep -v "Comment:" | grep -v "cognito" | grep -v "ContentSecurityPolicy" || true); \
if [ -n "$$SERVICE_MATCHES" ]; then \
echo -e "$(RED)ERROR: Found hardcoded service principal references in $$template:$(NC)"; \
echo "$$SERVICE_MATCHES" | sed 's/^/ /'; \
echo -e "$(YELLOW) These should use '\$${AWS::URLSuffix}' instead of 'amazonaws.com' for GovCloud compatibility$(NC)"; \
echo -e "$(YELLOW) Example: 'lambda.amazonaws.com' should be 'lambda.\$${AWS::URLSuffix}'$(NC)"; \
FOUND_ISSUES=1; \
fi; \
fi; \
done; \
if [ $$FOUND_ISSUES -eq 0 ]; then \
echo -e "$(GREEN)✅ No hardcoded ARN partition or service principal references found!$(NC)"; \
else \
echo -e "$(RED)❌ Found hardcoded references that need to be fixed for GovCloud compatibility$(NC)"; \
exit 1; \
fi
##@ Type Checking
typecheck: ## Run type checks with basedpyright
@echo "Running type checks..."
basedpyright
typecheck-stats: ## Type checks with detailed statistics
@echo "Running type checks with statistics..."
basedpyright --stats
# Usage: make typecheck-pr [TARGET_BRANCH=branch_name]
TARGET_BRANCH ?= main
typecheck-pr: ## Type check only files changed vs TARGET_BRANCH (default: main)
@echo "Type checking changed files against $(TARGET_BRANCH)..."
$(PYTHON) scripts/sdlc/typecheck_pr_changes.py $(TARGET_BRANCH)
##@ Testing
test: ## Run all tests (idp_common, cli, sdk, capacity, config library)
$(MAKE) -C lib/idp_common_pkg test PYTHON=$(PYTHON)
cd lib/idp_cli_pkg && $(PYTHON) -m pytest -v
cd lib/idp_sdk && $(PYTHON) -m pytest -m "not integration" -v
@echo "Running capacity planning Lambda tests..."
cd src/lambda/calculate_capacity && $(PYTHON) -m pytest -v
@echo "Validating config library files..."
$(PYTHON) -m pytest config_library/test_config_library.py -v
test-cli: ## Run only IDP CLI tests
@echo "Running IDP CLI tests..."
cd lib/idp_cli_pkg && $(PYTHON) -m pytest -v
@echo -e "$(GREEN)✅ All CLI tests passed!$(NC)"
test-config-library: ## Run only config library validation tests
@echo "Validating config library YAML/JSON files..."
$(PYTHON) -m pytest config_library/test_config_library.py -v
test-capacity: ## Run only capacity planning tests
@echo "Running capacity planning Lambda tests..."
cd src/lambda/calculate_capacity && $(PYTHON) -m pytest -v
test-capacity-coverage: ## Run capacity planning tests with coverage report
@echo "Running capacity planning Lambda tests with coverage..."
cd src/lambda/calculate_capacity && $(PYTHON) -m pytest --cov=. --cov-report=term --cov-report=html -v
@echo -e "$(GREEN)✅ Coverage report generated at src/lambda/calculate_capacity/htmlcov/index.html$(NC)"
##@ UI Development
# Usage: make ui-start STACK_NAME=<stack-name>
ui-start: ## Start UI dev server (requires STACK_NAME for .env generation)
ifndef STACK_NAME
$(error STACK_NAME is not set. Usage: make ui-start STACK_NAME)
endif
@if [ -n "$(STACK_NAME)" ]; then \
echo "Retrieving .env configuration from stack $(STACK_NAME)..."; \
ENV_CONTENT=$$(aws cloudformation describe-stacks \
--stack-name $(STACK_NAME) \
--query "Stacks[0].Outputs[?OutputKey=='WebUITestEnvFile'].OutputValue" \
--output text 2>/dev/null); \
if [ -z "$$ENV_CONTENT" ] || [ "$$ENV_CONTENT" = "None" ]; then \
echo -e "$(RED)ERROR: Could not retrieve WebUITestEnvFile from stack $(STACK_NAME)$(NC)"; \
echo -e "$(YELLOW)Make sure the stack exists and has completed deployment.$(NC)"; \
exit 1; \
fi; \
echo "$$ENV_CONTENT" > src/ui/.env; \
echo -e "$(GREEN)✅ Created src/ui/.env from stack outputs$(NC)"; \
fi
@if [ ! -f src/ui/.env ]; then \
echo -e "$(RED)ERROR: src/ui/.env not found$(NC)"; \
echo -e "$(YELLOW)Either provide STACK_NAME to auto-generate, or create .env manually.$(NC)"; \
echo -e "$(YELLOW)Usage: make ui-start STACK_NAME=<your-stack-name>$(NC)"; \
exit 1; \
fi
@echo "Installing UI dependencies..."
cd src/ui && npm ci --prefer-offline --no-audit
@echo "Starting UI development server..."
cd src/ui && npm run start
ui-lint: ## Run UI linting with checksum caching (skips if unchanged). Use FORCE=1 to force re-run.
@echo "Checking if UI lint is needed..."
@CURRENT_HASH=$$($(PYTHON) -c "from publish import IDPPublisher; p = IDPPublisher(); print(p.get_directory_checksum('src/ui'))"); \
STORED_HASH=$$(test -f src/ui/.checksum && cat src/ui/.checksum || echo ""); \
if [ -n "$(FORCE)" ] || [ "$$CURRENT_HASH" != "$$STORED_HASH" ]; then \
if [ -n "$(FORCE)" ]; then \
echo "FORCE=1 set - running lint..."; \
else \
echo "UI code checksum changed - running lint..."; \
fi; \
cd src/ui && npm ci --prefer-offline --no-audit && npm run lint -- --fix && npm run typecheck || exit 1; \
echo "$$CURRENT_HASH" > .checksum; \
echo -e "$(GREEN)✅ UI lint and typecheck completed and checksum updated$(NC)"; \
else \
echo -e "$(GREEN)✅ UI code checksum unchanged - skipping lint (use FORCE=1 to force re-run)$(NC)"; \
fi
ui-build: ## Build UI for production
@echo "Checking UI build"
cd src/ui && npm ci --prefer-offline --no-audit && npm run build
##@ Code Generation
codegen: ## Regenerate GraphQL types and operations
@cd src/ui && npm run codegen
@echo -e "$(GREEN)✅ GraphQL types regenerated. Don't forget to commit the changes.$(NC)"
codegen-check: ## Verify GraphQL codegen output is up-to-date
@echo "Checking if GraphQL codegen output is up-to-date..."
@cd src/ui && npm ci --prefer-offline --no-audit && npm run codegen
@if ! git diff --quiet src/ui/src/graphql/generated/; then \
if [ -n "$$CI" ] || [ -n "$$GITHUB_ACTIONS" ]; then \
echo -e "$(RED)ERROR: Generated GraphQL files are out of date!$(NC)"; \
echo -e "$(YELLOW)Run 'make codegen' and commit the updated files.$(NC)"; \
git --no-pager diff --stat src/ui/src/graphql/generated/; \
exit 1; \
else \
echo -e "$(YELLOW)Generated GraphQL files were out of date — auto-updated.$(NC)"; \
git --no-pager diff --stat src/ui/src/graphql/generated/; \
echo -e "$(YELLOW)Please commit the changes above.$(NC)"; \
fi \
else \
echo -e "$(GREEN)✅ GraphQL codegen output is up-to-date$(NC)"; \
fi
classes-from-bda: ## Generate standard class catalog from BDA blueprints
@echo "Generating standard class catalog from BDA standard blueprints..."
$(PYTHON) scripts/generate_standard_classes.py --region us-east-1 --output src/ui/src/data/standard-classes.json
@echo -e "$(GREEN)✅ Standard class catalog updated! Review changes in src/ui/src/data/standard-classes.json$(NC)"
##@ Git Workflow
commit: lint test ## Lint, test, auto-generate commit message, commit, and push
@echo "Generating commit message via Bedrock..."
@git add . && \
COMMIT_MESSAGE=$$(bash scripts/generate_commit_message.sh) && \
echo "Commit message: $$COMMIT_MESSAGE" && \
git commit -m "$$COMMIT_MESSAGE" && \
git push
fastcommit: fastlint ## Fast lint only, auto-generate commit message, commit, and push
@echo "Generating commit message via Bedrock..."
@git add . && \
COMMIT_MESSAGE=$$(bash scripts/generate_commit_message.sh) && \
echo "Commit message: $$COMMIT_MESSAGE" && \
git commit -m "$$COMMIT_MESSAGE" && \
git push
##@ Version Management
# Usage: make version V=0.6.0
# Validates PEP 440 compliance before updating (e.g., 0.5.3, 1.0.0, 0.6.0.dev1, 1.0.0rc1)
.PHONY: version
version: ## Update version across all packages (Usage: make version V=x.y.z)
ifndef V
$(error VERSION is not set. Usage: make version V=x.y.z)
endif
@$(PYTHON) -c "from packaging.version import Version; Version('$(V)')" 2>/dev/null || \
(echo -e "$(RED)ERROR: '$(V)' is not a valid PEP 440 version.$(NC)" && \
echo -e "$(YELLOW)Valid examples: 0.5.3, 1.0.0, 0.6.0.dev1, 1.0.0a1, 1.0.0rc1, 1.0.0.post1$(NC)" && \
echo -e "$(YELLOW)Invalid examples: 0.5.3.wip5, 1.0-beta, v1.0.0$(NC)" && \
exit 1)
@echo "Updating version to $(V)..."
@echo "$(V)" > VERSION
@sed -i.bak 's/^version = ".*"/version = "$(V)"/' lib/idp_cli_pkg/pyproject.toml && rm -f lib/idp_cli_pkg/pyproject.toml.bak
@sed -i.bak 's/^version = ".*"/version = "$(V)"/' lib/idp_sdk/pyproject.toml && rm -f lib/idp_sdk/pyproject.toml.bak
@sed -i.bak 's/^version = ".*"/version = "$(V)"/' lib/idp_common_pkg/pyproject.toml && rm -f lib/idp_common_pkg/pyproject.toml.bak
@sed -i.bak 's/version=".*"/version="$(V)"/' lib/idp_common_pkg/setup.py && rm -f lib/idp_common_pkg/setup.py.bak
@sed -i.bak 's/@click.version_option(version=".*")/@click.version_option(version="$(V)")/' lib/idp_cli_pkg/idp_cli/cli.py && rm -f lib/idp_cli_pkg/idp_cli/cli.py.bak
@sed -i.bak 's/^__version__ = ".*"/__version__ = "$(V)"/' lib/idp_sdk/idp_sdk/__init__.py && rm -f lib/idp_sdk/idp_sdk/__init__.py.bak
@sed -i.bak 's/^version = ".*"/version = "$(V)"/' lib/idp_mcp_connector_pkg/pyproject.toml && rm -f lib/idp_mcp_connector_pkg/pyproject.toml.bak
@sed -i.bak 's/^__version__ = ".*"/__version__ = "$(V)"/' lib/idp_mcp_connector_pkg/idp_mcp_connector/__init__.py && rm -f lib/idp_mcp_connector_pkg/idp_mcp_connector/__init__.py.bak
@echo -e "$(GREEN)✅ Version updated to $(V) in:$(NC)"
@echo " - VERSION"
@echo " - lib/idp_cli_pkg/pyproject.toml"
@echo " - lib/idp_cli_pkg/idp_cli/cli.py"
@echo " - lib/idp_sdk/pyproject.toml"
@echo " - lib/idp_sdk/idp_sdk/__init__.py"
@echo " - lib/idp_common_pkg/pyproject.toml"
@echo " - lib/idp_common_pkg/setup.py"
@echo " - lib/idp_mcp_connector_pkg/pyproject.toml"
@echo " - lib/idp_mcp_connector_pkg/idp_mcp_connector/__init__.py"
##@ Documentation
docs: docs-build ## Build and serve the documentation site locally
@echo "Starting docs preview server..."
cd docs-site && npm run preview
docs-setup: ## One-time docs site setup (symlinks + npm install)
@echo "Setting up documentation site..."
cd docs-site && bash setup.sh && npm install
@echo -e "$(GREEN)✅ Docs site setup complete!$(NC)"
docs-build: docs-setup ## Build documentation site (no serve)
@echo "Syncing sidebar with new docs..."
cd docs-site && node sync-sidebar.mjs
@echo "Building documentation site..."
cd docs-site && npm run build
@echo -e "$(GREEN)✅ Docs site built! $(NC)"
@echo "Preview at: http://localhost:4321"
docs-deploy: docs-build ## Deploy docs to GitHub Pages (from local build)
@echo "Deploying documentation site to GitHub Pages..."
touch docs-site/dist/.nojekyll
cd docs-site && npx gh-pages -d dist --dotfiles --repo https://github.com/aws-solutions-library-samples/accelerated-intelligent-document-processing-on-aws.git
@echo -e "$(GREEN)✅ Docs deployed to GitHub Pages!$(NC)"
##@ Security (DSR)
dsr: ## Run full DSR workflow (setup → scan → optional fix)
@$(MAKE) dsr-setup
@$(MAKE) dsr-scan
@echo ""
@echo "Do you want to run DSR fix? (y/N):"
@read answer && \
if [ "$$answer" = "y" ] || [ "$$answer" = "Y" ]; then \
$(MAKE) dsr-fix; \
fi
dsr-setup: ## Set up DSR tool
@echo "Setting up DSR tool..."
$(PYTHON) scripts/dsr/setup.py
dsr-scan: ## Run DSR security scan
@echo "Running DSR security scan..."
$(PYTHON) scripts/dsr/run.py
dsr-fix: ## Run DSR interactive fix
@echo "Running DSR interactive fix..."
$(PYTHON) scripts/dsr/fix.py
##@ Deploy
# Thin wrappers around `idp-cli publish` / `deploy` / `delete` for the common
# 80% case. Uncommon flags can still be passed via EXTRA_ARGS="--foo --bar".
# See 'docs/idp-cli.md' (or 'idp-cli <cmd> --help') for the full option list.
.PHONY: publish deploy delete-stack
# Usage examples:
# make publish REGION=us-east-1
# make publish REGION=us-east-1 BUCKET_BASENAME=my-idp-artifacts PREFIX=v1
# make publish REGION=us-gov-west-1 HEADLESS=1
# make publish REGION=us-east-1 PUBLIC=1 EXTRA_ARGS="--clean-build --verbose"
publish: ## Build & publish IDP artifacts to S3 (Usage: make publish REGION=... [BUCKET_BASENAME=...] [PREFIX=...] [HEADLESS=1] [PUBLIC=1] [EXTRA_ARGS=...])
ifndef REGION
$(error REGION is not set. Usage: make publish REGION=us-east-1 [BUCKET_BASENAME=...] [PREFIX=...] [HEADLESS=1] [PUBLIC=1] [EXTRA_ARGS=...])
endif
@echo -e "$(CYAN)Running idp-cli publish (region=$(REGION))...$(NC)"
$(IDP_CLI) publish \
--source-dir . \
--region $(REGION) \
$(if $(BUCKET_BASENAME),--bucket-basename $(BUCKET_BASENAME)) \
$(if $(PREFIX),--prefix $(PREFIX)) \
$(if $(HEADLESS),--headless) \
$(if $(PUBLIC),--public) \
$(EXTRA_ARGS)
# Usage examples:
# make deploy STACK_NAME=my-idp ADMIN_EMAIL=me@example.com # create new stack
# make deploy STACK_NAME=my-idp # update existing stack
# make deploy STACK_NAME=my-idp-dev ADMIN_EMAIL=me@example.com FROM_CODE=1 # build & deploy from local source
# make deploy STACK_NAME=my-idp ADMIN_EMAIL=me@example.com HEADLESS=1 # headless (no UI)
# make deploy STACK_NAME=my-idp CUSTOM_CONFIG=./my-config.yaml # update config on existing stack
# make deploy STACK_NAME=my-idp NO_WAIT=1 # fire-and-forget (default is --wait)
# make deploy STACK_NAME=my-idp EXTRA_ARGS="--max-concurrent 200 --log-level DEBUG"
deploy: ## Deploy/update IDP CloudFormation stack (Usage: make deploy STACK_NAME=... [ADMIN_EMAIL=...] [REGION=...] [FROM_CODE=1] [HEADLESS=1] [CUSTOM_CONFIG=...] [TEMPLATE_URL=...] [TEMPLATE_FILE=...] [NO_WAIT=1] [EXTRA_ARGS=...])
ifndef STACK_NAME
$(error STACK_NAME is not set. Usage: make deploy STACK_NAME=my-stack [ADMIN_EMAIL=...] [REGION=...] [FROM_CODE=1] [HEADLESS=1] [CUSTOM_CONFIG=...] [NO_WAIT=1] [EXTRA_ARGS=...])
endif
@echo -e "$(CYAN)Running idp-cli deploy (stack=$(STACK_NAME))...$(NC)"
$(IDP_CLI) deploy \
--stack-name $(STACK_NAME) \
$(if $(ADMIN_EMAIL),--admin-email $(ADMIN_EMAIL)) \
$(if $(REGION),--region $(REGION)) \
$(if $(FROM_CODE),--from-code .) \
$(if $(HEADLESS),--headless) \
$(if $(CUSTOM_CONFIG),--custom-config $(CUSTOM_CONFIG)) \
$(if $(TEMPLATE_URL),--template-url $(TEMPLATE_URL)) \
$(if $(TEMPLATE_FILE),--template-file $(TEMPLATE_FILE)) \
$(if $(NO_WAIT),,--wait) \
$(EXTRA_ARGS)
# Usage examples:
# make delete-stack STACK_NAME=test-stack # interactive
# make delete-stack STACK_NAME=test-stack FORCE=1 # skip confirmation
# make delete-stack STACK_NAME=test-stack FORCE=1 EMPTY_BUCKETS=1 # empty buckets first
# make delete-stack STACK_NAME=test-stack FORCE=1 FORCE_DELETE_ALL=1 # comprehensive cleanup
delete-stack: ## Delete an IDP CloudFormation stack (Usage: make delete-stack STACK_NAME=... [FORCE=1] [EMPTY_BUCKETS=1] [FORCE_DELETE_ALL=1] [REGION=...] [NO_WAIT=1] [EXTRA_ARGS=...])
ifndef STACK_NAME
$(error STACK_NAME is not set. Usage: make delete-stack STACK_NAME=my-stack [FORCE=1] [EMPTY_BUCKETS=1] [FORCE_DELETE_ALL=1])
endif
@echo -e "$(YELLOW)Running idp-cli delete (stack=$(STACK_NAME))...$(NC)"
$(IDP_CLI) delete \
--stack-name $(STACK_NAME) \
$(if $(FORCE),--force) \
$(if $(EMPTY_BUCKETS),--empty-buckets) \
$(if $(FORCE_DELETE_ALL),--force-delete-all) \
$(if $(REGION),--region $(REGION)) \
$(if $(NO_WAIT),,--wait) \
$(EXTRA_ARGS)