-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathMakefile
More file actions
130 lines (108 loc) · 5.13 KB
/
Makefile
File metadata and controls
130 lines (108 loc) · 5.13 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
#
# Copyright 2025 The Sigstore 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.
.PHONY: all test clean lint gosec ko-local tools ldflags
all: protos rekor-server-gcp rekor-server-posix rekor-server-aws rekor-server-gcpcloudsql
GIT_VERSION ?= $(shell git describe --tags --always --dirty)
GIT_HASH ?= $(shell git rev-parse HEAD)
DATE_FMT = +%Y-%m-%dT%H:%M:%SZ
SOURCE_DATE_EPOCH ?= $(shell git log -1 --pretty=%ct)
ifdef SOURCE_DATE_EPOCH
BUILD_DATE ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u "$(DATE_FMT)")
else
BUILD_DATE ?= $(shell date "$(DATE_FMT)")
endif
GIT_TREESTATE = "clean"
DIFF = $(shell git diff --quiet >/dev/null 2>&1; if [ $$? -eq 1 ]; then echo "1"; fi)
ifeq ($(DIFF), 1)
GIT_TREESTATE = "dirty"
endif
PROTO_DIRS = pkg/generated/protobuf/ api/proto/
SRC = $(shell find . -iname "*.go" | grep -v -e $(subst $() $(), -e ,$(strip $(PROTO_DIRS))))
PROTO_SRC = $(shell find $(PROTO_DIRS))
SIGSTORE_PROTO_BUILDER = $(shell grep FROM Dockerfile.protobuf-specs | cut -d' ' -f 2)
ZIZMOR = $(shell grep FROM Dockerfile.zizmor | cut -d' ' -f 2)
# for docker protobuf build
GO_MODULE = github.com/sigstore/rekor-tiles/v2
PROTOS = $(shell find api/proto/ -iname "*.proto" | sed 's|^|/project_dir/|')
PROTO_OUT = pkg/generated/protobuf
OPENAPI_OUT = docs/openapi
MOUNT_POINT = /project_dir
PLATFORM ?= linux/amd64
UID ?= $(shell id -u)
GID ?= $(shell id -g)
DOCKER_RUN = docker run --platform ${PLATFORM} --user ${UID}:${GID}
REKOR_LDFLAGS=-buildid= \
-X sigs.k8s.io/release-utils/version.gitVersion=$(GIT_VERSION) \
-X sigs.k8s.io/release-utils/version.gitCommit=$(GIT_HASH) \
-X sigs.k8s.io/release-utils/version.gitTreeState=$(GIT_TREESTATE) \
-X sigs.k8s.io/release-utils/version.buildDate=$(BUILD_DATE)
SERVER_LDFLAGS=$(REKOR_LDFLAGS)
GOBIN = $(abspath ./tools/bin)
STORAGE_BACKEND ?= gcp
lint:
go tool addlicense -l apache -c "The Sigstore Authors" -ignore "third_party/**" -v *
go tool goimports -w $(SRC)
docker run -t --rm -v $(PWD):/app -w /app \
--user $(shell id -u):$(shell id -g) \
-v $(shell go env GOCACHE):/.cache/go-build -e GOCACHE=/.cache/go-build \
-v $(shell go env GOMODCACHE):/.cache/mod -e GOMODCACHE=/.cache/mod \
-v ~/.cache/golangci-lint:/.cache/golangci-lint -e GOLANGCI_LINT_CACHE=/.cache/golangci-lint \
$(shell awk -F '[ @]' '/FROM golangci\/golangci-lint/{print $$2; exit}' Dockerfile.golangci-lint) golangci-lint run -v ./...
docker run -t --rm -v $(PWD):/source $(ZIZMOR) /source
gosec: ## Run gosec security scanner
$(GOBIN)/gosec ./...
rekor-server-gcp: $(SRC) $(PROTO_SRC)
CGO_ENABLED=0 go build -trimpath -ldflags "$(SERVER_LDFLAGS)" -o rekor-server-gcp ./cmd/rekor-server/gcp
rekor-server-posix: $(SRC) $(PROTO_SRC)
CGO_ENABLED=0 go build -trimpath -ldflags "$(SERVER_LDFLAGS)" -o rekor-server-posix ./cmd/rekor-server/posix
rekor-server-aws: $(SRC) $(PROTO_SRC)
CGO_ENABLED=0 go build -trimpath -ldflags "$(SERVER_LDFLAGS)" -o rekor-server-aws ./cmd/rekor-server/aws
rekor-server-gcpcloudsql: $(SRC) $(PROTO_SRC)
CGO_ENABLED=0 go build -trimpath -ldflags "$(SERVER_LDFLAGS)" -o rekor-server-gcpcloudsql ./cmd/rekor-server/gcpcloudsql
ldflags: ## Print ldflags
@echo $(SERVER_LDFLAGS)
test: ## Run all tests
go test ./...
ko-local: ## Build container images locally using ko, defaulting to the GCP container
KO_DOCKER_REPO=ko.local LDFLAGS="$(SERVER_LDFLAGS)" GIT_HASH=$(GIT_HASH) GIT_VERSION=$(GIT_VERSION) \
ko publish --base-import-paths \
--tags $(GIT_VERSION) --tags $(GIT_HASH) --image-refs rekorImagerefs-$(STORAGE_BACKEND) \
github.com/sigstore/rekor-tiles/v2/cmd/rekor-server/$(STORAGE_BACKEND)
# generate Go protobuf code
protos:
@echo "Generating go protobuf files"
@mkdir -p ${OPENAPI_OUT}
${DOCKER_RUN} -v ${PWD}:${MOUNT_POINT} ${SIGSTORE_PROTO_BUILDER} \
-I/opt/include -I/googleapis -I/grpc-gateway -I/protobuf-specs -I${MOUNT_POINT}/api/proto \
--go_out=${MOUNT_POINT} \
--go_opt=module=${GO_MODULE} \
--go-grpc_opt=module=${GO_MODULE} --go-grpc_out=${MOUNT_POINT} \
--grpc-gateway_opt=module=${GO_MODULE} --grpc-gateway_opt=logtostderr=true --grpc-gateway_out=${MOUNT_POINT} \
--openapiv2_out=${MOUNT_POINT}/${OPENAPI_OUT} \
${PROTOS}
clean: ## Remove built binaries and artifacts
rm -rf docs/openapi/*
rm -rf pkg/generated/protobuf/*
rm -rf dist
rm -rf hack/tools/bin
rm -rf rekor-server
##################
# help
##################
help: ## Display this help message
@echo "Usage: make <target>"
@echo ""
@echo "Targets:"
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z0-9_-]+:.*?## / {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)