1
0
Fork 0
home-stack-kustomize/Makefile

82 lines
2.5 KiB
Makefile
Raw Normal View History

2022-09-13 14:37:49 +00:00
KUSTOMIZE = KUSTOMIZE_PLUGIN_HOME=$(PWD)/plugins kustomize
KUSTOMIZEFLAGS = --enable-alpha-plugins
2020-05-14 21:56:01 +00:00
KUBECTL = kubectl
KUBECTLFLAGS =
2020-05-17 02:17:14 +00:00
KUBECTLDIFFFLAGS =
2021-08-26 16:42:21 +00:00
KUBECTLAPPLYFLAGS = --prune
2020-05-14 21:56:01 +00:00
SRC := $(shell find kustomize/ -type f)
2020-05-16 02:19:37 +00:00
OUTDIR = build
2020-05-14 21:56:01 +00:00
2022-09-13 14:37:49 +00:00
# DEVOUT = $(OUTDIR)/dev
# DEVMANIFESTSRC = kustomize/overlays/dev
# DEVMANIFESTOUT = $(DEVOUT)/manifest.yaml
# DEVCLUSTERSRC = kustomize/overlays/dev-cluster
# DEVCLUSTEROUT = $(DEVOUT)/cluster.yaml
2021-08-26 16:42:21 +00:00
PRODOUT = $(OUTDIR)/prod
PRODMANIFESTOUT = $(PRODOUT)/manifest.yaml
PRODMANIFESTSRC = kustomize/overlays/prod
2021-08-26 16:42:41 +00:00
PRODCLUSTEROUT = $(PRODOUT)/cluster.yaml
PRODCLUSTERSRC = kustomize/overlays/prod-cluster
2020-05-18 20:18:39 +00:00
2022-09-13 14:37:49 +00:00
# ifeq ($(environment),prod)
# environment = prod
2020-08-02 01:49:55 +00:00
2022-09-13 14:37:49 +00:00
# ENVOUTDIR = $(PRODOUT)
# ENVOUTFILE = $(PRODMANIFESTOUT) $(PRODCLUSTEROUT)
# else
# environment = dev
2020-08-02 01:49:55 +00:00
2022-09-13 14:37:49 +00:00
# ENVOUTDIR = $(DEVOUT)
# ENVOUTFILE = $(DEVMANIFESTOUT) $(DEVCLUSTERTOUT)
# endif
environment=prod
ENVOUTDIR = $(PRODOUT)
ENVOUTFILE = $(PRODMANIFESTOUT) $(PRODCLUSTEROUT)
2020-05-14 21:56:01 +00:00
2021-08-26 16:42:21 +00:00
.PHONY: diff
diff: $(environment)
$(KUBECTL) $(KUBECTLFLAGS) diff $(KUBECTLDIFFFLAGS) -f $(ENVOUTDIR) | highlight --out-format xterm256 --syntax diff
2020-05-14 21:56:01 +00:00
2021-08-26 16:42:21 +00:00
.PHONY: apply
apply: $(environment)
2023-02-05 03:11:39 +00:00
$(KUBECTL) $(KUBECTLFLAGS) apply $(KUBECTLAPPLYFLAGS) -l app.kubernetes.io/managed-by=kustomize-cluster -f $(ENVOUTDIR)
$(KUBECTL) $(KUBECTLFLAGS) apply $(KUBECTLAPPLYFLAGS) -l app.kubernetes.io/managed-by=kustomize -f $(ENVOUTDIR)
2020-05-14 21:56:01 +00:00
2021-08-26 16:42:21 +00:00
.PHONY: all dev prod
all: dev prod
2022-09-13 14:37:49 +00:00
# dev: $(DEVMANIFESTOUT) $(DEVCLUSTEROUT)
2021-08-26 16:42:21 +00:00
prod: $(PRODMANIFESTOUT) $(PRODCLUSTEROUT)
2020-05-14 21:56:01 +00:00
2022-09-13 14:37:49 +00:00
# $(DEVMANIFESTOUT): $(SRC)
# mkdir -p $(DEVOUT)
# $(KUSTOMIZE) build $(KUSTOMIZEFLAGS) $(DEVMANIFESTSRC) >$(DEVMANIFESTOUT) || (rm $(DEVMANIFESTOUT); exit 1)
2020-05-14 21:56:01 +00:00
2022-09-13 14:37:49 +00:00
# $(DEVCLUSTEROUT): $(SRC)
# mkdir -p $(DEVOUT)
# $(KUSTOMIZE) build $(KUSTOMIZEFLAGS) $(DEVCLUSTERSRC) >$(DEVCLUSTEROUT) || (rm $(DEVCLUSTEROUT); exit 1)
2021-08-26 16:42:21 +00:00
$(PRODMANIFESTOUT): $(SRC)
mkdir -p $(PRODOUT)
$(KUSTOMIZE) build $(KUSTOMIZEFLAGS) $(PRODMANIFESTSRC) >$(PRODMANIFESTOUT) || (rm $(PRODMANIFESTOUT); exit 1)
$(PRODCLUSTEROUT): $(SRC)
mkdir -p $(PRODOUT)
$(KUSTOMIZE) build $(KUSTOMIZEFLAGS) $(PRODCLUSTERSRC) >$(PRODCLUSTEROUT) || (rm $(PRODCLUSTEROUT); exit 1)
.PHONY: clean
clean:
rm -r $(OUTDIR)
2020-08-02 01:49:55 +00:00
2021-08-26 16:42:21 +00:00
# $(KUSTOMIZEOUTALL): $(SRC)
# @mkdir -p $(dir $(KUSTOMIZEOUTALL))
# $(KUSTOMIZE) build $(KUSTOMIZEFLAGS) $(KUSTOMIZEDIRALL) >$(KUSTOMIZEOUTALL) || (rm $(KUSTOMIZEOUTALL); exit 1)
2020-05-14 21:56:01 +00:00
2021-08-26 16:42:21 +00:00
# $(KUSTOMIZEOUT): $(SRC)
# @mkdir -p $(dir $(KUSTOMIZEOUT))
# $(KUSTOMIZE) build $(KUSTOMIZEFLAGS) $(KUSTOMIZEDIR) >$(KUSTOMIZEOUT) || (rm $(KUSTOMIZEOUT); exit 1)
2020-05-14 21:56:01 +00:00