-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathMakefile
More file actions
191 lines (152 loc) · 6.5 KB
/
Makefile
File metadata and controls
191 lines (152 loc) · 6.5 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# Copyright 2019 The Goployer Authors
#
# 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.
GOOS ?= $(shell go env GOOS)
GOARCH ?= amd64
BUILD_DIR ?= ./out
COMMAND_PKG ?= cmd
ORG = github.com/DevopsArtFactory
PROJECT = goployer
REPOPATH ?= $(ORG)/$(PROJECT)
RELEASE_BUCKET ?= $(PROJECT)
S3_RELEASE_PATH ?= s3://$(RELEASE_BUCKET)/releases/$(VERSION)
S3_RELEASE_LATEST ?= s3://$(RELEASE_BUCKET)/releases/latest
S3_BLEEDING_EDGE_LATEST ?= s3://$(RELEASE_BUCKET)/edge/latest
S3_EXPERIMENTAL_LATEST ?= s3://$(RELEASE_BUCKET)/experimental/latest
VERSION = 3.0.0
GCP_ONLY ?= false
GCP_PROJECT ?= goployer
SUPPORTED_PLATFORMS = linux-amd64 darwin-amd64 windows-amd64.exe linux-arm64
BUILD_PACKAGE = $(REPOPATH)/$(COMMAND_PKG)/$(PROJECT)
GOPLOYER_TEST_PACKAGES = ./pkg/goployer/... ./cmd/... ./hack/... ./pkg/webhook/...
GO_FILES = $(shell find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./pkg/diag/*")
VERSION_PACKAGE = $(REPOPATH)/pkg/version
COMMIT = $(shell git rev-parse HEAD)
TEST_PACKAGES = ./pkg/... ./hack/...
ifeq "$(strip $(VERSION))" ""
override VERSION = $(shell git describe --always --tags --dirty)
endif
LDFLAGS_linux = -static
LDFLAGS_darwin =
LDFLAGS_windows =
GO_BUILD_TAGS_linux = "osusergo netgo static_build release"
GO_BUILD_TAGS_darwin = "release"
GO_BUILD_TAGS_windows = "release"
GO_LDFLAGS = -X $(VERSION_PACKAGE).version=$(VERSION)
GO_LDFLAGS += -X $(VERSION_PACKAGE).buildDate=$(shell date +'%Y-%m-%dT%H:%M:%SZ')
GO_LDFLAGS += -X $(VERSION_PACKAGE).gitCommit=$(COMMIT)
GO_LDFLAGS += -X $(VERSION_PACKAGE).gitTreeState=$(if $(shell git status --porcelain),dirty,clean)
GO_LDFLAGS += -s -w
GO_LDFLAGS_windows =" $(GO_LDFLAGS) -extldflags \"$(LDFLAGS_windows)\""
GO_LDFLAGS_darwin =" $(GO_LDFLAGS) -extldflags \"$(LDFLAGS_darwin)\""
GO_LDFLAGS_linux =" $(GO_LDFLAGS) -extldflags \"$(LDFLAGS_linux)\""
# Build for local development.
$(BUILD_DIR)/$(PROJECT): $(GO_FILES) $(BUILD_DIR)
@echo
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=1 go build -tags $(GO_BUILD_TAGS_$(GOOS)) -ldflags $(GO_LDFLAGS_$(GOOS)) -o $@ $(BUILD_PACKAGE)
.PHONY: install
install: $(BUILD_DIR)/$(PROJECT)
cp $(BUILD_DIR)/$(PROJECT) $(GOPATH)/bin/$(PROJECT)
.PRECIOUS: $(foreach platform, $(SUPPORTED_PLATFORMS), $(BUILD_DIR)/$(PROJECT)-$(platform))
.PHONY: cross
cross: $(foreach platform, $(SUPPORTED_PLATFORMS), $(BUILD_DIR)/$(PROJECT)-$(platform))
$(BUILD_DIR)/$(PROJECT)-%: $(STATIK_FILES) $(GO_FILES) $(BUILD_DIR) deploy/cross/Dockerfile
$(eval os = $(firstword $(subst -, ,$*)))
$(eval arch = $(lastword $(subst -, ,$(subst .exe,,$*))))
$(eval ldflags = $(GO_LDFLAGS_$(os)))
$(eval tags = $(GO_BUILD_TAGS_$(os)))
docker build \
--build-arg GOOS=$(os) \
--build-arg GOARCH=$(arch) \
--build-arg TAGS=$(tags) \
--build-arg LDFLAGS=$(ldflags) \
-f deploy/cross/Dockerfile \
-t goployer/cross \
.
docker run --rm goployer/cross cat /build/goployer > $@
shasum -a 256 $@ | tee $@.sha256
file $@ || true
.PHONY: $(BUILD_DIR)/VERSION
$(BUILD_DIR)/VERSION: $(BUILD_DIR)
@ echo $(VERSION) > $@
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
.PHONY: update-edge
update-edge: format cross $(BUILD_DIR)/VERSION upload-edge-only
.PHONY: update-experimental
update-experimental: format cross $(BUILD_DIR)/VERSION upload-experimental-only
.PHONY: release
release: format clean cross $(BUILD_DIR)/VERSION upload-release-only
.PHONY: build
build: format cross $(BUILD_DIR)/VERSION
.PHONY: release-build
release-build: format cross
aws s3 cp $(BUILD_DIR)/ $(S3_RELEASE_PATH)/ --recursive --include "$(PROJECT)-*" --acl public-read
aws s3 cp $(S3_RELEASE_PATH)/ $(S3_RELEASE_LATEST)/ --recursive --acl public-read
# docker build \
# -f deploy/Dockerfile \
# --target release \
# -t gcr.io/$(GCP_PROJECT)/goployer:edge \
# -t gcr.io/$(GCP_PROJECT)/goployer:$(COMMIT) \
# .
.PHONY: upload-edge-only
upload-edge-only: version
aws s3 cp $(BUILD_DIR)/ $(S3_BLEEDING_EDGE_LATEST)/ --recursive --include "$(PROJECT)-*" --acl public-read
# docker build --build-arg GOPLOYER_VERSION=edge --build-arg GOPLOYER_URL=https://goployer.s3.ap-northeast-2.amazonaws.com/edge/latest/goployer-linux-amd64 -t devopsart/goployer:edge deploy
# docker push devopsart/goployer:edge
.PHONY: upload-experimental-only
upload-experimental-only: version
aws s3 cp $(BUILD_DIR)/ $(S3_EXPERIMENTAL_LATEST)/ --recursive --include "$(PROJECT)-*" --acl public-read
# docker build --build-arg GOPLOYER_VERSION=experimental --build-arg GOPLOYER_URL=https://goployer.s3.ap-northeast-2.amazonaws.com/experimental/latest/goployer-linux-amd64 -t devopsart/goployer:experimental deploy
# docker push devopsart/goployer:experimental
.PHONY: upload-release-only
upload-release-only: version
aws s3 cp $(BUILD_DIR)/ $(S3_RELEASE_PATH)/ --recursive --include "$(PROJECT)-*" --acl public-read
aws s3 cp $(S3_RELEASE_PATH)/ $(S3_RELEASE_LATEST)/ --recursive --acl public-read
# docker build --build-arg GOPLOYER_VERSION=edge --build-arg GOPLOYER_URL=https://goployer.s3.ap-northeast-2.amazonaws.com/edge/latest/goployer-linux-amd64 -t devopsart/goployer:latest deploy
# docker push devopsart/goployer:latest\
.PHONY: clean
clean:
rm -rf $(BUILD_DIR)
rm -rf manifest
rm -rf manifests
rm -rf scripts
.PHONY: version
version:
@echo "Current version is ${VERSION}"
.PHONY: format
format:
go fmt ./...
.PHONY: generate-schema
generate-schemas:
go run ./hack/schemas/main.go
# utilities for goployer site - not used anywhere else
.PHONY: preview-docs-draft
preview-docs-draft:
./deploy/docs/preview-docs.sh hugo serve -D --bind=0.0.0.0 --ignoreCache
.PHONY: preview-docs
preview-docs:
./deploy/docs/preview-docs.sh hugo serve --bind=0.0.0.0 --ignoreCache
.PHONY: test
test:
@ go test -count=1 -v -race -short -timeout=90s $(TEST_PACKAGES)
.PHONY: api-test
api-test:
@ ./hack/apitest.sh
.PHONY: coverage
coverage: $(BUILD_DIR)
@ go test -count=1 -race -cover -short -timeout=90s -coverprofile=out/coverage.txt -coverpkg="./pkg/...,./hack..." $(TEST_PACKAGES)
@- curl -s https://codecov.io/bash > $(BUILD_DIR)/upload_coverage && bash $(BUILD_DIR)/upload_coverage -t $(COVERAGE_TOKEN)
.PHONY: linters
linters: $(BUILD_DIR)
@ ./hack/linters.sh