This repository has been archived by the owner on Feb 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathMakefile
122 lines (98 loc) · 4.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
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
# Copyright (c) 2018 WSO2 Inc. (http:www.wso2.org) All Rights Reserved.
#
# WSO2 Inc. licenses this file to you 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.
PROJECT_ROOT := $(realpath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
PROJECT_PKG := cellery.io/cellery-controller
BUILD_DIRECTORY := build
BUILD_ROOT := $(PROJECT_ROOT)/$(BUILD_DIRECTORY)
GO_FILES = $(shell find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./pkg/generated/*")
GIT_REVISION := $(shell git rev-parse --verify HEAD)
MAIN_PACKAGES := controller webhook
BUILD_TARGETS := $(addprefix build., $(MAIN_PACKAGES))
TEST_TARGETS := $(addprefix test., $(MAIN_PACKAGES))
CONTROLLER_YAML_NAME := mesh-controller.yaml
VERSION ?= $(GIT_REVISION)
# Go build time flags
GO_LDFLAGS := -X $(PROJECT_PKG)/pkg/version.buildVersion=$(VERSION)
GO_LDFLAGS += -X $(PROJECT_PKG)/pkg/version.buildGitRevision=$(GIT_REVISION)
GO_LDFLAGS += -X $(PROJECT_PKG)/pkg/version.buildTime=$(shell date +%Y-%m-%dT%H:%M:%S%z)
DOCKER_TARGETS := $(addprefix docker., $(MAIN_PACKAGES))
DOCKER_PUSH_TARGETS := $(addprefix docker-push., $(MAIN_PACKAGES))
DOCKER_REPO ?= wso2cellery
DOCKER_IMAGE_PREFIX := mesh
DOCKER_IMAGE_TAG ?= $(VERSION)
all: build artifacts
.PHONY: $(BUILD_TARGETS)
$(BUILD_TARGETS):
$(eval TARGET=$(patsubst build.%,%,$@))
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o $(BUILD_ROOT)/$(TARGET) -ldflags "$(GO_LDFLAGS)" -x $(PROJECT_ROOT)/cmd/$(TARGET)
.PHONY: build
build: $(BUILD_TARGETS)
.PHONY: $(TEST_TARGETS)
$(TEST_TARGETS):
$(eval TARGET=$(patsubst test.%,%,$@))
true
# FIXME
# go test -race -covermode=atomic -coverprofile=$(PROJECT_ROOT)/coverage.txt ./pkg/$(TARGET)/...
.PHONY: test
test: $(TEST_TARGETS)
coverage: test
go tool cover -html=$(PROJECT_ROOT)/coverage.txt
.PHONY: $(DOCKER_TARGETS)
$(DOCKER_TARGETS): docker.% : build.%
$(eval TARGET=$(patsubst docker.%,%,$@))
docker build -f $(PROJECT_ROOT)/docker/$(TARGET)/Dockerfile $(BUILD_ROOT) -t $(DOCKER_REPO)/$(DOCKER_IMAGE_PREFIX)-$(TARGET):$(DOCKER_IMAGE_TAG)
docker tag $(DOCKER_REPO)/$(DOCKER_IMAGE_PREFIX)-$(TARGET):$(DOCKER_IMAGE_TAG) $(DOCKER_REPO)/$(DOCKER_IMAGE_PREFIX)-$(TARGET):latest
.PHONY: docker
docker: $(DOCKER_TARGETS)
.PHONY: $(DOCKER_PUSH_TARGETS)
$(DOCKER_PUSH_TARGETS): docker-push.% : docker.%
$(eval TARGET=$(patsubst docker-push.%,%,$@))
docker push $(DOCKER_REPO)/$(DOCKER_IMAGE_PREFIX)-$(TARGET):$(DOCKER_IMAGE_TAG)
docker push $(DOCKER_REPO)/$(DOCKER_IMAGE_PREFIX)-$(TARGET):latest
.PHONY: docker-push
docker-push: $(DOCKER_PUSH_TARGETS)
.PHONY: artifacts
artifacts:
@mkdir -p $(BUILD_ROOT)
@> $(BUILD_ROOT)/$(CONTROLLER_YAML_NAME)
@for yaml in $(PROJECT_ROOT)/artifacts/*.yaml; do \
cat $${yaml} >> $(BUILD_ROOT)/$(CONTROLLER_YAML_NAME); \
echo "---" >> ${BUILD_ROOT}/$(CONTROLLER_YAML_NAME); \
done
@sed -i.bak 's/$${CONTROLLER_IMAGE_TAG}/$(DOCKER_IMAGE_TAG)/g;s/$${DOCKER_REPO}/$(DOCKER_REPO)/g' ${BUILD_ROOT}/$(CONTROLLER_YAML_NAME)
@rm -f ${BUILD_ROOT}/$(CONTROLLER_YAML_NAME).bak
.PHONY: clean
clean:
@rm -rf $(BUILD_ROOT)
.PHONY: code.format
code.format: tools.goimports
@goimports -local $(PROJECT_PKG) -w -l $(GO_FILES)
.PHONY: code.format-check
code.format-check: tools.goimports
@goimports -local $(PROJECT_PKG) -l $(GO_FILES)
.PHONY: tools tools.goimports
tools: tools.goimports
tools.goimports:
@command -v goimports >/dev/null ; if [ $$? -ne 0 ]; then \
echo "goimports not found. Running 'go get golang.org/x/tools/cmd/goimports'"; \
GO111MODULE=off go get golang.org/x/tools/cmd/goimports; \
fi
.PHONY: vendor
vendor:
go mod vendor -v
.PHONY: verify-codegen
verify-codegen: vendor
$(PROJECT_ROOT)/hack/verify-codegen.sh