sigs.k8s.io/seccomp-operator@v0.1.0/Makefile (about) 1 # Copyright 2020 The Kubernetes Authors. 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 15 GO ?= go 16 17 PROJECT := seccomp-operator 18 BUILD_DIR := build 19 20 DATE_FMT = +'%Y-%m-%dT%H:%M:%SZ' 21 ifdef SOURCE_DATE_EPOCH 22 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)") 23 else 24 BUILD_DATE ?= $(shell date -u "$(DATE_FMT)") 25 endif 26 27 GIT_COMMIT := $(shell git rev-parse HEAD 2> /dev/null || echo unknown) 28 GIT_TREE_STATE := $(if $(shell git status --porcelain --untracked-files=no),dirty,clean) 29 VERSION := $(shell cat VERSION) 30 31 BUILDTAGS := netgo 32 BUILD_FILES := $(shell find . -type f -name '*.go' -or -name '*.mod' -or -name '*.sum' -not -name '*_test.go') 33 GO_PROJECT := sigs.k8s.io/$(PROJECT) 34 LDVARS := \ 35 -X $(GO_PROJECT)/internal/pkg/version.buildDate=$(BUILD_DATE) \ 36 -X $(GO_PROJECT)/internal/pkg/version.gitCommit=$(GIT_COMMIT) \ 37 -X $(GO_PROJECT)/internal/pkg/version.gitTreeState=$(GIT_TREE_STATE) \ 38 -X $(GO_PROJECT)/internal/pkg/version.version=$(VERSION) 39 LDFLAGS := -s -w -linkmode external -extldflags "-static" $(LDVARS) 40 41 CONTAINER_RUNTIME ?= docker 42 IMAGE ?= $(PROJECT):latest 43 44 GOLANGCI_LINT_VERSION = v1.30.0 45 REPO_INFRA_VERSION = v0.0.10 46 47 # Utility targets 48 49 all: $(BUILD_DIR)/$(PROJECT) ## Build the seccomp-operator binary 50 51 .PHONY: help 52 help: ## Display this help 53 @awk \ 54 -v "col=${COLOR}" -v "nocol=${NOCOLOR}" \ 55 ' \ 56 BEGIN { \ 57 FS = ":.*##" ; \ 58 printf "Available targets:\n"; \ 59 } \ 60 /^[a-zA-Z0-9_-]+:.*?##/ { \ 61 printf " %s%-25s%s %s\n", col, $$1, nocol, $$2 \ 62 } \ 63 /^##@/ { \ 64 printf "\n%s%s%s\n", col, substr($$0, 5), nocol \ 65 } \ 66 ' $(MAKEFILE_LIST) 67 68 $(BUILD_DIR): 69 mkdir -p $(BUILD_DIR) 70 71 $(BUILD_DIR)/$(PROJECT): $(BUILD_DIR) $(BUILD_FILES) 72 $(GO) build -ldflags '$(LDFLAGS)' -tags '$(BUILDTAGS)' -o $@ ./cmd/seccomp-operator 73 74 .PHONY: clean 75 clean: ## Clean the build directory 76 rm -rf $(BUILD_DIR) 77 78 .PHONY: go-mod 79 go-mod: ## Cleanup and verify go modules 80 export GO111MODULE=on \ 81 $(GO) mod tidy && \ 82 $(GO) mod verify 83 84 .PHONY: default-profiles 85 default-profiles: ## Generate the default profiles 86 $(GO) run ./profiles 87 88 .PHONY: image 89 image: ## Build the container image 90 $(CONTAINER_RUNTIME) build --build-arg version=$(VERSION) -t $(IMAGE) . 91 92 # Verification targets 93 94 .PHONY: verify 95 verify: verify-boilerplate verify-go-mod verify-go-lint verify-default-profiles ## Run all verification targets 96 97 .PHONY: verify-boilerplate 98 verify-boilerplate: $(BUILD_DIR)/verify_boilerplate.py ## Verify the boilerplate headers for all files 99 $(BUILD_DIR)/verify_boilerplate.py --boilerplate-dir hack/boilerplate 100 101 $(BUILD_DIR)/verify_boilerplate.py: $(BUILD_DIR) 102 curl -sfL https://raw.githubusercontent.com/kubernetes/repo-infra/$(REPO_INFRA_VERSION)/hack/verify_boilerplate.py \ 103 -o $(BUILD_DIR)/verify_boilerplate.py 104 chmod +x $(BUILD_DIR)/verify_boilerplate.py 105 106 .PHONY: verify-go-mod 107 verify-go-mod: go-mod ## Verify the go modules 108 hack/tree-status 109 110 .PHONY: verify-default-profiles 111 verify-default-profiles: default-profiles ## Verify the generated default profiles 112 hack/tree-status 113 114 .PHONY: verify-go-lint 115 verify-go-lint: $(BUILD_DIR)/golangci-lint ## Verify the golang code by linting 116 $(BUILD_DIR)/golangci-lint run 117 118 $(BUILD_DIR)/golangci-lint: 119 export \ 120 VERSION=$(GOLANGCI_LINT_VERSION) \ 121 URL=https://raw.githubusercontent.com/golangci/golangci-lint \ 122 BINDIR=$(BUILD_DIR) && \ 123 curl -sfL $$URL/$$VERSION/install.sh | sh -s $$VERSION 124 $(BUILD_DIR)/golangci-lint version 125 $(BUILD_DIR)/golangci-lint linters 126 127 # Test targets 128 129 .PHONY: test-unit 130 test-unit: $(BUILD_DIR) ## Run the unit tests 131 $(GO) test -ldflags '$(LDVARS)' -v -test.coverprofile=$(BUILD_DIR)/coverage.out ./... 132 $(GO) tool cover -html $(BUILD_DIR)/coverage.out -o $(BUILD_DIR)/coverage.html 133 134 .PHONY: test-e2e 135 test-e2e: ## Run the end-to-end tests 136 $(GO) test -timeout 20m -tags e2e -count=1 ./test/... -v