-
Notifications
You must be signed in to change notification settings - Fork 141
/
Makefile
113 lines (88 loc) · 3.68 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
DOCKER_IMAGE_NAME := traefik/mesh
UNAME := $(shell uname)
SRCS = $(shell git ls-files '*.go' | grep -v '^vendor/')
BINARY_NAME = traefik-mesh
DIST_DIR = $(CURDIR)/dist
DIST_DIR_TRAEFIK_MESH = $(DIST_DIR)/$(BINARY_NAME)
PROJECT ?= github.com/traefik/mesh
TAG_NAME ?= $(shell git tag -l --contains HEAD)
SHA := $(shell git rev-parse --short HEAD)
VERSION := $(if $(TAG_NAME),$(TAG_NAME),$(SHA))
BUILD_DATE := $(shell date -u '+%Y-%m-%d_%I:%M:%S%p')
INTEGRATION_TEST_OPTS := -test.timeout=20m -check.vv -v
export GO111MODULE=on
default: clean check test build
$(DIST_DIR):
mkdir -p $(DIST_DIR)
clean:
rm -rf $(CURDIR)/dist/ cover.out $(CURDIR)/pages $(CURDIR)/gh-pages.zip $(CURDIR)/mesh-gh-pages
# Static linting of source files. See .golangci.toml for options
local-check: $(DIST_DIR)
golangci-lint run --config .golangci.toml
# Local commands
local-build: $(DIST_DIR)
CGO_ENABLED=0 go build -o ${DIST_DIR_TRAEFIK_MESH} -ldflags="-s -w \
-X github.com/traefik/mesh/pkg/version.Version=$(VERSION) \
-X github.com/traefik/mesh/pkg/version.Commit=$(SHA) \
-X github.com/traefik/mesh/pkg/version.Date=$(BUILD_DATE)" \
$(CURDIR)/cmd/mesh/mesh.go
local-test: clean
go test -v -cover ./...
ifeq ($(UNAME), Linux)
test-integration: $(DIST_DIR) kubectl build k3d
else
test-integration: $(DIST_DIR) kubectl build local-build k3d
endif
CGO_ENABLED=0 go test ./integration -integration $(INTEGRATION_TEST_OPTS) $(TESTFLAGS)
test-integration-nobuild: $(DIST_DIR) kubectl k3d
CGO_ENABLED=0 go test ./integration -integration $(INTEGRATION_TEST_OPTS) $(TESTFLAGS)
kubectl:
@command -v kubectl >/dev/null 2>&1 || (curl -LO https://storage.googleapis.com/kubernetes-release/release/$(shell curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && chmod +x ./kubectl && sudo mv ./kubectl /usr/local/bin/kubectl)
build: $(DIST_DIR)
docker build --tag "$(DOCKER_IMAGE_NAME):latest" --build-arg="MAKE_TARGET=local-build" $(CURDIR)/
docker run --name=build -t "$(DOCKER_IMAGE_NAME):latest" version
docker cp build:/app/$(BINARY_NAME) $(DIST_DIR)/
docker rm build
test: $(DIST_DIR)
docker build --tag "$(DOCKER_IMAGE_NAME):test" --target maker --build-arg="MAKE_TARGET=local-test" $(CURDIR)/
check: $(DIST_DIR)
docker build --tag "$(DOCKER_IMAGE_NAME):check" --target base-image $(CURDIR)/
docker run --rm \
-v $(CURDIR):/go/src/$(PROJECT) \
-w /go/src/$(PROJECT) \
-e GO111MODULE \
"$(DOCKER_IMAGE_NAME):check" golangci-lint run --config .golangci.toml
publish-images: build
seihon publish -v "$(VERSION)" -v "latest" --image-name ${DOCKER_IMAGE_NAME} --dry-run=false --base-runtime-image=alpine:3.15
## Create packages for the release
release-packages: vendor build
rm -rf dist
docker build --tag "$(DOCKER_IMAGE_NAME):release-packages" --target base-image $(CURDIR)/
docker run --rm \
-v $(CURDIR):/go/src/$(PROJECT) \
-w /go/src/$(PROJECT) \
-e GITHUB_TOKEN \
"$(DOCKER_IMAGE_NAME):release-packages" goreleaser release --skip-publish
docker run --rm \
-v $(CURDIR):/go/src/$(PROJECT) \
-w /go/src/$(PROJECT) \
"$(DOCKER_IMAGE_NAME):release-packages" chown -R $(shell id -u):$(shell id -g) dist/
## Format the Code
fmt:
gofmt -s -l -w $(SRCS)
## Update vendor directory
vendor:
go mod vendor
upgrade:
go get -u
go mod tidy
tidy:
go mod tidy
k3d:
@command -v k3d >/dev/null 2>&1 || curl -s https://raw.githubusercontent.com/rancher/k3d/v3.4.0/install.sh | TAG=v3.4.0 bash
docs-package:
mkdir -p $(CURDIR)/pages
make -C $(CURDIR)/docs
cp -r $(CURDIR)/docs/site/* $(CURDIR)/pages/
.PHONY: local-check local-build local-test check build test publish-images \
vendor kubectl test-integration local-test-integration pages k3d