-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
122 lines (106 loc) · 5.02 KB
/
Makefile
File metadata and controls
122 lines (106 loc) · 5.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
.DEFAULT_GOAL := help
include app/.env
export REGISTRY_PRE=$(DOCKERHUB_USERNAME)/$(IMAGE_NAME)-dev
export REGISTRY_PRO=$(DOCKERHUB_USERNAME)/$(IMAGE_NAME)
export TAGS=$(shell curl -s "https://hub.docker.com/v2/repositories/${REGISTRY_PRE}/tags/" | jq -r '.results[].name'| grep -E 'rc[0-9]{2}' | tr '\n' ' ')
export LATEST_TAG := $(if $(TAGS),$(lastword $(sort $(TAGS))),00)
export LATEST_VERSION := $(shell echo "$(LATEST_TAG)" | sed -E 's/([0-9]+\.[0-9]+\.[0-9]+)-rc[0-9]{2}+/\1/')
export LATEST_RC := $(if $(filter-out 00,$(LATEST_TAG)),$(shell echo "$(LATEST_TAG)" | sed -E 's/^.*-rc([0-9]{2})$$/\1/'),00)
ifeq ($(IMAGE_VERSION),$(LATEST_VERSION))
NEXT_RC := $(shell sh -c 'if [ "$(LATEST_RC)" -eq "08" ]; then printf "%02d" 9; elif [ "$(LATEST_RC)" -eq "09" ]; then printf "%02d" 10; else printf "%02d" $$(($(LATEST_RC) + 1)); fi')
else
NEXT_RC := 00
endif
export NEXT_RC
export GH_TAG := $(shell git fetch --tags && git tag --sort=-creatordate | head -n 1)
.PHONY: help
help: ## Show this help.
@grep -E '^\S+:.*?## .*$$' $(firstword $(MAKEFILE_LIST)) | \
awk 'BEGIN {FS = ":.*?## "}; {printf "%-30s %s\n", $$1, $$2}'
.PHONY: todo
todo: ## Show the TODOs in the code.
@{ grep -n -w TODO Makefile | uniq || echo "No pending tasks"; } | sed '/grep/d'
.PHONY: show-env
show-env: ## Show the environment variables.
@echo "Showing the environment variables."
@echo "REGISTRY_PRE: $(REGISTRY_PRE)"
@echo "REGISTRY_PRO: $(REGISTRY_PRO)"
@echo "TAGS: $(TAGS)"
@echo "LATEST_TAG: $(LATEST_TAG)"
@echo "IMAGE_VERSION: $(IMAGE_VERSION)"
@echo "LATEST_VERSION: $(LATEST_VERSION)"
@echo "LATEST_RC: $(LATEST_RC)"
@echo "NEXT_RC: $(NEXT_RC)"
@echo "GH_TAG: $(GH_TAG)"
.PHONY: set-up
set-up: ## Prepare the environment for debugging.
@echo "Preparing $(IMAGE_NAME) for debugging."
@./scripts/create-requirements.sh
.PHONY: clean
clean: ## Clean the app.
@echo "Cleaning $(IMAGE_NAME) docker image."
docker-compose -f ./app/docker-compose.yml down --rmi all --volumes
.PHONY: build
build: ## Build the app.
@echo "Building $(IMAGE_NAME) docker image as $(IMAGE_NAME):$(IMAGE_VERSION)."
docker build -t $(REGISTRY_PRE):$(IMAGE_VERSION) ./app
.PHONY: run
run: pre-commit ## Start the app in development mode.
@echo "Starting $(IMAGE_NAME) in development mode."
docker-compose -f ./app/docker-compose.yml up --build $(IMAGE_NAME)
# TODO: Implement tests
.PHONY: test
test: ## Run the unit, integration and acceptance tests.
@echo "Running the unit, integration and acceptance tests."
docker-compose -f ./app/docker-compose.yml run --rm $(IMAGE_NAME) pytest -n 4 /workspace/app/tests -ra
.PHONY: pre-commit
pre-commit: ## Run the pre-commit checks.
@echo "Running the pre-commit checks."
$(MAKE) reformat
$(MAKE) check-typing
$(MAKE) check-style
.PHONY: check-typing
check-typing: ## Check the typing.
@echo "Checking the typing."
docker-compose -f ./app/docker-compose.yml run --rm $(IMAGE_NAME) mypy .
.PHONY: check-style
check-style: ## Check the styling.
@echo "Checking the styling."
docker-compose -f ./app/docker-compose.yml run --rm $(IMAGE_NAME) ruff check .
.PHONY: reformat
reformat: ## Reformat the code.
@echo "Reformatting the code."
docker-compose -f ./app/docker-compose.yml run --rm $(IMAGE_NAME) ruff format .
.PHONY: publish-image-pre
publish-image-pre: build ## Push the release candidate to the registry.
@echo "Publishing the image as release candidate - $(REGISTRY_PRE):$(IMAGE_VERSION)-rc$(NEXT_RC)"
@docker tag $(REGISTRY_PRE):$(IMAGE_VERSION) $(REGISTRY_PRE):$(IMAGE_VERSION)-rc$(NEXT_RC)
@docker tag $(REGISTRY_PRE):$(IMAGE_VERSION) $(REGISTRY_PRE):latest
@docker push $(REGISTRY_PRE):$(IMAGE_VERSION)-rc$(NEXT_RC)
@docker push $(REGISTRY_PRE):latest
## export REGISTRY_PRE=zuidui/api-gateway-dev
## export IMAGE_VERSION=0.0.3
## echo $(REGISTRY_PRE)
## echo $(IMAGE_VERSION)
## echo $(NEXT_RC)
## envsubst < chart/api-gateway-rollout/values_template.yaml > chart/api-gateway-rollout/values.yaml
## cat chart/api-gateway-rollout/values_template.yaml
## cat chart/api-gateway-rollout/values.yaml
## helm package chart/api-gateway-rollout
## helm upgrade api-gateway-rollout ./chart/api-gateway-rollout-0.1.0.tgz
.PHONY: publish-image-pro
publish-image-pro: ## Publish the latest release to the registry.
@echo "Publishing the latest image in the registry - $(REGISTRY_PRO):$(LATEST_VERSION)"
@docker pull $(REGISTRY_PRE):$(LATEST_TAG)
@docker tag $(REGISTRY_PRE):$(LATEST_TAG) $(REGISTRY_PRO):latest
@docker tag $(REGISTRY_PRE):$(LATEST_TAG) $(REGISTRY_PRO):$(LATEST_VERSION)
@docker push $(REGISTRY_PRO):$(LATEST_VERSION)
@docker push $(REGISTRY_PRO):latest
@if [ "$(GH_TAG)" = "$(IMAGE_VERSION)" ]; then \
git tag -d $(LATEST_VERSION); \
git push origin --delete $(LATEST_VERSION); \
gh release delete $(LATEST_VERSION) --yes; \
fi
@git tag -a $(LATEST_VERSION) -m "Release $(LATEST_VERSION)"
@git push --force origin $(LATEST_VERSION)
@gh release create $(LATEST_VERSION) -t $(LATEST_VERSION) -n $(LATEST_VERSION)