-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
76 lines (58 loc) · 2.18 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
# We don't need make's built-in rules.
MAKEFLAGS += --no-builtin-rules
GO_FLAGS= CGO_ENABLED=0
GO_LDFLAGS= -ldflags=""
GO_BUILD_CMD=$(GO_FLAGS) go build $(GO_LDFLAGS)
BINARY_NAME=limes
BUILD_DIR=build
APP_VERSION=$(shell hack/version.sh)
.PHONY: docker
all: clean generate-all lint test build-all package-all
lint:
@echo "Linting code..."
@go vet ./...
test:
@echo "Running tests..."
@go test ./...
code-gen:
@echo "Generating code..."
@go generate ./...
generate-all: code-gen
pre-build:
@mkdir -p $(BUILD_DIR)
build-linux: pre-build
@echo "Building Linux binary..."
GOOS=linux GOARCH=amd64 $(GO_BUILD_CMD) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64
GOOS=linux GOARCH=arm64 $(GO_BUILD_CMD) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-arm64
build-osx: pre-build
@echo "Building OSX binary..."
GOOS=darwin GOARCH=amd64 $(GO_BUILD_CMD) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64
GOOS=darwin GOARCH=arm64 $(GO_BUILD_CMD) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-arm64
build build-all: build-linux build-osx
.PHONY: package-linux
package-linux:
@echo "Packaging Linux binary..."
tar -C $(BUILD_DIR) -zcf $(BUILD_DIR)/$(BINARY_NAME)-$(APP_VERSION)-linux-amd64.tar.gz $(BINARY_NAME)-linux-amd64
tar -C $(BUILD_DIR) -zcf $(BUILD_DIR)/$(BINARY_NAME)-$(APP_VERSION)-linux-arm64.tar.gz $(BINARY_NAME)-linux-arm64
.PHONY: package-osx
package-osx:
@echo "Packaging OSX binaries..."
tar -C $(BUILD_DIR) -zcf $(BUILD_DIR)/$(BINARY_NAME)-$(APP_VERSION)-darwin-amd64.tar.gz $(BINARY_NAME)-darwin-amd64
tar -C $(BUILD_DIR) -zcf $(BUILD_DIR)/$(BINARY_NAME)-$(APP_VERSION)-darwin-arm64.tar.gz $(BINARY_NAME)-darwin-arm64
.PHONY: package-all
package-all: package-linux package-osx
clean:
@echo "Cleaning..."
@rm -Rf $(BUILD_DIR)
docker:
# Build a new image (delete old one)
docker build --force-rm --build-arg GOPROXY -t $(BINARY_NAME) .
build-in-docker: docker
# Force-stop any containers with this name
docker rm -f $(BINARY_NAME) || true
# Create a new container with newly built image (but don't run it)
docker create --name $(BINARY_NAME) $(BINARY_NAME)
# Copy over the binary to disk (from container)
docker cp '$(BINARY_NAME):/opt/' $(BUILD_DIR)
# House-keeping: removing container
docker rm -f $(BINARY_NAME)