-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
84 lines (65 loc) · 2.12 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
# BEGIN: lint-install .
# http://github.com/tinkerbell/lint-install
.PHONY: lint
lint: _lint
LINT_ARCH := $(shell uname -m)
LINT_OS := $(shell uname)
LINT_OS_LOWER := $(shell echo $(LINT_OS) | tr '[:upper:]' '[:lower:]')
LINT_ROOT := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
# shellcheck and hadolint lack arm64 native binaries: rely on x86-64 emulation
ifeq ($(LINT_OS),Darwin)
ifeq ($(LINT_ARCH),arm64)
LINT_ARCH=x86_64
endif
endif
LINTERS :=
FIXERS :=
GOLANGCI_LINT_CONFIG := $(LINT_ROOT)/.golangci.yml
GOLANGCI_LINT_VERSION ?= v1.43.0
GOLANGCI_LINT_BIN := out/linters/golangci-lint-$(GOLANGCI_LINT_VERSION)-$(LINT_ARCH)
$(GOLANGCI_LINT_BIN):
mkdir -p out/linters
rm -rf out/linters/golangci-lint-*
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b out/linters $(GOLANGCI_LINT_VERSION)
mv out/linters/golangci-lint $@
LINTERS += golangci-lint-lint
golangci-lint-lint: $(GOLANGCI_LINT_BIN)
$(GOLANGCI_LINT_BIN) run
FIXERS += golangci-lint-fix
golangci-lint-fix: $(GOLANGCI_LINT_BIN)
$(GOLANGCI_LINT_BIN) run --fix
.PHONY: _lint $(LINTERS)
_lint: $(LINTERS)
.PHONY: fix $(FIXERS)
fix: $(FIXERS)
GIT_TAG ?= dirty-tag
GIT_VERSION ?= $(shell git describe --tags --always --dirty)
GIT_HASH ?= $(shell git rev-parse HEAD)
LDFLAGS=-buildid= -X $(PKG).gitVersion=$(GIT_VERSION) \
-X $(PKG).gitCommit=$(GIT_HASH) \
-X $(PKG).gitTreeState=$(GIT_TREESTATE) \
-X $(PKG).buildDate=$(BUILD_DATE)
KOCACHE_PATH=/tmp/ko
define create_kocache_path
mkdir -p $(KOCACHE_PATH)
endef
KO_DOCKER_REPO ?= ghcr.io/chainguard-dev/googkol
DIGEST ?=
##########
# ko build
##########
.PHONY: ko
ko: ## Build images using ko
$(create_kocache_path)
$(eval DIGEST := $(shell LDFLAGS="$(LDFLAGS)" GIT_HASH=$(GIT_HASH) GIT_VERSION=$(GIT_VERSION) \
KOCACHE=$(KOCACHE_PATH) ko build --bare \
--platform=all --tags $(GIT_VERSION) --tags $(GIT_HASH) \
chainguard.dev/googkol))
@echo Image Digest $(DIGEST)
#######################
# Sign images
#######################
.PHONY: sign-image
sign-image: ko ## Sign images built using ko
cosign sign $(DIGEST)
# END: lint-install .