|
1 | 1 | # Makefile for eoapi-k8s |
2 | 2 |
|
3 | 3 | # Variables |
4 | | -HELM_REPO_URL=https://devseed.com/eoapi-k8s/ |
5 | | -HELM_CHART_NAME=eoapi/eoapi |
6 | | -PGO_CHART_VERSION=5.7.4 |
| 4 | +LOCAL_CLUSTER_SCRIPT := ./scripts/local-cluster.sh |
| 5 | +DEPLOY_SCRIPT := ./scripts/deploy.sh |
| 6 | +TEST_SCRIPT := ./scripts/test.sh |
7 | 7 |
|
8 | | -.PHONY: all deploy minikube ingest tests integration lint validate-schema help |
| 8 | +# Default cluster type (can be overridden) |
| 9 | +CLUSTER_TYPE ?= k3s |
9 | 10 |
|
10 | | -# Default target |
11 | | -all: deploy |
| 11 | +.PHONY: help deploy clean test test-local lint validate |
| 12 | +.DEFAULT_GOAL := help |
| 13 | + |
| 14 | +help: |
| 15 | + @echo "eoAPI Kubernetes Makefile" |
| 16 | + @echo "" |
| 17 | + @echo "MAIN COMMANDS:" |
| 18 | + @echo " deploy Deploy eoAPI to current kubectl context" |
| 19 | + @echo " test Run Helm unit tests" |
| 20 | + @echo " integration Run integration tests on current cluster" |
| 21 | + @echo " clean Clean up deployment" |
| 22 | + @echo "" |
| 23 | + @echo "LOCAL DEVELOPMENT:" |
| 24 | + @echo " local Create local cluster and deploy (CLUSTER_TYPE=minikube|k3s)" |
| 25 | + @echo " local-start Start existing local cluster" |
| 26 | + @echo " local-stop Stop local cluster" |
| 27 | + @echo " local-delete Delete local cluster" |
| 28 | + @echo " local-status Show local cluster status" |
| 29 | + @echo " test-local Run full integration tests on local cluster" |
| 30 | + @echo "" |
| 31 | + @echo "QUALITY:" |
| 32 | + @echo " lint Run linting and code quality checks" |
| 33 | + @echo " validate Validate Helm schemas" |
| 34 | + @echo "" |
| 35 | + @echo "VARIABLES:" |
| 36 | + @echo " CLUSTER_TYPE Local cluster type: minikube or k3s (default: k3s)" |
| 37 | + @echo "" |
| 38 | + @echo "EXAMPLES:" |
| 39 | + @echo " make local CLUSTER_TYPE=minikube" |
| 40 | + @echo " make test-local CLUSTER_TYPE=k3s" |
12 | 41 |
|
13 | 42 | deploy: |
14 | | - @echo "Deploying eoAPI." |
15 | | - @command -v bash >/dev/null 2>&1 || { echo "bash is required but not installed"; exit 1; } |
16 | | - @./scripts/deploy.sh |
17 | | - |
18 | | -minikube: |
19 | | - @echo "Starting minikube." |
20 | | - @command -v minikube >/dev/null 2>&1 || { echo "minikube is required but not installed"; exit 1; } |
21 | | - minikube start |
22 | | - # Deploy eoAPI via the regular helm install routine |
23 | | - @make deploy |
24 | | - minikube addons enable ingress |
25 | | - @echo "eoAPI is now available at:" |
26 | | - @minikube service ingress-nginx-controller -n ingress-nginx --url | head -n 1 |
| 43 | + @$(DEPLOY_SCRIPT) |
27 | 44 |
|
28 | | -ingest: |
29 | | - @echo "Ingesting STAC collections and items into the database." |
30 | | - @command -v bash >/dev/null 2>&1 || { echo "bash is required but not installed"; exit 1; } |
31 | | - @./scripts/ingest.sh || { echo "Ingestion failed."; exit 1; } |
| 45 | +clean: |
| 46 | + @$(DEPLOY_SCRIPT) cleanup |
32 | 47 |
|
33 | | -tests: |
34 | | - @echo "Running Helm unit tests..." |
35 | | - @command -v helm >/dev/null 2>&1 || { echo "helm is required but not installed"; exit 1; } |
36 | | - @./scripts/deploy.sh setup |
37 | | - @./scripts/test.sh helm |
| 48 | +test: |
| 49 | + @$(DEPLOY_SCRIPT) setup |
| 50 | + @$(TEST_SCRIPT) helm |
38 | 51 |
|
39 | 52 | integration: |
40 | | - @echo "Running integration tests against Kubernetes cluster..." |
41 | | - @command -v bash >/dev/null 2>&1 || { echo "bash is required but not installed"; exit 1; } |
42 | | - @./scripts/test.sh integration |
| 53 | + @$(TEST_SCRIPT) integration |
| 54 | + |
| 55 | +local: |
| 56 | + @$(LOCAL_CLUSTER_SCRIPT) deploy --type $(CLUSTER_TYPE) |
| 57 | + |
| 58 | +local-start: |
| 59 | + @$(LOCAL_CLUSTER_SCRIPT) start --type $(CLUSTER_TYPE) |
| 60 | + |
| 61 | +local-stop: |
| 62 | + @$(LOCAL_CLUSTER_SCRIPT) stop --type $(CLUSTER_TYPE) |
| 63 | + |
| 64 | +local-delete: |
| 65 | + @$(LOCAL_CLUSTER_SCRIPT) delete --type $(CLUSTER_TYPE) |
| 66 | + |
| 67 | +local-status: |
| 68 | + @$(LOCAL_CLUSTER_SCRIPT) status --type $(CLUSTER_TYPE) |
| 69 | + |
| 70 | +test-local: |
| 71 | + @$(LOCAL_CLUSTER_SCRIPT) start --type $(CLUSTER_TYPE) |
| 72 | + @$(LOCAL_CLUSTER_SCRIPT) context --type $(CLUSTER_TYPE) |
| 73 | + @$(MAKE) integration |
43 | 74 |
|
44 | 75 | lint: |
45 | | - @echo "Running linting and code quality checks..." |
46 | 76 | @if [ ! -f .git/hooks/pre-commit ]; then \ |
47 | 77 | echo "Installing pre-commit..."; \ |
48 | 78 | uv pip install pre-commit yamllint shellcheck-py || pip3 install --user pre-commit yamllint shellcheck-py; \ |
49 | 79 | pre-commit install; \ |
50 | 80 | fi |
51 | 81 | @pre-commit run --all-files |
52 | 82 |
|
53 | | -validate-schema: |
54 | | - @echo "Validating Helm values schemas..." |
55 | | - @command -v helm >/dev/null 2>&1 || { echo "❌ helm is required but not installed"; exit 1; } |
56 | | - @command -v ajv >/dev/null 2>&1 || { echo "❌ ajv-cli is required but not installed. Run: npm install -g ajv-cli ajv-formats"; exit 1; } |
| 83 | +validate: |
| 84 | + @command -v helm >/dev/null 2>&1 || { echo "❌ helm required but not installed"; exit 1; } |
| 85 | + @command -v ajv >/dev/null 2>&1 || { echo "❌ ajv-cli required. Run: npm install -g ajv-cli ajv-formats"; exit 1; } |
57 | 86 | @for chart_dir in charts/*/; do \ |
58 | 87 | chart_name=$$(basename "$$chart_dir"); \ |
59 | 88 | if [ -f "$${chart_dir}values.schema.json" ]; then \ |
60 | | - echo "🔍 Validating schema for $$chart_name..."; \ |
61 | | - if helm lint "$$chart_dir" --strict && \ |
62 | | - helm template test "$$chart_dir" >/dev/null && \ |
63 | | - ajv compile -s "$${chart_dir}values.schema.json" --spec=draft7 --strict=false && \ |
64 | | - python3 -c "import yaml,json; json.dump(yaml.safe_load(open('$${chart_dir}values.yaml')), open('/tmp/values-$${chart_name}.json','w'))" && \ |
65 | | - ajv validate -s "$${chart_dir}values.schema.json" -d "/tmp/values-$${chart_name}.json" --spec=draft7; then \ |
66 | | - rm -f "/tmp/values-$${chart_name}.json"; \ |
67 | | - echo "✅ $$chart_name validation passed"; \ |
68 | | - else \ |
| 89 | + echo "🔍 Validating $$chart_name..."; \ |
| 90 | + helm lint "$$chart_dir" --strict && \ |
| 91 | + helm template test "$$chart_dir" >/dev/null && \ |
| 92 | + ajv compile -s "$${chart_dir}values.schema.json" --spec=draft7 --strict=false && \ |
| 93 | + python3 -c "import yaml,json; json.dump(yaml.safe_load(open('$${chart_dir}values.yaml')), open('/tmp/values-$${chart_name}.json','w'))" && \ |
| 94 | + ajv validate -s "$${chart_dir}values.schema.json" -d "/tmp/values-$${chart_name}.json" --spec=draft7 && \ |
| 95 | + rm -f "/tmp/values-$${chart_name}.json" && \ |
| 96 | + echo "✅ $$chart_name validation passed" || { \ |
69 | 97 | rm -f "/tmp/values-$${chart_name}.json"; \ |
70 | 98 | echo "❌ $$chart_name validation failed"; \ |
71 | 99 | exit 1; \ |
72 | | - fi; \ |
| 100 | + }; \ |
73 | 101 | else \ |
74 | 102 | echo "⚠️ $$chart_name: no values.schema.json found, skipping"; \ |
75 | 103 | fi; \ |
76 | 104 | done |
77 | 105 |
|
78 | | -help: |
79 | | - @echo "Makefile commands:" |
80 | | - @echo " make deploy - Deploy eoAPI to the configured Kubernetes cluster." |
81 | | - @echo " make minikube - Install eoAPI on minikube." |
82 | | - @echo " make ingest - Ingest STAC collections and items into the database." |
83 | | - @echo " make integration - Run integration tests on connected Kubernetes cluster." |
84 | | - @echo " make tests - Run unit tests." |
85 | | - @echo " make lint - Run linting and code quality checks." |
86 | | - @echo " make validate-schema - Validate Helm values schemas." |
87 | | - @echo " make help - Show this help message." |
| 106 | +ingest: |
| 107 | + @./scripts/ingest.sh |
0 commit comments