Commit c6568fe4 by Chavee Issariyapat

update Makefile to 1.2.2

parent a7bab293
# a helper shell script
MAKE_VERSION=1.2.1
MAKE_VERSION=1.2.2
define MAKEFUNCTIONCODE
function hasChanges() {
......@@ -144,12 +144,25 @@ endif
ifeq (deploy,$(firstword $(MAKECMDGOALS)))
doit=true
endif
ifeq (show-deploy,$(firstword $(MAKECMDGOALS)))
doit=true
endif
ifeq (annotate,$(firstword $(MAKECMDGOALS)))
doit=true
endif
ifeq (rollback,$(firstword $(MAKECMDGOALS)))
doit=true
endif
ifdef doit
# use the rest as arguments for "make xxx"
#CMD_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
# ...and turn them into do-nothing targets
#$(eval $(CMD_ARGS):;@:)
ifdef n
DEPLOYARG= -n $(n) --context=$(c)
else
DEPLOYARG= -n nexpieio --context=$(c)
endif
endif
# ifeq ($(CMD_ARGS),)
......@@ -162,7 +175,7 @@ endif
.PHONY: pre-build docker-build post-build build release patch-release minor-release major-release tag check-status check-release showtag show-tag \
push do-push post-push post-init update-make rmi images deploy
push do-push post-push post-init update-make rmi images deploy show-deploy annotate rollback
init:
@echo "$$MAKEFUNCTIONCODE" > ./.make-function
......@@ -219,41 +232,6 @@ showtag: init release.conf
@. $(RELEASE_SUPPORT); getVersionWithHash
@rm .make-function
# tag-patch-release: init
# VERSION := $(shell . $(RELEASE_SUPPORT); nextPatchLevel)
# tag-patch-release: release.conf tag
# tag-minor-release: init
# VERSION := $(shell . $(RELEASE_SUPPORT); nextMinorLevel)
# tag-minor-release: release.conf tag
# tag-major-release: init
# VERSION := $(shell . $(RELEASE_SUPPORT); nextMajorLevel)
# tag-major-release: release.conf tag
# patch-release: tag-patch-release release
# @echo $(VERSION)
# minor-release: tag-minor-release release
# @echo $(VERSION)
# major-release: tag-major-release release
# @echo $(VERSION)
# tag:
# @echo "$$MAKEFUNCTIONCODE" > ./.make-function
# TAG=$(shell . $(RELEASE_SUPPORT); getTag $(VERSION))
# tag: check-status
# @echo "$$MAKEFUNCTIONCODE" > ./.make-function
# @. $(RELEASE_SUPPORT) ; ! tagExists $(TAG) || (echo "ERROR: tag $(TAG) for version $(VERSION) already tagged in git" >&2 && exit 1) ;
# @. $(RELEASE_SUPPORT) ; setRelease $(VERSION)
# git add .
# git commit -m "bumped to version $(VERSION)" ;
# git tag $(TAG) ;
# @ if [ -n "$(shell git remote -v)" ] ; then git push --tags ; else echo 'no remote to push tags to' ; fi
# @rm .make-function
check-status: init
@. $(RELEASE_SUPPORT) ; ! hasChanges || (echo "ERROR: there are still outstanding changes" >&2) ;
@rm .make-function
......@@ -286,6 +264,43 @@ env-snippet:
@rm nexpieconfig.yaml
@rm env-snippet-nexpieconfig.yaml
show-deploy: init release.conf
ifndef c
@echo Please run make show-deploy c={context}
else
kubectl rollout history deployment/$(DEPLOYMENT) $(DEPLOYARG)
endif
@rm .make-function
annotate: init release.conf
ifndef c
@echo Please run make show-deploy c={context} a="{annotation text}"
else ifndef a
@echo Please run make show-deploy c={context} a="{annotation text}"
else
kubectl annotate deployment/$(DEPLOYMENT) kubernetes.io/change-cause="$(a)" $(DEPLOYARG)
endif
@rm .make-function
rollback: init release.conf
ifndef r
@echo Please run make rollback r={revision} c={context}
else
kubectl rollout undo deployment/$(DEPLOYMENT) --to-revision=$(r) $(DEPLOYARG)
endif
@rm .make-function
deploy: init release.conf
@ cat k8s/deployment.yaml | sed "s/{{IMAGE_TAG}}/$(VERSIONHASH)/g" | kubectl apply -f - $(DEPLOYARG)
ifndef c
@echo Deploy failed : Please make deploy with c={context}
else
@cat k8s/deployment.yaml | sed "s/{{IMAGE_TAG}}/$(VERSIONHASH)/g" | kubectl apply -f - $(DEPLOYARG)
@rm .make-function
ifdef a
@kubectl annotate deployment/$(DEPLOYMENT) kubernetes.io/change-cause="$(a)" $(DEPLOYARG)
endif
endif
......@@ -138,22 +138,39 @@ $ make env-snippet
หากมีการสร้างไฟล์ deployment.yaml ไว้ในโฟลเดอร์ k8s
สามารถสั่ง deploy ขึ้น kubenetes cluster ได้ด้วยคำสั่ง
ในกรณีที่ใน yaml ไม่จำเป็นต้องระบุ namespace (เช่นใช้ default)
ในกรณีที่ต้องการระบุ namespace และ context
```
make deploy
make deploy n=<namespace> c=<context>
```
ในกรณีที่ต้องการระบุ namespace
เช่น
```
make deploy n=<namespace>
make deploy n=nexpie c=minikube
```
ในกรณีที่ต้องระบุ namespace และเลือก context
ถ้าไม่ได้พิมพ์ -n จะเซตเป็น nexpieio ให้เป็นค่าปกติ แต่ถ้าเซตก็จะใช้ค่าที่เซต ตัวอย่าง สองคำสั่งนี้เท่ากัน
```
make deploy n=<namespace> c=<context>
make deploymennt c=dev n=nexpieio
make deploymennt c=dev
```
เช่น
ตั้ง annotation ตอน make deploy ได้เลย ตามตัวอย่าง
```
make deploy n=nexpie c=minikube
make deploymennt c=dev a="add user api"
```
ดู deployment history ได้จากคำสั่ง
```
make show-deploy c=dev
```
เซต annotation ของ deploy ล่าสุดบน k8s ได้จากคำสั่งตามตัวอย่าง
```
make annotate c=dev a="add user api"
```
undo deployment ได้จากคำสั่งตามตัวอย่าง
```
make rollback c=dev r=24
```
tag ของ image จะอยู่ในรูปแบบนี้ 1.0.1-1-84f08685
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment