1
0
Fork 0
home-stack-kustomize/Makefile

43 lines
1.2 KiB
Makefile

KUSTOMIZE = kustomize
KUSTOMIZEFLAGS =
KUBECTL = kubectl
KUBECTLFLAGS =
KUBECTLDIFFFLAGS =
KUBECTLDIFFPRINTER = highlight --out-format xterm256 --syntax diff
KUBECTLAPPLYFLAGS = --server-side --force-conflicts
KUBECTLAPPLYPRUNEFLAGS = --server-side --force-conflicts --prune
KUBECTLAPPLYPRINTER = sed -E -e 's/(.+configured)/\o033[32m\1\o033[0m/g' -e 's/(.+pruned)/\o033[31m\1\o033[0m/g'
SRC := $(shell find kustomize/ -type f)
OUT = build
PRODOUT = $(OUT)/prod.yaml
PRODSRC = kustomize/env/prod
.PHONY: prod
prod: diff
.PHONY: diff
diff: $(PRODOUT)
$(KUBECTL) $(KUBECTLFLAGS) diff $(KUBECTLDIFFFLAGS) -f $(PRODOUT) | $(KUBECTLDIFFPRINTER)
.PHONY: apply
apply: $(PRODOUT)
$(KUBECTL) $(KUBECTLFLAGS) apply $(KUBECTLAPPLYFLAGS) -l app.kubernetes.io/managed-by=kustomize -f $(PRODOUT) | $(KUBECTLAPPLYPRINTER)
.PHONY: apply-prune
apply-prune: $(PRODOUT)
$(KUBECTL) $(KUBECTLFLAGS) apply $(KUBECTLAPPLYPRUNEFLAGS) -l app.kubernetes.io/managed-by=kustomize -f $(PRODOUT) | $(KUBECTLAPPLYPRINTER)
$(PRODOUT): $(SRC)
mkdir -p $(OUT)
$(KUSTOMIZE) build $(KUSTOMIZEFLAGS) $(PRODSRC) >$(PRODOUT) || (rm $(PRODOUT); exit 1)
.PHONY: clean
clean:
rm -r $(OUT)
.PHONY: infra
infra:
terraform -chdir=terraform apply