@@ -7,15 +7,21 @@ TAG ?= latest
77CRD_OPTIONS ?= crd:crdVersions=v1
88
99# Base image used to build the Go binary
10- BASE_IMG ?= ghcr.io/hiddeco/golang-with-libgit2
11- BASE_TAG ?= dev
10+ LIBGIT2_IMG ?= ghcr.io/fluxcd/golang-with-libgit2
11+ LIBGIT2_TAG ?= libgit2-1.1.1
12+
13+ # Allows for defining additional Docker buildx arguments,
14+ # e.g. '--push'.
15+ BUILD_ARGS ?=
16+ # Architectures to build images for
17+ BUILD_PLATFORMS ?= linux/amd64,linux/arm64,linux/arm/v7
1218
1319# Directory with versioned, downloaded things
1420CACHE := cache
1521
1622# Version of the source-controller from which to get the GitRepository CRD.
1723# Change this if you bump the source-controller/api version in go.mod.
18- SOURCE_VER ?= v0.15.4
24+ SOURCE_VER ?= v0.16.0
1925
2026# Version of the image-reflector-controller from which to get the ImagePolicy CRD.
2127# Change this if you bump the image-reflector-controller/api version in go.mod.
@@ -27,13 +33,21 @@ LIBGIT2_VER ?= 1.1.1
2733# Repository root based on Git metadata.
2834REPOSITORY_ROOT := $(shell git rev-parse --show-toplevel)
2935
30- # libgit2 related magical paths.
36+ # libgit2 related magical paths
3137# These are used to determine if the target libgit2 version is already available on
32- # the system, or where they should be installed to.
33- SYSTEM_LIBGIT2_VER := $(shell pkg-config --modversion libgit2 2>/dev/null)
38+ # the system, or where they should be installed to
39+ SYSTEM_LIBGIT2_VERSION := $(shell pkg-config --modversion libgit2 2>/dev/null)
3440LIBGIT2_PATH := $(REPOSITORY_ROOT ) /hack/libgit2
3541LIBGIT2_LIB_PATH := $(LIBGIT2_PATH ) /lib
36- LIBGIT2 := $(LIBGIT2_LIB_PATH ) /libgit2.so.$(LIBGIT2_VER )
42+ LIBGIT2 := $(LIBGIT2_LIB_PATH ) /libgit2.so.$(LIBGIT2_VERSION )
43+
44+ ifneq ($(LIBGIT2_VERSION ) ,$(SYSTEM_LIBGIT2_VERSION ) )
45+ LIBGIT2_FORCE ?= 1
46+ endif
47+
48+ ifeq ($(shell uname -s) ,Darwin)
49+ LIBGIT2 := $(LIBGIT2_LIB_PATH)/libgit2.$(LIBGIT2_VERSION).dylib
50+ endif
3751
3852# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
3953ifeq (,$(shell go env GOBIN) )
@@ -127,10 +141,12 @@ generate: controller-gen ## Generate code
127141 cd api; $(CONTROLLER_GEN ) object:headerFile=" ../hack/boilerplate.go.txt" paths=" ./..."
128142
129143docker-build : # # Build the Docker image
130- docker build \
131- --build-arg BASE_IMG=$(BASE_IMG ) \
132- --build-arg BASE_TAG=$(BASE_TAG ) \
133- -t $(IMG ) :$(TAG ) .
144+ docker buildx build \
145+ --build-arg LIBGIT2_IMG=$(LIBGIT2_IMG ) \
146+ --build-arg LIBGIT2_TAG=$(LIBGIT2_TAG ) \
147+ --platform=$(BUILD_PLATFORMS ) \
148+ -t $(IMG ) :$(TAG ) \
149+ $(BUILD_ARGS ) .
134150
135151docker-push : # # Push the Docker image
136152 docker push $(IMG ) :$(TAG )
@@ -168,16 +184,15 @@ else
168184API_REF_GEN =$(shell which gen-crd-api-reference-docs)
169185endif
170186
171- libgit2 : $(LIBGIT2 ) # # Detect or download libgit2 library
187+ libgit2 : $(LIBGIT2 ) # # Detect or download libgit2 library
172188
173189$(LIBGIT2 ) :
174- ifeq ($(LIBGIT2_VER ) ,$(SYSTEM_LIBGIT2_VER ) )
175- else
190+ ifeq (1, $(LIBGIT2_FORCE ) )
176191 @{ \
177192 set -e; \
178193 mkdir -p $(LIBGIT2_PATH); \
179- docker cp $(shell docker create --rm $(BASE_IMG):$(BASE_TAG)):/libgit2 /Makefile $(LIBGIT2_PATH); \
180- INSTALL_PREFIX=$(LIBGIT2_PATH) LIGBIT2_VERSION=$(LIBGIT2_VER) make -C $(LIBGIT2_PATH); \
194+ curl -sL https://raw.githubusercontent.com/fluxcd/golang-with-libgit2/$(LIBGIT2_TAG)/hack /Makefile -o $(LIBGIT2_PATH)/Makefile ; \
195+ INSTALL_PREFIX=$(LIBGIT2_PATH) make -C $(LIBGIT2_PATH) libgit2 ; \
181196 }
182197endif
183198
0 commit comments