chore: update Makefiles for Skaffold-based workflow
Root Makefile: - Replace deploy-*/deploy-all/restart-all with skaffold dev/run - Add dev-<service> targets for per-service watch mode - Rename dev → skaffold dev (was: up+infra+deploy-all) - Rename to bootstrap for the full first-time setup - Add test-integration target service.mk: - Remove REGISTRY variable (image is now homelab/<svc>, no registry prefix) - Remove skaffold-gen (skaffold.yaml files are committed) - Update skaffold-dev/run to pass -p local - Keep build-deploy as a manual fallback Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
0442f6cde7
commit
464bde2ee6
84
Makefile
84
Makefile
@ -3,7 +3,10 @@ SHELL := /bin/zsh
|
|||||||
.DEFAULT_GOAL := help
|
.DEFAULT_GOAL := help
|
||||||
|
|
||||||
K3D_SCRIPT := infrastructure/k3d/k3d.sh
|
K3D_SCRIPT := infrastructure/k3d/k3d.sh
|
||||||
TERRAFORM := terraform
|
TERRAFORM := terraform
|
||||||
|
|
||||||
|
# ── Cluster ───────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
.PHONY: up
|
.PHONY: up
|
||||||
up: ## Create the k3d dev cluster
|
up: ## Create the k3d dev cluster
|
||||||
$(K3D_SCRIPT) homelab
|
$(K3D_SCRIPT) homelab
|
||||||
@ -12,48 +15,57 @@ up: ## Create the k3d dev cluster
|
|||||||
down: ## Delete the k3d dev cluster
|
down: ## Delete the k3d dev cluster
|
||||||
$(K3D_SCRIPT) homelab delete
|
$(K3D_SCRIPT) homelab delete
|
||||||
|
|
||||||
|
# ── Infrastructure ────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
.PHONY: infra
|
.PHONY: infra
|
||||||
infra: ## Deploy shared infrastructure (MongoDB, monitoring, Traefik metrics)
|
infra: ## Deploy shared infrastructure (MongoDB, monitoring, Traefik)
|
||||||
$(TERRAFORM) -chdir=infrastructure/terraform/ apply
|
$(TERRAFORM) -chdir=infrastructure/terraform/ apply
|
||||||
|
|
||||||
SERVICES := $(shell find apps -name Makefile -path "*/services/*" -exec dirname {} \;)
|
# ── Services (Skaffold) ───────────────────────────────────────────────────────
|
||||||
|
|
||||||
.PHONY: deploy-finance
|
|
||||||
deploy-finance: ## Build and deploy the finance API
|
|
||||||
$(MAKE) -C apps/finance/services/api build-deploy
|
|
||||||
|
|
||||||
.PHONY: deploy-auth-users
|
|
||||||
deploy-auth-users: ## Build and deploy the auth users service
|
|
||||||
$(MAKE) -C apps/auth/services/users build-deploy
|
|
||||||
|
|
||||||
.PHONY: deploy-auth-gateway
|
|
||||||
deploy-auth-gateway: ## Build and deploy the auth gateway service
|
|
||||||
$(MAKE) -C apps/auth/services/gateway build-deploy
|
|
||||||
|
|
||||||
.PHONY: test
|
|
||||||
test: ## Run all tests
|
|
||||||
go test ./...
|
|
||||||
|
|
||||||
.PHONY: deploy-all
|
|
||||||
deploy-all: ## Build, load, deploy, and restart every service
|
|
||||||
@for dir in $(SERVICES); do \
|
|
||||||
echo "\033[36m>>> $$dir\033[0m"; \
|
|
||||||
$(MAKE) -C "$$dir" build-deploy || true; \
|
|
||||||
done
|
|
||||||
|
|
||||||
.PHONY: restart-all
|
|
||||||
restart-all: ## Restart all deployments (pick up new images)
|
|
||||||
@for dir in $(SERVICES); do \
|
|
||||||
ns=$$(echo "$$dir" | awk -F/ '{print $$2}'); \
|
|
||||||
svc=$$(basename "$$dir"); \
|
|
||||||
kubectl rollout restart deployment "$$svc" -n "$$ns" 2>/dev/null || true; \
|
|
||||||
done
|
|
||||||
|
|
||||||
.PHONY: dev
|
.PHONY: dev
|
||||||
dev: up infra deploy-all ## Full cycle: cluster + infra + all services
|
dev: ## Watch all services — rebuild and redeploy on file change
|
||||||
|
skaffold dev
|
||||||
|
|
||||||
|
.PHONY: run
|
||||||
|
run: ## Build and deploy all services once
|
||||||
|
skaffold run
|
||||||
|
|
||||||
|
.PHONY: dev-finance
|
||||||
|
dev-finance: ## Watch finance API only
|
||||||
|
skaffold dev -f apps/finance/services/api/skaffold.yaml -p local
|
||||||
|
|
||||||
|
.PHONY: dev-gateway
|
||||||
|
dev-gateway: ## Watch auth gateway only
|
||||||
|
skaffold dev -f apps/auth/services/gateway/skaffold.yaml -p local
|
||||||
|
|
||||||
|
.PHONY: dev-users
|
||||||
|
dev-users: ## Watch auth users only
|
||||||
|
skaffold dev -f apps/auth/services/users/skaffold.yaml -p local
|
||||||
|
|
||||||
|
.PHONY: dev-example
|
||||||
|
dev-example: ## Watch test example-service only
|
||||||
|
skaffold dev -f apps/test/services/example-service/skaffold.yaml -p local
|
||||||
|
|
||||||
|
# ── Tests ─────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
.PHONY: test
|
||||||
|
test: ## Run all unit tests
|
||||||
|
go test ./...
|
||||||
|
|
||||||
|
.PHONY: test-integration
|
||||||
|
test-integration: ## Run integration tests (requires Docker for testcontainers)
|
||||||
|
go test -tags integration ./...
|
||||||
|
|
||||||
|
# ── Lifecycle ─────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
.PHONY: bootstrap
|
||||||
|
bootstrap: up infra run ## Full bootstrap: cluster + infra + all services
|
||||||
|
|
||||||
.PHONY: reset
|
.PHONY: reset
|
||||||
reset: down up infra deploy-all
|
reset: down bootstrap ## Tear down and rebuild everything from scratch
|
||||||
|
|
||||||
|
# ── Help ──────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
.PHONY: help
|
.PHONY: help
|
||||||
help: ## Show this help
|
help: ## Show this help
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
# Usage: include infrastructure/Makefile/service.mk
|
# Usage: include infrastructure/Makefile/service.mk
|
||||||
# SERVICE_NAME is inferred from the directory name by default.
|
# SERVICE_NAME is inferred from the directory name by default.
|
||||||
# Optional: IMAGE_TAG, K8S_DIR, CLUSTER_NAME
|
# Optional: IMAGE_TAG, K8S_DIR, CLUSTER_NAME
|
||||||
# Auto-detects Go project (main/ dir) vs Node project (package.json)
|
|
||||||
|
|
||||||
SERVICE_NAME ?= $(notdir $(CURDIR))
|
SERVICE_NAME ?= $(notdir $(CURDIR))
|
||||||
SERVICE_DIR ?= .
|
SERVICE_DIR ?= .
|
||||||
@ -15,17 +14,16 @@ _rel_path := $(patsubst $(_abs_root)/%,%,$(CURDIR))
|
|||||||
NAMESPACE ?= $(word 2,$(subst /, ,$(_rel_path)))
|
NAMESPACE ?= $(word 2,$(subst /, ,$(_rel_path)))
|
||||||
|
|
||||||
IMAGE_TAG ?= latest
|
IMAGE_TAG ?= latest
|
||||||
REGISTRY ?= git.homelab.local/admin
|
IMAGE ?= homelab/$(SERVICE_NAME):$(IMAGE_TAG)
|
||||||
IMAGE ?= $(REGISTRY)/$(SERVICE_NAME):$(IMAGE_TAG)
|
|
||||||
CLUSTER_NAME ?= homelab
|
CLUSTER_NAME ?= homelab
|
||||||
|
|
||||||
_is_node := $(shell [ -f $(SERVICE_DIR)/package.json ] && echo yes)
|
|
||||||
|
|
||||||
.PHONY: help
|
.PHONY: help
|
||||||
help: ## Show this help
|
help: ## Show this help
|
||||||
@grep -hE '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | \
|
@grep -hE '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | \
|
||||||
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
|
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
|
||||||
|
|
||||||
|
# ── Manual build/deploy (fallback when Skaffold is not available) ─────────────
|
||||||
|
|
||||||
.PHONY: build
|
.PHONY: build
|
||||||
build: ## Build the Docker image
|
build: ## Build the Docker image
|
||||||
docker build -t $(IMAGE) -f $(SERVICE_DIR)/Dockerfile $(PROJECT_ROOT)
|
docker build -t $(IMAGE) -f $(SERVICE_DIR)/Dockerfile $(PROJECT_ROOT)
|
||||||
@ -35,29 +33,22 @@ load: ## Load the image into the k3d cluster
|
|||||||
k3d image import $(IMAGE) -c $(CLUSTER_NAME)
|
k3d image import $(IMAGE) -c $(CLUSTER_NAME)
|
||||||
|
|
||||||
.PHONY: deploy
|
.PHONY: deploy
|
||||||
deploy: ## Apply k8s manifests to the cluster
|
deploy: ## Apply k8s manifests
|
||||||
@kubectl create namespace $(NAMESPACE) --dry-run=client -o yaml | kubectl apply -f -
|
kubectl apply -f $(K8S_DIR)/
|
||||||
kubectl apply -f $(K8S_DIR)/ -n $(NAMESPACE)
|
|
||||||
|
|
||||||
.PHONY: build-deploy
|
.PHONY: build-deploy
|
||||||
build-deploy: build load deploy ## Build, load, and deploy in one step
|
build-deploy: build load deploy ## Build, load into k3d, and deploy (manual fallback)
|
||||||
|
|
||||||
.PHONY: skaffold-gen
|
# ── Skaffold ──────────────────────────────────────────────────────────────────
|
||||||
skaffold-gen: ## Generate skaffold.yaml for the service
|
|
||||||
@echo "Generating $(SERVICE_DIR)/skaffold.yaml ..."
|
|
||||||
@ROOT="$$(cd "$(PROJECT_ROOT)" && pwd)"; \
|
|
||||||
SVC="$$(pwd)"; \
|
|
||||||
REL="$${SVC#$$ROOT/}"; \
|
|
||||||
printf 'apiVersion: skaffold/v4beta13\nkind: Config\nmetadata:\n name: %s\nbuild:\n artifacts:\n - image: homelab/%s\n context: %s\n docker:\n dockerfile: %s/Dockerfile\n local:\n push: false\nmanifests:\n rawYaml:\n - k8s/*.yaml\ndeploy:\n kubectl: {}\n' "$(SERVICE_NAME)" "$(SERVICE_NAME)" "$(PROJECT_ROOT)" "$$REL" > $(SERVICE_DIR)/skaffold.yaml
|
|
||||||
|
|
||||||
.PHONY: skaffold-dev
|
.PHONY: skaffold-dev
|
||||||
skaffold-dev: ## Run skaffold in dev mode (auto-sync, port-forward)
|
skaffold-dev: ## Watch this service — rebuild and redeploy on file change
|
||||||
skaffold dev -f $(SERVICE_DIR)/skaffold.yaml
|
skaffold dev -f $(SERVICE_DIR)/skaffold.yaml -p local
|
||||||
|
|
||||||
.PHONY: skaffold-run
|
.PHONY: skaffold-run
|
||||||
skaffold-run: ## Run skaffold once (build + deploy)
|
skaffold-run: ## Build and deploy this service once
|
||||||
skaffold run -f $(SERVICE_DIR)/skaffold.yaml
|
skaffold run -f $(SERVICE_DIR)/skaffold.yaml -p local
|
||||||
|
|
||||||
.PHONY: skaffold-delete
|
.PHONY: skaffold-delete
|
||||||
skaffold-delete: ## Delete resources deployed by skaffold
|
skaffold-delete: ## Remove resources deployed by skaffold
|
||||||
skaffold delete -f $(SERVICE_DIR)/skaffold.yaml
|
skaffold delete -f $(SERVICE_DIR)/skaffold.yaml
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user