@@ -39,9 +39,7 @@ LDFLAGS=-buildid= -X $(PKG).gitVersion=$(GIT_VERSION) \
3939
4040DIGEST ?=
4141
42- define create_kocache_path
43- mkdir -p $(KOCACHE_PATH )
44- endef
42+ PROJECT_BIN := $(shell pwd) /bin
4543
4644# #########
4745# default
@@ -53,35 +51,54 @@ default: help
5351# ko build
5452# #########
5553
54+ DOCKER_HOST ?= $(shell docker context inspect --format '{{.Endpoints.docker.Host}}')
55+
56+ KO_BIN := $(PROJECT_BIN ) /ko
57+ KO_VERSION := v0.18.0
58+ KO_DOCKER_REPO ?= chainguard.dev/apko
59+ KOCACHE := $(PROJECT_BIN ) /kocache
60+ KO_TAGS := --tags $(IMAGE_TAG ) --tags $(GIT_VERSION ) --tags $(GIT_HASH )
61+
62+ $(KO_BIN ) :
63+ @echo " Installing ko@$( KO_VERSION) to $( PROJECT_BIN) …"
64+ @GOBIN=$(PROJECT_BIN ) go install github.com/google/ko@$(KO_VERSION )
65+
66+ $(KOCACHE ) :
67+ @mkdir -p $@
68+
5669.PHONY : ko
57- ko : # # Build images using ko
58- $( create_kocache_path )
59- $(eval DIGEST := $(shell LDFLAGS="$(LDFLAGS ) " GIT_HASH=$(GIT_HASH ) GIT_VERSION=$(GIT_VERSION ) \
60- KOCACHE =$(KOCACHE_PATH ) ko build --bare \
61- --platform=all --tags $( IMAGE_TAG ) --tags $( GIT_VERSION ) --tags $( GIT_HASH ) \
62- chainguard.dev/apko ))
70+ ko : $( KO_BIN ) $( KOCACHE ) # # Build images using ko
71+ @ $( MAKE ) --no-print-directory log- $@
72+ @ $(eval DIGEST := $(shell LDFLAGS="$(LDFLAGS ) " GIT_HASH=$(GIT_HASH ) GIT_VERSION=$(GIT_VERSION ) \
73+ KO_DOCKER_REPO =$(KO_DOCKER_REPO ) \
74+ KOCACHE= $( KOCACHE ) \
75+ $< build --bare --platform=all $( KO_TAGS ) ))
6376 @echo Image Digest $(DIGEST )
6477
6578.PHONY : ko-local
66- ko-local : # # Build images locally using ko
67- $(create_kocache_path )
79+ ko-local : $(KO_BIN ) $(KOCACHE ) # # Build images locally using ko
80+ @$(MAKE ) --no-print-directory log-$@
81+ @DOCKER_HOST=$(DOCKER_HOST ) \
82+ KO_DOCKER_REPO=$(KO_DOCKER_REPO ) \
6883 LDFLAGS=" $( LDFLAGS) " GIT_HASH=$(GIT_HASH ) GIT_VERSION=$(GIT_VERSION ) \
69- KOCACHE=$(KOCACHE_PATH ) ko build --bare \
70- --tags $(IMAGE_TAG ) --tags $(GIT_VERSION ) --tags $(GIT_HASH ) --local \
71- chainguard.dev/apko
84+ $< build --bare --local $(KO_TAGS )
7285
7386.PHONY : ko-apply
74- ko-apply : # # Build the image and apply the manifests
75- $(create_kocache_path )
87+ ko-apply : $(KO_BIN ) $(KOCACHE ) # # Build the image and apply the manifests
88+ @$(MAKE ) --no-print-directory log-$@
89+ @KO_DOCKER_REPO=$(KO_DOCKER_REPO ) \
90+ KOCACHE=$(KOCACHE ) \
7691 LDFLAGS=" $( LDFLAGS) " \
77- KOCACHE= $( KOCACHE_PATH ) ko apply --base-import-paths \
92+ $< apply --base-import-paths \
7893 --recursive --filename config/
7994
80- .PHONY : ko-apply
81- ko-resolve : # # Build the image generate the Task YAML
82- $(create_kocache_path )
95+ .PHONY : ko-resolve
96+ ko-resolve : $(KO_BIN ) $(KOCACHE ) # # Build the image generate the Task YAML
97+ @$(MAKE ) --no-print-directory log-$@
98+ @KO_DOCKER_REPO=$(KO_DOCKER_REPO ) \
99+ KOCACHE=$(KOCACHE ) \
83100 LDFLAGS=" $( LDFLAGS) " \
84- KOCACHE= $( KOCACHE_PATH ) ko resolve --base-import-paths \
101+ $< resolve --base-import-paths \
85102 --recursive --filename config/ > task.yaml
86103
87104# #########
@@ -108,26 +125,28 @@ install: $(SRCS) ## Builds and moves apko into BINDIR (default /usr/bin)
108125# lint / test section
109126# ####################
110127
111- GOLANGCI_LINT_DIR = $(shell pwd) /bin
112- GOLANGCI_LINT_BIN = $( GOLANGCI_LINT_DIR ) /golangci-lint
128+ GOLANGCI_LINT_BIN : = $(PROJECT_BIN ) /golangci-lint
129+ GOLANGCI_LINT_VERSION := v2.6.1
113130
114- .PHONY : golangci-lint
115- golangci-lint :
116- rm -f $(GOLANGCI_LINT_BIN ) || :
117- set -e ; \
118- GOBIN=$(GOLANGCI_LINT_DIR ) go install github.com/golangci/golangci-lint/cmd/golangci-lint/v2@v2.2.1 ; \
131+ $(GOLANGCI_LINT_BIN ) :
132+ @echo " Installing golangci-lint@$( GOLANGCI_LINT_VERSION) to $( PROJECT_BIN) …"
133+ @GOBIN=$(PROJECT_BIN ) go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION )
134+
135+ $(GOBIN ) /goimports :
136+ @echo " Installing goimports to $( GOBIN) …"
137+ @go install golang.org/x/tools/cmd/goimports@latest
119138
120139.PHONY : fmt
121- fmt : # # Format all go files
122- @ $(MAKE ) --no-print-directory log-$@
123- goimports -w $(GOFILES )
140+ fmt : $( GOBIN ) /goimports # # Format all go files
141+ @$(MAKE ) --no-print-directory log-$@
142+ @ $< -l $(GOFILES )
124143
125144.PHONY : checkfmt
126145checkfmt : SHELL := /usr/bin/env bash
127- checkfmt : # # Check formatting of all go files
128- @ $(MAKE ) --no-print-directory log-$@
129- $( shell test -z "$( shell gofmt -l $(GOFILES ) | tee /dev/stderr) ")
130- $( shell test -z "$( shell goimports -l $(GOFILES ) | tee /dev/stderr) ")
146+ checkfmt : $( GOBIN ) /goimports # # Check formatting of all go files
147+ @$(MAKE ) --no-print-directory log-$@
148+ @ test -z " $$ ( gofmt -l $( GOFILES) ) " || { echo " Files need formatting " ; exit 1 ; }
149+ @ test -z " $$ ($< -l $( GOFILES) ) " || { echo " Linting issues found " ; exit 1 ; }
131150
132151log-% :
133152 @grep -h -E ' ^$*:.*?## .*$$' $(MAKEFILE_LIST ) | \
@@ -140,8 +159,9 @@ log-%:
140159 }'
141160
142161.PHONY : lint
143- lint : checkfmt golangci-lint # # Run linters and checks like golangci-lint
144- $(GOLANGCI_LINT_BIN ) run -n
162+ lint : checkfmt $(GOLANGCI_LINT_BIN ) # # Run linters and checks like golangci-lint
163+ @$(MAKE ) --no-print-directory log-$@
164+ @$(GOLANGCI_LINT_BIN ) run -n
145165
146166.PHONY : test
147167test : # # Run go test
177197# ######################
178198# Sign images
179199# ######################
200+
201+ COSIGN_VERSION := v3.0.2
202+
203+ $(PROJECT_BIN ) /cosign :
204+ @echo " Installing cosign to $( PROJECT_BIN) …"
205+ @GOBIN=$(PROJECT_BIN ) go install github.com/sigstore/cosign/v3/cmd/cosign@$(COSIGN_VERSION )
206+
180207.PHONY : sign-image
181- sign-image : ko # # Sign images built using ko
182- cosign sign -y $(DIGEST )
208+ sign-image : $(PROJECT_BIN ) /cosign ko # # Sign images built using ko
209+ @$(MAKE ) --no-print-directory log-$@
210+ @echo " Signing $( DIGEST) …"
211+ @$< sign -y $(DIGEST )
183212
184213# #################
185214# help
0 commit comments