1
0
Fork 0
home-stack-kustomize/Makefile

50 lines
1.3 KiB
Makefile

KUSTOMIZE = docker run -v $(HOME)/.aws:/root/.aws:ro -v $(PWD):/host:ro -w /host badjware/kustomize-plugins:latest
KUSTOMIZEFLAGS = --enable_alpha_plugins
KUBECTL = kubectl
KUBECTLFLAGS =
KUBECTLDIFFFLAGS =
KUBECTLAPPLYFLAGS = -l managed-by=kustomize --prune
SRC := $(shell find kustomize/ -type f)
OUTDIR = build
# all environments
KUSTOMIZEDIRALL = kustomize/environment/all
KUSTOMIZEOUTALL = $(OUTDIR)/all/manifest.yaml
ifeq ($(environment),prod)
# prod
KUSTOMIZEDIR = kustomize/environment/prod
KUSTOMIZEOUT = $(OUTDIR)/prod/manifest.yaml
else
# dev
environment = dev
KUBECTLFLAGS += --kubeconfig kubectl/kubeconfig.yaml
KUSTOMIZEDIR = kustomize/environment/dev
KUSTOMIZEOUT = $(OUTDIR)/dev/manifest.yaml
endif
.PHONY: info clean diff apply
all: info $(KUSTOMIZEOUT)
info:
@echo "Building for" $(environment)
clean:
rm -r $(OUTDIR)
$(KUSTOMIZEOUT): $(SRC)
@mkdir -p $(dir $(KUSTOMIZEOUTALL))
@mkdir -p $(dir $(KUSTOMIZEOUT))
$(KUSTOMIZE) build $(KUSTOMIZEFLAGS) $(KUSTOMIZEDIRALL) >$(KUSTOMIZEOUTALL) || (rm $(KUSTOMIZEOUTALL); exit 1)
$(KUSTOMIZE) build $(KUSTOMIZEFLAGS) $(KUSTOMIZEDIR) >$(KUSTOMIZEOUT) || (rm $(KUSTOMIZEOUT); exit 1)
diff: $(KUSTOMIZEOUT)
$(KUBECTL) $(KUBECTLFLAGS) diff $(KUBECTLDIFFFLAGS) -f $(KUSTOMIZEOUT)
apply: $(KUSTOMIZEOUT)
$(KUBECTL) $(KUBECTLFLAGS) apply $(KUBECTLAPPLYFLAGS) -f $(KUSTOMIZEOUT)