Makefile 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. ROOT_DIR = $(shell pwd)
  2. NAMESPACE = "default"
  3. DEPLOY_NAME = "template-single"
  4. DOCKER_NAME = "template-single"
  5. # Install/Update to the latest CLI tool.
  6. .PHONY: cli
  7. cli:
  8. @set -e; \
  9. wget -O gf https://github.com/gogf/gf/releases/latest/download/gf_$(shell go env GOOS)_$(shell go env GOARCH) && \
  10. chmod +x gf && \
  11. ./gf install -y && \
  12. rm ./gf
  13. # Check and install CLI tool.
  14. .PHONY: cli.install
  15. cli.install:
  16. @set -e; \
  17. gf -v > /dev/null 2>&1 || if [[ "$?" -ne "0" ]]; then \
  18. echo "GoFame CLI is not installed, start proceeding auto installation..."; \
  19. make cli; \
  20. fi;
  21. # Generate Go files for DAO/DO/Entity.
  22. .PHONY: dao
  23. dao: cli.install
  24. @gf gen dao
  25. # Generate Go files for Service.
  26. .PHONY: service
  27. service: cli.install
  28. @gf gen service
  29. # Build image, deploy image and yaml to current kubectl environment and make port forward to local machine.
  30. .PHONY: start
  31. start:
  32. @set -e; \
  33. make image; \
  34. make deploy; \
  35. make port;
  36. # Build docker image.
  37. .PHONY: image
  38. image: cli.install
  39. $(eval _TAG = $(shell git log -1 --format="%cd.%h" --date=format:"%Y%m%d%H%M%S"))
  40. ifneq (, $(shell git status --porcelain 2>/dev/null))
  41. $(eval _TAG = $(_TAG).dirty)
  42. endif
  43. $(eval _TAG = $(if ${TAG}, ${TAG}, $(_TAG)))
  44. $(eval _PUSH = $(if ${PUSH}, ${PUSH}, ))
  45. @gf docker -p -b "-a amd64 -s linux -p temp" -t $(DOCKER_NAME):${_TAG};
  46. # Build docker image and automatically push to docker repo.
  47. .PHONY: image.push
  48. image.push:
  49. @make image PUSH=-p;
  50. # Deploy image and yaml to current kubectl environment.
  51. .PHONY: deploy
  52. deploy:
  53. $(eval _TAG = $(if ${TAG}, ${TAG}, develop))
  54. @set -e; \
  55. mkdir -p $(ROOT_DIR)/temp/kustomize;\
  56. cd $(ROOT_DIR)/manifest/deploy/kustomize/overlays/${_TAG};\
  57. kustomize build > $(ROOT_DIR)/temp/kustomize.yaml;\
  58. kubectl apply -f $(ROOT_DIR)/temp/kustomize.yaml; \
  59. kubectl patch -n $(NAMESPACE) deployment/$(DEPLOY_NAME) -p "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"date\":\"$(shell date +%s)\"}}}}}";