-
Notifications
You must be signed in to change notification settings - Fork 29
/
Makefile
146 lines (118 loc) · 4.73 KB
/
Makefile
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#
# Copyright 2022-2023 The KubeBlocks Authors
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
################################################################################
# Variables #
################################################################################
.SHELLFLAGS = -ec
VERSION ?= 0.1.0
CONFIG_PATH ?= ./images/example/mysql_snapshot_sample.yaml
MODULE_NAME ?= dt-main
GIT_BRANCH ?= main
export RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static
# To use buildx: https://github.com/docker/buildx#docker-ce
export DOCKER_CLI_EXPERIMENTAL=enabled
DOCKER:=DOCKER_BUILDKIT=1 docker
BUILDX_ENABLED ?= ""
ifeq ($(BUILDX_ENABLED), "")
ifeq ($(shell docker buildx inspect 2>/dev/null | awk '/Status/ { print $$2 }'), running)
BUILDX_ENABLED = true
else
BUILDX_ENABLED = false
endif
endif
BUILDX_BUILDER ?= x-builder
define BUILDX_ERROR
buildx not enabled, refusing to run this recipe
endef
APT_MIRROR ?= mirrors.aliyun.com
IMG ?= apecloud/ape-dts
IMG_TAG ?= latest
PLATFORMS ?= linux/arm64,linux/amd64
.DEFAULT_GOAL := help
##@ General
# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk commands is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php
# https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
# .PHONY: all
# all: ## Make all cmd binaries.
##@ Development
CARGO_BUILD_ARGS ?=
.PHONY: init
init: ## Build
git submodule update --init
.PHONY: build
build: ## Build
cargo build --release $(CARGO_BUILD_ARGS)
.PHONY: build-debug
build-debug: ## Build
cargo build $(CARGO_BUILD_ARGS)
.PHONY: build-release
build-release: ## Build release
cargo build --release $(CARGO_BUILD_ARGS)
.PHONE: clean
clean: ## Clean
cargo clean
.PHONE: lint
lint:
cargo clippy --workspace
.PHONY: test
test: CARGO_INCREMENTAL=0
test: RUSTFLAGS='-Cinstrument-coverage'
test: LLVM_PROFILE_FILE='cargo-test-%p-%m.profraw'
test: ## Run tests.
cargo test
.PHONY: test-cover
test-cover: grcov test ## Run tests with coverage report
grcov . --binary-path ./target/debug/deps/ -s . -t html --branch --ignore-not-existing --ignore '../*' --ignore "/*" -o target/coverage/html
##@ Container images
DOCKER_BUILD_ARGS ?=
.PHONY: install-docker-buildx
install-docker-buildx: ## Create `docker buildx` builder.
@if ! docker buildx inspect $(BUILDX_BUILDER) > /dev/null; then \
echo "Buildx builder $(BUILDX_BUILDER) does not exist, creating..."; \
docker buildx create --name=$(BUILDX_BUILDER) --use --driver=docker-container --platform linux/amd64,linux/arm64; \
else \
echo "Buildx builder $(BUILDX_BUILDER) already exists"; \
fi
.PHONY: docker-build
docker-build: DOCKER_BUILD_ARGS += --cache-to type=gha,mode=max --cache-from type=gha --build-arg MODULE_NAME=$(MODULE_NAME) --build-arg APT_MIRROR=$(APT_MIRROR) #--no-cache
docker-build: install-docker-buildx ## Build docker image.
ifneq ($(BUILDX_ENABLED), true)
$(DOCKER) build --tag $(IMG):$(IMG_TAG) $(DOCKER_BUILD_ARGS) .
else
$(DOCKER) buildx build --platform ${PLATFORMS} --tag $(IMG):$(IMG_TAG) $(DOCKER_BUILD_ARGS) .
endif
.PHONY: docker-push
docker-push: docker-build ## Push docker image.
ifneq ($(BUILDX_ENABLED), true)
$(DOCKER) push --tag $(IMG):$(IMG_TAG)
else
$(DOCKER) buildx build --platform ${PLATFORMS} --tag $(IMG):$(IMG_TAG) $(DOCKER_BUILD_ARGS) --push .
endif
##@ Tools
.PHONY: grcov
grcov: ## Download grcov locally if necessary.
ifeq (, $(shell ls $(which grcov) 2>/dev/null))
cargo install grcov
endif