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:
Gonçalo Rodrigues 2026-06-20 16:34:08 +01:00
parent 0442f6cde7
commit 464bde2ee6
2 changed files with 60 additions and 57 deletions

View File

@ -3,7 +3,10 @@ SHELL := /bin/zsh
.DEFAULT_GOAL := help
K3D_SCRIPT := infrastructure/k3d/k3d.sh
TERRAFORM := terraform
TERRAFORM := terraform
# ── Cluster ───────────────────────────────────────────────────────────────────
.PHONY: up
up: ## Create the k3d dev cluster
$(K3D_SCRIPT) homelab
@ -12,48 +15,57 @@ up: ## Create the k3d dev cluster
down: ## Delete the k3d dev cluster
$(K3D_SCRIPT) homelab delete
# ── Infrastructure ────────────────────────────────────────────────────────────
.PHONY: infra
infra: ## Deploy shared infrastructure (MongoDB, monitoring, Traefik metrics)
infra: ## Deploy shared infrastructure (MongoDB, monitoring, Traefik)
$(TERRAFORM) -chdir=infrastructure/terraform/ apply
SERVICES := $(shell find apps -name Makefile -path "*/services/*" -exec dirname {} \;)
.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
# ── Services (Skaffold) ───────────────────────────────────────────────────────
.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
reset: down up infra deploy-all
reset: down bootstrap ## Tear down and rebuild everything from scratch
# ── Help ──────────────────────────────────────────────────────────────────────
.PHONY: help
help: ## Show this help

View File

@ -1,7 +1,6 @@
# Usage: include infrastructure/Makefile/service.mk
# SERVICE_NAME is inferred from the directory name by default.
# Optional: IMAGE_TAG, K8S_DIR, CLUSTER_NAME
# Auto-detects Go project (main/ dir) vs Node project (package.json)
SERVICE_NAME ?= $(notdir $(CURDIR))
SERVICE_DIR ?= .
@ -15,17 +14,16 @@ _rel_path := $(patsubst $(_abs_root)/%,%,$(CURDIR))
NAMESPACE ?= $(word 2,$(subst /, ,$(_rel_path)))
IMAGE_TAG ?= latest
REGISTRY ?= git.homelab.local/admin
IMAGE ?= $(REGISTRY)/$(SERVICE_NAME):$(IMAGE_TAG)
IMAGE ?= homelab/$(SERVICE_NAME):$(IMAGE_TAG)
CLUSTER_NAME ?= homelab
_is_node := $(shell [ -f $(SERVICE_DIR)/package.json ] && echo yes)
.PHONY: help
help: ## Show this help
@grep -hE '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | \
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
# ── Manual build/deploy (fallback when Skaffold is not available) ─────────────
.PHONY: build
build: ## Build the Docker image
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)
.PHONY: deploy
deploy: ## Apply k8s manifests to the cluster
@kubectl create namespace $(NAMESPACE) --dry-run=client -o yaml | kubectl apply -f -
kubectl apply -f $(K8S_DIR)/ -n $(NAMESPACE)
deploy: ## Apply k8s manifests
kubectl apply -f $(K8S_DIR)/
.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-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
# ── Skaffold ──────────────────────────────────────────────────────────────────
.PHONY: skaffold-dev
skaffold-dev: ## Run skaffold in dev mode (auto-sync, port-forward)
skaffold dev -f $(SERVICE_DIR)/skaffold.yaml
skaffold-dev: ## Watch this service — rebuild and redeploy on file change
skaffold dev -f $(SERVICE_DIR)/skaffold.yaml -p local
.PHONY: skaffold-run
skaffold-run: ## Run skaffold once (build + deploy)
skaffold run -f $(SERVICE_DIR)/skaffold.yaml
skaffold-run: ## Build and deploy this service once
skaffold run -f $(SERVICE_DIR)/skaffold.yaml -p local
.PHONY: skaffold-delete
skaffold-delete: ## Delete resources deployed by skaffold
skaffold-delete: ## Remove resources deployed by skaffold
skaffold delete -f $(SERVICE_DIR)/skaffold.yaml