1
0
Fork 0
home-stack-kustomize/Makefile

59 lines
1.6 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
ifeq ($(environment),prod)
environment = prod
# prod
KUSTOMIZEDIR = kustomize/overlays/prod
KUSTOMIZEOUT = $(OUTDIR)/$(environment)/manifest.yaml
# base-deploy
KUSTOMIZEDIRALL = kustomize/overlays/prod-base-deploy
KUSTOMIZEOUTALL = $(OUTDIR)/$(environment)/base-deploy.yaml
else
environment = dev
# dev
#KUBECTLFLAGS += --kubeconfig kubectl/kubeconfig.yaml
KUSTOMIZEDIR = kustomize/overlays/dev
KUSTOMIZEOUT = $(OUTDIR)/$(environment)/manifest.yaml
# base-deploy
KUSTOMIZEDIRALL = kustomize/overlays/dev-base-deploy
KUSTOMIZEOUTALL = $(OUTDIR)/$(environment)/base-deploy.yaml
endif
.PHONY: all info base-deploy clean diff apply
all: info base-deploy $(KUSTOMIZEOUT)
info:
@echo "Building for" $(environment)
clean:
rm -r $(OUTDIR)
base-deploy: $(SRC)
@mkdir -p $(dir $(KUSTOMIZEOUTALL))
$(KUSTOMIZE) build $(KUSTOMIZEFLAGS) $(KUSTOMIZEDIRALL) >$(KUSTOMIZEOUTALL) || (rm $(KUSTOMIZEOUTALL); exit 1)
$(KUSTOMIZEOUT): $(SRC)
@mkdir -p $(dir $(KUSTOMIZEOUT))
$(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)