-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathMakefile
129 lines (105 loc) · 4.47 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
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
GINKGO = go run github.com/onsi/ginkgo/v2/ginkgo
# Common ginkgo options: -v for verbose mode, --focus="test name" for running single tests
GFLAGS ?= --race --randomize-all --randomize-suites
BIN = $(PWD)/bin
FINCH_DAEMON_PROJECT_ROOT ?= $(shell pwd)
# Base path used to install.
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
BINARY = $(addprefix bin/,finch-daemon)
PACKAGE := github.com/runfinch/finch-daemon
VERSION := $(shell git describe --match 'v[0-9]*' --dirty='.modified' --always --tags)
GITCOMMIT := $(shell git rev-parse HEAD)$(shell if ! git diff --no-ext-diff --quiet --exit-code; then echo .m; fi)
ifndef GODEBUG
EXTRA_LDFLAGS += -s -w
endif
LDFLAGS_BASE := -X $(PACKAGE)/version.Version=$(VERSION) -X $(PACKAGE)/version.GitCommit=$(GITCOMMIT) $(EXTRA_LDFLAGS)
.PHONY: build
build:
ifeq ($(STATIC),)
@echo "Building Dynamic Binary"
CGO_ENABLED=1 GOOS=linux go build \
-ldflags "$(LDFLAGS_BASE)" \
-v -o $(BINARY) $(PACKAGE)/cmd/finch-daemon
else
@echo "Building Static Binary"
CGO_ENABLED=0 GOOS=linux go build \
-tags netgo \
-ldflags "$(LDFLAGS_BASE) -extldflags '-static'" \
-v -o $(BINARY) $(PACKAGE)/cmd/finch-daemon
endif
clean:
@rm -f $(BINARIES)
@rm -rf $(BIN)
.PHONY: linux
linux:
ifneq ($(shell uname), Linux)
$(error This needs to be run on linux!)
endif
.PHONY: start
start: linux build unlink
sudo $(BINARY) --debug --socket-owner $${UID}
DLV=$(BIN)/dlv
$(DLV):
GOBIN=$(BIN) go install github.com/go-delve/delve/cmd/dlv@latest
.PHONY: start-debug
start-debug: linux build $(DLV) unlink
sudo $(DLV) --listen=:2345 --headless=true --api-version=2 exec $(BINARY) -- --debug --socket-owner $${UID}
install: linux
install -d $(DESTDIR)$(BINDIR)
install $(BINARY) $(DESTDIR)$(BINDIR)
uninstall:
@rm -f $(addprefix $(DESTDIR)$(BINDIR)/,$(notdir $(BINARY)))
# Unlink the unix socket if the link does not get cleaned up properly (or if finch-daemon is already running)
.PHONY: unlink
unlink: linux
ifneq ("$(wildcard /run/finch.sock)","")
sudo unlink /run/finch.sock
endif
.PHONY: gen-code
gen-code: linux
rm -rf ./pkg/mocks
GOBIN=$(BIN) go install github.com/golang/mock/mockgen
GOBIN=$(BIN) go install golang.org/x/tools/cmd/stringer
PATH=$(BIN):$(PATH) go generate ./...
PATH=$(BIN):$(PATH) mockgen --destination=./mocks/mocks_container/container.go -package=mocks_container github.com/containerd/containerd Container
PATH=$(BIN):$(PATH) mockgen --destination=./mocks/mocks_container/process.go -package=mocks_container github.com/containerd/containerd Process
PATH=$(BIN):$(PATH) mockgen --destination=./mocks/mocks_container/task.go -package=mocks_container github.com/containerd/containerd Task
PATH=$(BIN):$(PATH) mockgen --destination=./mocks/mocks_image/store.go -package=mocks_image github.com/containerd/containerd/images Store
PATH=$(BIN):$(PATH) mockgen --destination=./mocks/mocks_container/network_manager.go -package=mocks_container github.com/containerd/nerdctl/pkg/containerutil NetworkOptionsManager
PATH=$(BIN):$(PATH) mockgen --destination=./mocks/mocks_cio/io.go -package=mocks_cio github.com/containerd/containerd/cio IO
PATH=$(BIN):$(PATH) mockgen --destination=./mocks/mocks_http/response_writer.go -package=mocks_http net/http ResponseWriter
PATH=$(BIN):$(PATH) mockgen --destination=./mocks/mocks_http/conn.go -package=mocks_http net Conn
GOLINT=$(BIN)/golangci-lint
$(GOLINT): linux
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(BIN) v1.60.3
.PHONY: lint
lint: linux $(GOLINT)
$(GOLINT) run ./...
.PHONY: test-unit
test-unit: linux
$(GINKGO) $(GFLAGS) ./...
# Runs tests in headless dlv mode, must specify package directory with PKG_DIR
PKG_DIR ?= .
.PHONY: test-unit-debug
test-unit-debug: linux $(DLV)
sudo $(DLV) --listen=:2345 --headless=true --api-version=2 test $(PKG_DIR)
.PHONY: test-e2e
test-e2e: linux
DOCKER_HOST="unix:///run/finch.sock" \
DOCKER_API_VERSION="v1.41" \
TEST_E2E=1 \
$(GINKGO) $(GFLAGS) ./e2e/...
.PHONY: licenses
licenses:
PATH=$(BIN):$(PATH) go-licenses report --template="scripts/third-party-license.tpl" --ignore github.com/runfinch ./... > THIRD_PARTY_LICENSES
.PHONY: coverage
coverage: linux
$(GINKGO) -r -v -race --trace --cover --coverprofile="coverage-report.out" ./...
go tool cover -html="coverage-report.out" -o="unit-test-coverage-report.html"
.PHONY: release
release: linux
@echo "$@"
@$(FINCH_DAEMON_PROJECT_ROOT)/scripts/create-releases.sh $(RELEASE_TAG)