...

Text file src/github.com/sigstore/timestamp-authority/Makefile

Documentation: github.com/sigstore/timestamp-authority

     1#
     2# Copyright 2022 The Sigstore Authors.
     3#
     4# Licensed under the Apache License, Version 2.0 (the "License");
     5# you may not use this file except in compliance with the License.
     6# You may obtain a copy of the License at
     7#
     8#     http://www.apache.org/licenses/LICENSE-2.0
     9#
    10# Unless required by applicable law or agreed to in writing, software
    11# distributed under the License is distributed on an "AS IS" BASIS,
    12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13# See the License for the specific language governing permissions and
    14# limitations under the License.
    15
    16.PHONY: all test clean clean-gen lint gosec ko ko-local
    17
    18all: timestamp-cli timestamp-server
    19
    20GENSRC = pkg/generated/client/%.go pkg/generated/models/%.go pkg/generated/restapi/%.go
    21OPENAPIDEPS = openapi.yaml
    22SRCS = $(shell find cmd -iname "*.go") $(shell find pkg -iname "*.go"|grep -v pkg/generated) pkg/generated/restapi/configure_timestamp_server.go $(GENSRC)
    23TOOLS_DIR := hack/tools
    24TOOLS_BIN_DIR := $(abspath $(TOOLS_DIR)/bin)
    25
    26# Set version variables for LDFLAGS
    27GIT_VERSION ?= $(shell git describe --tags --always --dirty)
    28GIT_HASH ?= $(shell git rev-parse HEAD)
    29DATE_FMT = +%Y-%m-%dT%H:%M:%SZ
    30SOURCE_DATE_EPOCH ?= $(shell git log -1 --pretty=%ct)
    31ifdef SOURCE_DATE_EPOCH
    32    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)")
    33else
    34    BUILD_DATE ?= $(shell date "$(DATE_FMT)")
    35endif
    36GIT_TREESTATE = "clean"
    37DIFF = $(shell git diff --quiet >/dev/null 2>&1; if [ $$? -eq 1 ]; then echo "1"; fi)
    38ifeq ($(DIFF), 1)
    39    GIT_TREESTATE = "dirty"
    40endif
    41
    42KO_PREFIX ?= ghcr.io/sigstore
    43export KO_DOCKER_REPO=$(KO_PREFIX)
    44
    45# Binaries
    46SWAGGER := $(TOOLS_BIN_DIR)/swagger
    47
    48LDFLAGS=-X sigs.k8s.io/release-utils/version.gitVersion=$(GIT_VERSION) \
    49				-X sigs.k8s.io/release-utils/version.gitCommit=$(GIT_HASH) \
    50				-X sigs.k8s.io/release-utils/version.gitTreeState=$(GIT_TREESTATE) \
    51				-X sigs.k8s.io/release-utils/version.buildDate=$(BUILD_DATE)
    52
    53CLI_LDFLAGS=$(LDFLAGS)
    54SERVER_LDFLAGS=$(LDFLAGS)
    55
    56$(GENSRC): $(SWAGGER) $(OPENAPIDEPS)
    57	$(SWAGGER) generate client -f openapi.yaml -q -r COPYRIGHT.txt -t pkg/generated
    58	$(SWAGGER) generate server -f openapi.yaml -q -r COPYRIGHT.txt -t pkg/generated --exclude-main -A timestamp_server --flag-strategy=pflag
    59
    60.PHONY: validate-openapi
    61validate-openapi: $(SWAGGER) ## Validate OpenAPI spec
    62	$(SWAGGER) validate openapi.yaml
    63
    64# this exists to override pattern match rule above since this file is in the generated directory but should not be treated as generated code
    65pkg/generated/restapi/configure_timestamp_server.go: $(OPENAPIDEPS)
    66
    67lint: ## Go linting
    68	$(GOBIN)/golangci-lint run -v ./...
    69
    70gosec: ## Run gosec
    71	$(GOBIN)/gosec ./...
    72
    73gen: $(GENSRC) ## Generate code from OpenAPI spec
    74
    75.PHONY : timestamp-cli
    76timestamp-cli: $(SRCS) ## Build the TSA CLI
    77	CGO_ENABLED=0 go build -trimpath -ldflags "$(CLI_LDFLAGS)" -o bin/timestamp-cli ./cmd/timestamp-cli
    78
    79timestamp-server: $(SRCS) ## Build the TSA server 
    80	CGO_ENABLED=0 go build -trimpath -ldflags "$(SERVER_LDFLAGS)" -o bin/timestamp-server ./cmd/timestamp-server
    81
    82test: timestamp-cli ## Run tests
    83	go test ./...
    84
    85clean: ## Clean all builds
    86	rm -rf dist
    87	rm -rf hack/tools/bin
    88	rm -rf bin/timestamp-cli bin/timestamp-server
    89
    90clean-gen: clean ## Clean generated code
    91	rm -rf $(shell find pkg/generated -iname "*.go"|grep -v pkg/generated/restapi/configure_timestamp_server.go)
    92
    93up: ## Run the TSA with Docker Compose
    94	docker-compose -f docker-compose.yml build --build-arg SERVER_LDFLAGS="$(SERVER_LDFLAGS)"
    95	docker-compose -f docker-compose.yml up
    96
    97ko: ## Run Ko
    98	# timestamp-server
    99	LDFLAGS="$(LDFLAGS)" GIT_HASH=$(GIT_HASH) GIT_VERSION=$(GIT_VERSION) \
   100	KO_DOCKER_REPO=$(KO_PREFIX)/timestamp-server ko build --bare \
   101		--platform=all --tags $(GIT_VERSION) --tags $(GIT_HASH) \
   102		--image-refs timestampServerImagerefs github.com/sigstore/timestamp-authority/cmd/timestamp-server
   103
   104	# timestamp-cli
   105	LDFLAGS="$(LDFLAGS)" GIT_HASH=$(GIT_HASH) GIT_VERSION=$(GIT_VERSION) \
   106	KO_DOCKER_REPO=$(KO_PREFIX)/timestamp-cli ko build --bare \
   107		--platform=all --tags $(GIT_VERSION) --tags $(GIT_HASH) \
   108		--image-refs timestampCLIImagerefs github.com/sigstore/timestamp-authority/cmd/timestamp-cli
   109
   110.PHONY: ko-local
   111ko-local: ## Run Ko locally
   112	LDFLAGS="$(SERVER_LDFLAGS)" GIT_HASH=$(GIT_HASH) GIT_VERSION=$(GIT_VERSION) \
   113	ko publish --base-import-paths \
   114		--tags $(GIT_VERSION) --tags $(GIT_HASH) --local \
   115		github.com/sigstore/timestamp-authority/cmd/timestamp-server
   116
   117	LDFLAGS="$(CLI_LDFLAGS)" GIT_HASH=$(GIT_HASH) GIT_VERSION=$(GIT_VERSION) \
   118	ko publish --base-import-paths \
   119		--tags $(GIT_VERSION) --tags $(GIT_HASH) --local \
   120		github.com/sigstore/timestamp-authority/cmd/timestamp-cli
   121
   122## --------------------------------------
   123## Tooling Binaries
   124## --------------------------------------
   125
   126$(SWAGGER): $(TOOLS_DIR)/go.mod
   127	cd $(TOOLS_DIR); go build -trimpath -tags=tools -o $(TOOLS_BIN_DIR)/swagger github.com/go-swagger/go-swagger/cmd/swagger
   128
   129##################
   130# help
   131##################
   132
   133help: ## Display help
   134	@awk -F ':|##' \
   135		'/^[^\t].+?:.*?##/ {\
   136			printf "\033[36m%-30s\033[0m %s\n", $$1, $$NF \
   137		}' $(MAKEFILE_LIST) | sort
   138
   139include release/release.mk

View as plain text