You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
# detect operating system
ifeq ($(OS),Windows_NT) CURRENT_OS := Windows else CURRENT_OS := $(shell uname -s) endif
UNAME=$(shell uname -a) X86_64=$(findstring x86_64, $(UNAME))
#GOBIN
GOBIN = $(shell pwd)/build/bin GO ?= latest
# variables
NAME_DEV=develop NAME_MASTER=master
RD_SUFFIX=rd
BRANCH_DEV=$(NAME_DEV)-$(RD_SUFFIX) BRANCH_MASTER=$(NAME_MASTER)-$(RD_SUFFIX)
CURR_MODEL_NAME=$(notdir $(shell pwd)) GIT_BRANCH=$(shell git rev-parse --abbrev-ref HEAD) GIT_HASH=$(shell git rev-parse HEAD | cut -c 1-8) BUILD_FLAGS = -tags netgo -ldflags "-X git.pandaminer.com/ox/build.GitBranch=$(GIT_BRANCH)" ACR_PREFIX=registry.ap-southeast-1.aliyuncs.com/oxbtc-rd
K8S_NAMESPACE_PREFIX=halley
K8S_DEPLOY_PARAM_CURR_MODEL_NAME=$(CURR_MODEL_NAME) K8S_DEPLOY_PARAM_IMAGE_TAG=$(GIT_BRANCH)-$(GIT_HASH) K8S_DEPLOY_PARAM_RESOURCE_SUFFIX=$(GIT_BRANCH) K8S_DEPLOY_PARAM_ARC_PREFIX=$(ACR_PREFIX)
TMP_FILE_DEPLOY=.tmp.deploy.txt
#GIT_BRANCH=master-rd
## git分支和命名空间的对应s
## master-rd 分支,对应命名空间 halley-rd
## develop-rd 分支,对应命名空间 halley-dev-rd
ifeq ($(GIT_BRANCH),$(BRANCH_MASTER)) K8S_DEPLOY_PARAM_CURR_K8S_NAMESPACE=$(K8S_NAMESPACE_PREFIX)-$(RD_SUFFIX) else K8S_DEPLOY_PARAM_CURR_K8S_NAMESPACE=$(K8S_NAMESPACE_PREFIX)-dev-$(RD_SUFFIX) endif
MAKE_ENV += K8S_DEPLOY_PARAM_CURR_MODEL_NAME K8S_DEPLOY_PARAM_IMAGE_TAG K8S_DEPLOY_PARAM_RESOURCE_SUFFIX K8S_DEPLOY_PARAM_ARC_PREFIX K8S_DEPLOY_PARAM_CURR_K8S_NAMESPACE SHELL_EXPORT := $(foreach v,$(MAKE_ENV),$(v)='$($(v))' )
# GIT_BRANCH=11
all: build
# unittest:
# # @go test -v ./internal/...
gitReset: @echo ==gitReset== @git fetch --all; @git reset --hard origin/$(GIT_BRANCH);
buildquick: gitReset @echo ==buildquick== @go mod tidy; @echo GIT_BRANCH=$(GIT_BRANCH) GIT_HASH=$(GIT_HASH) K8S_DEPLOY_PARAM_IMAGE_TAG=$(K8S_DEPLOY_PARAM_IMAGE_TAG) @echo BUILD_FLAGS=$(BUILD_FLAGS) @go build $(BUILD_FLAGS) -o ./pack/service ./
docker: clean buildquick @echo ==build docker image and push == ## 非 x86_64平台,不允许做docker镜像的构建 @if [ "$(X86_64)" = "" ] ; then\
echo !!!! not x86_64 platform , can not build docker image !!!!!!!!; \
exit 11; \
fi
## 非 develop-rd、master-rd 分支,不允许做docker镜像构建 @echo ACR_PREFIX=$(ACR_PREFIX); @echo CURR_MODEL_NAME=$(CURR_MODEL_NAME); @echo GIT_BRANCH=$(GIT_BRANCH); @if [[ $(GIT_BRANCH) = $(BRANCH_DEV) || $(GIT_BRANCH) = $(BRANCH_MASTER) ]]; then\
docker build -t $(CURR_MODEL_NAME):$(K8S_DEPLOY_PARAM_IMAGE_TAG) -f pack/Dockerfile .;\
docker tag $(CURR_MODEL_NAME):$(K8S_DEPLOY_PARAM_IMAGE_TAG) $(ACR_PREFIX)/$(CURR_MODEL_NAME):$(K8S_DEPLOY_PARAM_IMAGE_TAG); \
docker push $(ACR_PREFIX)/$(CURR_MODEL_NAME):$(K8S_DEPLOY_PARAM_IMAGE_TAG); \
else \
echo !!!!! no docker building in branch $(GIT_BRANCH) !!!!!!; \
fi
deployK8s: docker @echo ==deploy to K8s== @echo $(SHELL_EXPORT);
@if [[ $(GIT_BRANCH) = $(BRANCH_DEV) || $(GIT_BRANCH) = $(BRANCH_MASTER) ]]; then\
$(SHELL_EXPORT) envsubst < deployK8s.yaml > $(TMP_FILE_DEPLOY) ; kubectl apply -f $(TMP_FILE_DEPLOY) ; \
kubectl replace -f $(TMP_FILE_DEPLOY) --force; \
else \
echo !!!!! no docker building in branch $(GIT_BRANCH) !!!!!!; \
fi
build: buildquick
clean: rm -rf ./build ./pack/service
.PHONY: build
|