-
Notifications
You must be signed in to change notification settings - Fork 12
/
Makefile
81 lines (62 loc) · 2.08 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
# Project name (name of the executable)
BINARY_NAME := myduckserver
# Go source directory
SRC_DIR := .
# Go source files
SRC_FILES := $(wildcard $(SRC_DIR)/*.go)
# Version information
VERSION := $(shell git describe --tags --always --dirty)
BUILD_TIME := $(shell date +%Y-%m-%dT%H:%M:%S%z)
GIT_COMMIT := $(shell git rev-parse HEAD)
# Docker image information
IMAGE_NAME ?= myduck
IMAGE_TAG ?= latest
REGISTRY ?= apecloud
# Compilation flags
LDFLAGS := -X 'main.Version=$(VERSION)' -X 'main.BuildTime=$(BUILD_TIME)' -X 'main.GitCommit=$(GIT_COMMIT)'
# Build target
$(BINARY_NAME): $(SRC_FILES)
go build -ldflags "$(LDFLAGS)" -o $(BINARY_NAME) $(SRC_DIR)
# Default target
.PHONY: all build
all: build
build: $(BINARY_NAME)
# Clean target
.PHONY: clean
clean:
rm -f $(BINARY_NAME)
# Run target
.PHONY: run
run: build
./$(BINARY_NAME)
# Build and push for multiple architectures using Docker Buildx
.PHONY: push-image
docker buildx build --platform linux/amd64,linux/arm64 -t $(REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG) --push .
# Build image locally using Docker Buildx (for testing)
.PHONY: build-image-local
build-image-local:
docker buildx build -f docker/Dockerfile -t $(IMAGE_NAME):$(IMAGE_TAG) --load .
.PHONY: run-image
run-image:
docker run -d -p 3306:3306 -e MYSQL_CHARSET=utf8 $(IMAGE_NAME):$(IMAGE_TAG)
# Stop and remove the container
.PHONY: stop-image
stop-image:
docker stop $$(docker ps -q --filter ancestor=$(IMAGE_NAME):$(IMAGE_TAG)) || true
docker rm $$(docker ps -a -q --filter ancestor=$(IMAGE_NAME):$(IMAGE_TAG)) || true
# Remove the locally built image
.PHONY: clean-image
clean-image:
docker rmi $(IMAGE_NAME):$(IMAGE_TAG) || true
# Test target
.PHONY: test-full test cover
TEST_CMD = go test -cover -coverprofile cover.out
SHOW_TOTAL_COVERAGE = go tool cover -func=cover.out | grep total | awk '{print "Total Coverage: " $$3 " (run '\''make cover'\'' for details)"}'
test-full:
$(TEST_CMD) ./... | grep -v './transpiler'
@$(SHOW_TOTAL_COVERAGE)
test:
$(TEST_CMD) $(shell go list ./... | grep -v './binlogreplication')
@$(SHOW_TOTAL_COVERAGE)
cover:
go tool cover -html=cover.out