1
0
Fork 0
home-stack-kustomize/Makefile

78 lines
2.3 KiB
Makefile
Raw Normal View History

KUSTOMIZE = docker run -v $(HOME)/.aws:/root/.aws:ro -v $(PWD):/host -w /host badjware/kustomize-plugins:latest
2020-05-14 21:56:01 +00:00
KUSTOMIZEFLAGS = --enable_alpha_plugins
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
2021-08-26 16:42:21 +00:00
DEVOUT = $(OUTDIR)/dev
DEVMANIFESTSRC = kustomize/overlays/dev
DEVMANIFESTOUT = $(DEVOUT)/manifest.yaml
DEVCLUSTERSRC = kustomize/overlays/dev-cluster
DEVCLUSTEROUT = $(DEVOUT)/cluster.yaml
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
2020-05-14 21:56:01 +00:00
ifeq ($(environment),prod)
2020-08-02 01:49:55 +00:00
environment = prod
2021-08-26 16:42:21 +00:00
ENVOUTDIR = $(PRODOUT)
2021-08-26 16:42:41 +00:00
ENVOUTFILE = $(PRODMANIFESTOUT) $(PRODCLUSTEROUT)
2020-05-14 21:56:01 +00:00
else
environment = dev
2020-08-02 01:49:55 +00:00
2021-08-26 16:42:21 +00:00
ENVOUTDIR = $(DEVOUT)
ENVOUTFILE = $(DEVMANIFESTOUT) $(DEVCLUSTERTOUT)
2020-05-14 21:56:01 +00:00
endif
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)
$(KUBECTL) $(KUBECTLFLAGS) apply -l managed-by=kustomize-cluster -f $(ENVOUTDIR)
$(KUBECTL) $(KUBECTLFLAGS) apply -l 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
dev: $(DEVMANIFESTOUT) $(DEVCLUSTEROUT)
prod: $(PRODMANIFESTOUT) $(PRODCLUSTEROUT)
2020-05-14 21:56:01 +00:00
2021-08-26 16:42:21 +00:00
$(DEVMANIFESTOUT): $(SRC)
mkdir -p $(DEVOUT)
$(KUSTOMIZE) build $(KUSTOMIZEFLAGS) $(DEVMANIFESTSRC) >$(DEVMANIFESTOUT) || (rm $(DEVMANIFESTOUT); exit 1)
2020-05-14 21:56:01 +00:00
2021-08-26 16:42:21 +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