@@ -3,8 +3,12 @@ IMG ?= fluxcd/image-automation-controller:latest
33# Produce CRDs that work back to Kubernetes 1.16
44CRD_OPTIONS ?= crd:crdVersions=v1
55
6+ # Base image used to build the Go binary
7+ BASE_IMG ?= ghcr.io/hiddeco/golang-with-libgit2
8+ BASE_TAG ?= dev
9+
610# Directory with versioned, downloaded things
7- CACHE: = cache
11+ CACHE := cache
812
913# Version of the source-controller from which to get the GitRepository CRD.
1014# Change this if you bump the source-controller/api version in go.mod.
@@ -14,17 +18,31 @@ SOURCE_VER ?= v0.15.4
1418# Change this if you bump the image-reflector-controller/api version in go.mod.
1519REFLECTOR_VER ?= v0.11.1
1620
21+ # Version of libgit2 the controller should depend on.
22+ LIBGIT2_VER ?= 1.1.1
23+
24+ # Repository root based on Git metadata.
25+ REPOSITORY_ROOT := $(shell git rev-parse --show-toplevel)
26+
27+ # libgit2 related magical paths.
28+ # These are used to determine if the target libgit2 version is already available on
29+ # the system, or where they should be installed to.
30+ SYSTEM_LIBGIT2_VER := $(shell pkg-config --modversion libgit2 2>/dev/null)
31+ LIBGIT2_PATH := $(REPOSITORY_ROOT ) /hack/libgit2
32+ LIBGIT2_LIB_PATH := $(LIBGIT2_PATH ) /lib
33+ LIBGIT2 := $(LIBGIT2_LIB_PATH ) /libgit2.so.$(LIBGIT2_VER )
34+
1735# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
1836ifeq (,$(shell go env GOBIN) )
1937GOBIN =$(shell go env GOPATH) /bin
2038else
2139GOBIN =$(shell go env GOBIN)
2240endif
2341
24- TEST_CRDS: = controllers/testdata/crds
42+ TEST_CRDS := controllers/testdata/crds
2543
2644# Log level for `make run`
27- LOG_LEVEL? = info
45+ LOG_LEVEL ?= info
2846
2947all : manager
3048
@@ -52,14 +70,19 @@ ${CACHE}/imagepolicies_${REFLECTOR_VER}.yaml:
5270 curl -s --fail https://raw.githubusercontent.com/fluxcd/image-reflector-controller/${REFLECTOR_VER} /config/crd/bases/image.toolkit.fluxcd.io_imagepolicies.yaml \
5371 -o ${CACHE} /imagepolicies_${REFLECTOR_VER} .yaml
5472
55- test : test_deps generate fmt vet manifests api-docs # # Run tests
73+ test : $(LIBGIT2 ) test-api test_deps generate fmt vet manifests api-docs # # Run tests
74+ LD_LIBRARY_PATH=$(LIBGIT2_LIB_PATH ) \
75+ PKG_CONFIG_PATH=$(LIBGIT2_LIB_PATH ) /pkgconfig/ \
5676 go test ./... -coverprofile cover.out
77+
78+ test-api : # # Run api tests
5779 cd api; go test ./... -coverprofile cover.out
5880
59- manager : generate fmt vet # # Build manager binary
81+ manager : $(LIBGIT2 ) generate fmt vet # # Build manager binary
82+ PKG_CONFIG_PATH=$(LIBGIT2_LIB_PATH ) /pkgconfig/ \
6083 go build -o bin/manager main.go
6184
62- run : generate fmt vet manifests # Run against the configured Kubernetes cluster in ~/.kube/config
85+ run : $( LIBGIT2 ) generate fmt vet manifests # Run against the configured Kubernetes cluster in ~/.kube/config
6386 go run ./main.go --log-level=${LOG_LEVEL} --log-encoding=console
6487
6588install : manifests # # Install CRDs into a cluster
@@ -92,11 +115,11 @@ fmt: ## Run go fmt against code
92115 go fmt ./...
93116 cd api; go fmt ./...
94117
95- vet : # # Run go vet against code
118+ vet : $(LIBGIT2 ) # # Run go vet against code
119+ PKG_CONFIG_PATH=$(LIBGIT2_LIB_PATH ) /pkgconfig \
96120 go vet ./...
97121 cd api; go vet ./...
98122
99-
100123generate : controller-gen # # Generate code
101124 cd api; $(CONTROLLER_GEN ) object:headerFile=" ../hack/boilerplate.go.txt" paths=" ./..."
102125
@@ -139,6 +162,19 @@ else
139162API_REF_GEN =$(shell which gen-crd-api-reference-docs)
140163endif
141164
165+ libgit2 : $(LIBGIT2 ) # # Detect or download libgit2 library
166+
167+ $(LIBGIT2 ) :
168+ ifeq ($(LIBGIT2_VER ) ,$(SYSTEM_LIBGIT2_VER ) )
169+ else
170+ @{ \
171+ set -e; \
172+ mkdir -p $(LIBGIT2_PATH); \
173+ docker cp $(shell docker create --rm $(BASE_IMG):$(BASE_TAG)):/libgit2/Makefile $(LIBGIT2_PATH); \
174+ INSTALL_PREFIX=$(LIBGIT2_PATH) LIGBIT2_VERSION=$(LIBGIT2_VER) LIBGIT2_REVISION= make -C $(LIBGIT2_PATH); \
175+ }
176+ endif
177+
142178.PHONY : help
143179help : # # Display this help menu
144180 @awk ' BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-20s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST )
0 commit comments