Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
466 lines (391 loc) · 16.1 KB
/
Copy pathMakefile
File metadata and controls
466 lines (391 loc) · 16.1 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
# Makefile for lowkey CLI
# Docker image settings
IMAGE_NAME = lowkey
IMAGE_TAG = latest
REGISTRY = ghcr.io/moonbeam-nyc
FULL_IMAGE = $(REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG)
# Default target
.PHONY: help
help: ## Show this help message
@echo "Available commands:"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}'
# Docker build commands
.PHONY: docker-build
docker-build: ## Build Docker image locally
docker build -t $(IMAGE_NAME):$(IMAGE_TAG) .
.PHONY: docker-build-full
docker-build-full: ## Build Docker image with full registry path
docker build -t $(FULL_IMAGE) .
# Docker run commands
.PHONY: docker-run
docker-run: ## Run Docker container with help command
docker run --rm $(IMAGE_NAME):$(IMAGE_TAG)
.PHONY: docker-run-version
docker-run-version: ## Show version using Docker container
docker run --rm $(IMAGE_NAME):$(IMAGE_TAG) --version
.PHONY: docker-run-help
docker-run-help: ## Show help using Docker container
docker run --rm $(IMAGE_NAME):$(IMAGE_TAG) --help
# Interactive development commands
.PHONY: docker-run-shell
docker-run-shell: ## Run container with shell for debugging
docker run --rm -it --entrypoint /bin/sh $(IMAGE_NAME):$(IMAGE_TAG)
.PHONY: docker-run-aws
docker-run-aws: ## Run container with AWS environment variables mounted
docker run --rm \
-e AWS_ACCESS_KEY_ID \
-e AWS_SECRET_ACCESS_KEY \
-e AWS_REGION \
-e AWS_PROFILE \
-v ~/.aws:/home/lowkey/.aws:ro \
$(IMAGE_NAME):$(IMAGE_TAG) $(ARGS)
# Example usage commands
.PHONY: docker-example-copy-env
docker-example-copy-env: ## Example: Copy secrets to env format (requires AWS credentials)
$(MAKE) docker-run-aws ARGS="copy --input-type aws-secrets-manager --input-name example-secret --output-type env"
.PHONY: docker-example-copy-json
docker-example-copy-json: ## Example: Copy secrets to JSON format (requires AWS credentials)
$(MAKE) docker-run-aws ARGS="copy --input-type aws-secrets-manager --input-name example-secret --output-type json"
.PHONY: docker-example-list-aws
docker-example-list-aws: ## Example: List AWS secrets (requires AWS credentials)
$(MAKE) docker-run-aws ARGS="list --type aws-secrets-manager --region us-east-1"
.PHONY: docker-example-list-env
docker-example-list-env: ## Example: List .env files in current directory
docker run --rm -v $(PWD):/workspace $(IMAGE_NAME):$(IMAGE_TAG) list --type env --path /workspace
.PHONY: docker-example-list-json
docker-example-list-json: ## Example: List JSON files in current directory
docker run --rm -v $(PWD):/workspace $(IMAGE_NAME):$(IMAGE_TAG) list --type json --path /workspace
# File output commands
.PHONY: docker-run-output
docker-run-output: ## Run container with volume mount for file output
docker run --rm \
-e AWS_ACCESS_KEY_ID \
-e AWS_SECRET_ACCESS_KEY \
-e AWS_REGION \
-e AWS_PROFILE \
-v ~/.aws:/home/lowkey/.aws:ro \
-v $(PWD):/workspace \
$(IMAGE_NAME):$(IMAGE_TAG) $(ARGS)
# Testing commands
.PHONY: docker-test-build
docker-test-build: docker-build docker-run-version ## Build and test that the container works
@echo "✅ Docker build and basic functionality test passed"
.PHONY: docker-test-all
docker-test-all: docker-build docker-run docker-run-version docker-run-help ## Run all basic tests
@echo "✅ All basic tests passed"
# Cleanup commands
.PHONY: docker-clean
docker-clean: ## Remove locally built Docker images
docker rmi $(IMAGE_NAME):$(IMAGE_TAG) 2>/dev/null || true
docker rmi $(FULL_IMAGE) 2>/dev/null || true
.PHONY: docker-clean-all
docker-clean-all: docker-clean ## Remove all Docker images and containers
docker system prune -f
.PHONY: clean-all
clean-all: docker-clean-all k3d-clean localstack-clean log-clean ## Clean everything: Docker, k3d, LocalStack, and logs
@echo "✅ All environments and resources cleaned up"
# Development commands
.PHONY: dev-install
dev-install: ## Install dependencies locally for development
npm install
.PHONY: dev-link
dev-link: ## Link package globally for local development
npm link
.PHONY: dev-unlink
dev-unlink: ## Unlink global package
npm unlink -g @moonbeam-nyc/lowkey
# Package version commands
.PHONY: version-patch
version-patch: ## Bump patch version
npm run version:patch
.PHONY: version-minor
version-minor: ## Bump minor version
npm run version:minor
.PHONY: version-major
version-major: ## Bump major version
npm run version:major
# Package publish commands (version + publish)
.PHONY: publish-patch
publish-patch: ## Bump patch version and publish to npm
npm run publish:patch
.PHONY: publish-minor
publish-minor: ## Bump minor version and publish to npm
npm run publish:minor
.PHONY: publish-major
publish-major: ## Bump major version and publish to npm
npm run publish:major
# Kubernetes (k3d) cluster management
.PHONY: k3d-check
k3d-check: ## Check if k3d is installed
@which k3d > /dev/null 2>&1 || (echo "❌ k3d is not installed. Install it with: make k3d-install" && exit 1)
@echo "✅ k3d is installed: $$(k3d version)"
.PHONY: k3d-install
k3d-install: ## Install k3d (macOS/Linux)
@echo "Installing k3d..."
@if [ "$$(uname)" = "Darwin" ]; then \
if which brew > /dev/null 2>&1; then \
brew install k3d; \
else \
curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash; \
fi \
else \
curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash; \
fi
@echo "✅ k3d installed successfully"
.PHONY: k3d-create
k3d-create: k3d-check ## Create a local k3d cluster named 'lowkey-test'
k3d cluster create lowkey-test \
--servers 1 \
--agents 2 \
--port "8080:80@loadbalancer" \
--port "8443:443@loadbalancer" \
--wait
@echo "✅ k3d cluster 'lowkey-test' created successfully"
@echo "Run 'make k3d-context' to switch to this cluster"
.PHONY: k3d-delete
k3d-delete: ## Delete the k3d cluster 'lowkey-test'
k3d cluster delete lowkey-test
@echo "✅ k3d cluster 'lowkey-test' deleted"
.PHONY: k3d-stop
k3d-stop: ## Stop the k3d cluster 'lowkey-test'
@k3d cluster stop lowkey-test
@echo "⏳ Waiting for containers to stop..."
@while docker ps --format '{{.Names}}' | grep -q 'k3d-lowkey-test'; do \
sleep 1; \
done
@echo "✅ k3d cluster 'lowkey-test' stopped and all containers are down"
.PHONY: k3d-start
k3d-start: ## Start the k3d cluster 'lowkey-test'
k3d cluster start lowkey-test
@echo "✅ k3d cluster 'lowkey-test' started"
.PHONY: k3d-context
k3d-context: ## Set kubectl context to k3d-lowkey-test
kubectl config use-context k3d-lowkey-test
@echo "✅ kubectl context switched to 'k3d-lowkey-test'"
.PHONY: k3d-status
k3d-status: ## Show status of k3d clusters
@echo "k3d clusters:"
@k3d cluster list
@echo ""
@echo "Current kubectl context:"
@kubectl config current-context
.PHONY: k3d-clean
k3d-clean: ## Clean up k3d cluster and all resources (safe to run even if cluster doesn't exist)
@k3d cluster delete lowkey-test 2>/dev/null || true
@echo "✅ k3d cluster and resources cleaned up"
.PHONY: k3d-restart
k3d-restart: k3d-stop k3d-start ## Restart the k3d cluster
@echo "✅ k3d cluster restarted"
.PHONY: k3d-setup
k3d-setup: k3d-create k3d-context ## Create cluster and set context (one command setup)
@echo "✅ k3d cluster ready to use!"
# Debug and logging commands
.PHONY: debug-run
debug-run: ## Run lowkey in debug mode with logging
LOWKEY_DEBUG=true node cli.js $(ARGS)
.PHONY: debug-interactive
debug-interactive: ## Run interactive mode with debug logging
LOWKEY_DEBUG=true LOCALSTACK_ENDPOINT=http://localhost:4566 AWS_REGION=us-east-1 node cli.js interactive
.PHONY: log
log: ## View the latest debug log
@if [ -f "$$(ls -1t lowkey-logs/lowkey-debug-*.log 2>/dev/null | head -1)" ]; then \
tail -f "$$(ls -1t lowkey-logs/lowkey-debug-*.log | head -1)"; \
else \
echo "No debug logs found. Run with LOWKEY_DEBUG=true or use 'make debug-run'"; \
fi
.PHONY: log-latest
log-latest: ## Cat the entire latest debug log
@if [ -f "$$(ls -1t lowkey-logs/lowkey-debug-*.log 2>/dev/null | head -1)" ]; then \
cat "$$(ls -1t lowkey-logs/lowkey-debug-*.log | head -1)"; \
else \
echo "No debug logs found. Run with LOWKEY_DEBUG=true or use 'make debug-run'"; \
fi
.PHONY: log-clean
log-clean: ## Clean up all debug logs
rm -rf lowkey-logs/
.PHONY: log-list
log-list: ## List all debug log files
@if [ -d lowkey-logs ]; then \
ls -lht lowkey-logs/*.log 2>/dev/null | head -20 || echo "No logs found"; \
else \
echo "No logs directory found"; \
fi
# Testing commands
.PHONY: test-setup
test-setup: ## Setup test environment (LocalStack and k3d)
@./scripts/test-setup.sh
.PHONY: test
test: test-setup ## Run all tests with automatic environment setup
@echo "🧪 Running all tests..."
@export LOCALSTACK_ENDPOINT=http://localhost:4566; \
export AWS_ACCESS_KEY_ID=test; \
export AWS_SECRET_ACCESS_KEY=test; \
export AWS_DEFAULT_REGION=us-east-1; \
npm test
.PHONY: test-quick
test-quick: ## Run tests without environment setup (quick, may skip some tests)
npm test
.PHONY: test-watch
test-watch: ## Run tests in watch mode
npm run test:watch
.PHONY: test-unit
test-unit: ## Run only unit tests
node --test tests/unit/*.test.js
.PHONY: test-integration
test-integration: ## Run only integration tests
node --test tests/integration/*.test.js
.PHONY: test-coverage
test-coverage: ## Run tests with coverage report
npm run test:coverage
.PHONY: test-coverage-threshold
test-coverage-threshold: ## Run tests with coverage and enforce 80% threshold
npm run test:coverage:threshold
.PHONY: test-coverage-with-setup
test-coverage-with-setup: test-setup ## Run full test suite with coverage and automatic environment setup
@echo "📊 Running full test suite with coverage..."
@export LOCALSTACK_ENDPOINT=http://localhost:4566; \
export AWS_ACCESS_KEY_ID=test; \
export AWS_SECRET_ACCESS_KEY=test; \
export AWS_DEFAULT_REGION=us-east-1; \
npm run test:coverage
.PHONY: test-coverage-threshold-with-setup
test-coverage-threshold-with-setup: test-setup ## Run full test suite with coverage and enforce 80% threshold
@echo "📊 Running full test suite with coverage and threshold enforcement..."
@export LOCALSTACK_ENDPOINT=http://localhost:4566; \
export AWS_ACCESS_KEY_ID=test; \
export AWS_SECRET_ACCESS_KEY=test; \
export AWS_DEFAULT_REGION=us-east-1; \
npm run test:coverage:threshold
.PHONY: test-ci
test-ci: test-coverage-threshold-with-setup ## Run tests for CI with coverage requirements and environment setup
@echo "✅ All tests passed for CI with coverage requirements"
.PHONY: ci-local
ci-local: ## Run the same checks as CI locally
@echo "🚀 Running CI checks locally..."
@echo "1️⃣ Syntax validation..."
@node --check cli.js
@find lib commands tests -name "*.js" -exec node --check {} \; 2>/dev/null || true
@echo "2️⃣ Unit tests..."
@$(MAKE) test-unit
@echo "3️⃣ Full test suite with coverage and threshold..."
@$(MAKE) test-coverage-threshold-with-setup
@echo "✅ All CI checks passed locally!"
.PHONY: ci-quick
ci-quick: ## Quick CI validation without external services
@echo "⚡ Running quick CI checks..."
@node --check cli.js
@npm run test:unit
@echo "✅ Quick CI checks passed!"
# LocalStack commands for AWS simulation
.PHONY: localstack-start
localstack-start: ## Start LocalStack for AWS simulation
docker compose -f docker-compose.localstack.yml up -d
@echo "✅ LocalStack started on http://localhost:4566"
@echo "Use 'make localstack-status' to check if services are ready"
.PHONY: localstack-stop
localstack-stop: ## Stop LocalStack
docker compose -f docker-compose.localstack.yml down
@echo "✅ LocalStack stopped"
.PHONY: localstack-restart
localstack-restart: localstack-stop localstack-start ## Restart LocalStack
@echo "✅ LocalStack restarted"
.PHONY: localstack-logs
localstack-logs: ## View LocalStack logs
docker compose -f docker-compose.localstack.yml logs -f localstack
.PHONY: localstack-status
localstack-status: ## Check LocalStack health status
@echo "LocalStack Health Check:"
@curl -s http://localhost:4566/_localstack/health | jq . 2>/dev/null || curl -s http://localhost:4566/_localstack/health
.PHONY: localstack-clean
localstack-clean: ## Stop LocalStack and clean up volumes (safe to run even if not running)
@docker compose -f docker-compose.localstack.yml down -v 2>/dev/null || true
@rm -rf tmp/localstack 2>/dev/null || true
@echo "✅ LocalStack cleaned up"
.PHONY: localstack-test-setup
localstack-test-setup: localstack-start ## Start LocalStack and create test secrets
@echo "Waiting for LocalStack to be ready..."
@for i in $$(seq 1 20); do \
if curl -s http://localhost:4566/_localstack/health >/dev/null 2>&1; then \
echo "✅ LocalStack is ready after $$((i*3)) seconds"; \
break; \
fi; \
if [ $$i -eq 20 ]; then \
echo "❌ LocalStack failed to start after 60 seconds"; \
exit 1; \
fi; \
printf "."; \
sleep 3; \
done; \
echo ""; \
echo "Creating test secrets..."
@docker compose -f docker-compose.localstack.yml exec -T localstack \
awslocal secretsmanager delete-secret --secret-id test-secret --force-delete-without-recovery >/dev/null 2>&1 || true
@docker compose -f docker-compose.localstack.yml exec -T localstack \
awslocal secretsmanager create-secret \
--name test-secret \
--secret-string '{"username":"testuser","password":"testpass","api_key":"test123"}' || true
@echo "✅ Test environment ready"
.PHONY: localstack-test-list
localstack-test-list: ## List secrets in LocalStack
@docker compose -f docker-compose.localstack.yml exec -T localstack \
awslocal secretsmanager list-secrets
.PHONY: test-localstack
test-localstack: localstack-test-setup ## Run tests against LocalStack
@echo "Running tests with LocalStack..."
@LOCALSTACK_ENDPOINT=http://localhost:4566 \
AWS_ACCESS_KEY_ID=test \
AWS_SECRET_ACCESS_KEY=test \
AWS_REGION=us-east-1 \
NODE_ENV=test \
npm test
@echo "✅ LocalStack tests completed"
.PHONY: test-aws
test-aws: localstack-test-setup ## Run only AWS copy tests against LocalStack
@echo "Running AWS copy tests with LocalStack..."
@LOCALSTACK_ENDPOINT=http://localhost:4566 \
AWS_ACCESS_KEY_ID=test \
AWS_SECRET_ACCESS_KEY=test \
AWS_REGION=us-east-1 \
NODE_ENV=test \
node --test tests/integration/copy-aws.test.js
@echo "✅ AWS copy tests completed"
# Helper target to ensure LocalStack is running
.PHONY: localstack-ensure-running
localstack-ensure-running:
@if ! curl -s http://localhost:4566/_localstack/health >/dev/null 2>&1; then \
echo "🚀 LocalStack not running, starting it..."; \
$(MAKE) localstack-start; \
echo "⏳ Waiting for LocalStack to be ready..."; \
for i in $$(seq 1 20); do \
if curl -s http://localhost:4566/_localstack/health >/dev/null 2>&1; then \
echo "✅ LocalStack is ready after $$((i*3)) seconds"; \
break; \
fi; \
if [ $$i -eq 20 ]; then \
echo "❌ LocalStack failed to start after 60 seconds"; \
exit 1; \
fi; \
printf "."; \
sleep 3; \
done; \
echo ""; \
fi
# LocalStack development commands with environment pre-configured
.PHONY: localstack-interactive
localstack-interactive: ## Run lowkey interactive mode with LocalStack (auto-starts LocalStack)
@echo "🔍 Checking if LocalStack is running..."
@$(MAKE) localstack-ensure-running
@echo "🎯 Starting lowkey interactive with LocalStack..."
@LOCALSTACK_ENDPOINT=http://localhost:4566 AWS_REGION=us-east-1 node cli.js interactive
.PHONY: localstack-list
localstack-list: localstack-ensure-running ## List secrets in LocalStack (auto-starts LocalStack)
@LOCALSTACK_ENDPOINT=http://localhost:4566 AWS_REGION=us-east-1 node cli.js list --type aws-secrets-manager --region us-east-1
.PHONY: localstack-copy
localstack-copy: localstack-ensure-running ## Copy secrets with LocalStack (auto-starts LocalStack, requires ARGS)
@LOCALSTACK_ENDPOINT=http://localhost:4566 AWS_REGION=us-east-1 node cli.js copy $(ARGS)
.PHONY: localstack-inspect
localstack-inspect: localstack-ensure-running ## Inspect secrets with LocalStack (auto-starts LocalStack, requires ARGS)
@LOCALSTACK_ENDPOINT=http://localhost:4566 AWS_REGION=us-east-1 node cli.js inspect $(ARGS)
.PHONY: localstack-run
localstack-run: localstack-ensure-running ## Run any lowkey command with LocalStack (auto-starts LocalStack, requires ARGS)
@LOCALSTACK_ENDPOINT=http://localhost:4566 AWS_REGION=us-east-1 node cli.js $(ARGS)