-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
116 lines (92 loc) · 4.36 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
# Copyright 2019 Shanghai JingDuo Information Technology co., Ltd.
#
# Licensed 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.
GO := go
GOFMT := gofmt
ARCH ?= $(shell go env GOARCH)
OS ?= $(shell go env GOOS)
.PHONY: all
IMAGE_REPOSITORY_URL = docker.io/kpaas
BUILD_NUMBER = $(shell git rev-parse --short HEAD)
BUILD_TAG := $(shell date +%Y%m%d%H%M%S)
ifneq ($(shell uname), Darwin)
EXTLDFLAGS = -extldflags "-static" $(null)
else
EXTLDFLAGS =
endif
all: build test
build: build_service_cross_without_doc build_deploy_cross_without_protos
.PHONY: service_doc
SED_PATH := $(shell which sed)
service_doc:
# swaggo need larger than 1.6
swag init -g run/service/main.go -o pkg/service/swaggerdocs
if strings $(SED_PATH) | grep -q 'GNU'; then \
$(SED_PATH) -i '/^\/\/ This file was generated by swaggo\/swag at/{n;d;}' pkg/service/swaggerdocs/docs.go; \
$(SED_PATH) -i '/^\/\/ This file was generated by swaggo\/swag at/d' pkg/service/swaggerdocs/docs.go; \
else \
$(SED_PATH) -i '' '/^\/\/ This file was generated by swaggo\/swag at/{n;d;}' pkg/service/swaggerdocs/docs.go; \
$(SED_PATH) -i '' '/^\/\/ This file was generated by swaggo\/swag at/d' pkg/service/swaggerdocs/docs.go; \
fi
.PHONY: test
test:
mkdir -p .test-result
go test -cover -coverprofile cover.out -outputdir .test-result ./...
go tool cover -html=.test-result/cover.out -o .test-result/coverage.html
.PHONY: build_service_local
build_service_local: service_doc
mkdir -p builds/debug
go build -o builds/debug/service -ldflags '${EXTLDFLAGS}-X github.com/kpaas-io/kpaas/pkg/utils/version.VersionDev=build.$(BUILD_NUMBER)' github.com/kpaas-io/kpaas/run/service
.PHONY: build_service_cross
build_service_cross: service_doc
mkdir -p builds/release
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o builds/release/service -ldflags '${EXTLDFLAGS}-X github.com/kpaas-io/kpaas/pkg/utils/version.VersionDev=build.$(BUILD_NUMBER)' github.com/kpaas-io/kpaas/run/service
.PHONY: build_service_cross_without_doc
build_service_cross_without_doc:
mkdir -p builds/release
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o builds/release/service -ldflags '${EXTLDFLAGS}-X github.com/kpaas-io/kpaas/pkg/utils/version.VersionDev=build.$(BUILD_NUMBER)' github.com/kpaas-io/kpaas/run/service
.PHONY: run_service_local
run_service_local: build_service_local
builds/debug/service --log-level=debug
.PHONY: run_deploy_local
run_deploy_local: build_deploy_local
builds/debug/deploy --log-level=debug
build_service_image: build_service_cross
docker build -t $(IMAGE_REPOSITORY_URL)/service:$(BUILD_TAG) -f builds/docker/service/Dockerfile .
push_service_image: build_service_image
docker push $(IMAGE_REPOSITORY_URL)/service:$(BUILD_TAG)
.PHONY: build_deploy_protos
build_deploy_protos:
@sh builds/protos/deploy/protos.sh
.PHONY: build_deploy_local
build_deploy_local: build_deploy_protos
mkdir -p builds/debug
go build -o builds/debug/deploy -ldflags '${EXTLDFLAGS}-X github.com/kpaas-io/kpaas/pkg/utils/version.VersionDev=build.$(BUILD_NUMBER)' github.com/kpaas-io/kpaas/run/deploy
.PHONY: build_deploy_cross
build_deploy_cross: build_deploy_protos
mkdir -p builds/release
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o builds/release/deploy -ldflags '${EXTLDFLAGS}-X github.com/kpaas-io/kpaas/pkg/utils/version.VersionDev=build.$(BUILD_NUMBER)' github.com/kpaas-io/kpaas/run/deploy
.PHONY: build_deploy_cross_without_protos
build_deploy_cross_without_protos:
mkdir -p builds/release
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o builds/release/deploy -ldflags '${EXTLDFLAGS}-X github.com/kpaas-io/kpaas/pkg/utils/version.VersionDev=build.$(BUILD_NUMBER)' github.com/kpaas-io/kpaas/run/deploy
assets-deploy-cross: assets build_deploy_cross
assets-deploy-local: assets build_deploy_local
.PHONY: assets
assets:
GO111MODULE=$(GO111MODULE) $(GO) generate ./pkg/deploy/assets
@$(GOFMT) -w ./pkg/deploy/assets
.PHONY: pre_commit
pre_commit: test
go fmt ./...
go vet ./...