-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use static libraries from built image
Signed-off-by: Paulo Gomes <[email protected]>
- Loading branch information
Paulo Gomes
committed
Jan 27, 2022
1 parent
93c636e
commit 75dee8f
Showing
5 changed files
with
86 additions
and
121 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,8 @@ jobs: | |
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-go- | ||
- name: Run tests | ||
run: make test | ||
- name: Setup Kubernetes | ||
uses: engineerd/[email protected] | ||
with: | ||
|
@@ -36,11 +38,6 @@ jobs: | |
uses: fluxcd/pkg/actions/kustomize@main | ||
- name: Setup Helm | ||
uses: fluxcd/pkg/actions/helm@main | ||
- name: Run tests | ||
uses: ./.github/actions/run-tests | ||
env: | ||
GOROOT: | ||
GOPATH: /github/home/go | ||
- name: Verify | ||
run: make verify | ||
- name: Run E2E tests | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,30 +18,24 @@ CRD_OPTIONS ?= crd:crdVersions=v1 | |
# Repository root based on Git metadata | ||
REPOSITORY_ROOT := $(shell git rev-parse --show-toplevel) | ||
|
||
# Libgit2 version | ||
LIBGIT2_VERSION ?= 1.1.1 | ||
|
||
# Other dependency versions | ||
ENVTEST_BIN_VERSION ?= 1.19.2 | ||
|
||
# libgit2 related magical paths | ||
# These are used to determine if the target libgit2 version is already available on | ||
# the system, or where they should be installed to | ||
SYSTEM_LIBGIT2_VERSION := $(shell pkg-config --modversion libgit2 2>/dev/null) | ||
LIBGIT2_PATH := $(REPOSITORY_ROOT)/hack/libgit2 | ||
KUBEBUILDER_ASSETS?="$(shell $(ENVTEST) --arch=$(ENVTEST_ARCH) use -i $(ENVTEST_KUBERNETES_VERSION) --bin-dir=$(ENVTEST_ASSETS_DIR) -p path)" | ||
|
||
LIBGIT2_PATH := $(REPOSITORY_ROOT)/build/libgit2 | ||
LIBGIT2_LIB_PATH := $(LIBGIT2_PATH)/lib | ||
LIBGIT2 := $(LIBGIT2_LIB_PATH)/libgit2.so.$(LIBGIT2_VERSION) | ||
LIBGIT2_LIB64_PATH := $(LIBGIT2_PATH)/lib64 | ||
LIBGIT2 := $(LIBGIT2_LIB_PATH)/libgit2.a | ||
|
||
ifneq ($(LIBGIT2_VERSION),$(SYSTEM_LIBGIT2_VERSION)) | ||
LIBGIT2_FORCE ?= 1 | ||
endif | ||
export CGO_ENABLED=1 | ||
export PKG_CONFIG_PATH=$(LIBGIT2_LIB_PATH)/pkgconfig:$(LIBGIT2_LIB64_PATH)/pkgconfig | ||
export CGO_CFLAGS=-I$(LIBGIT2_PATH)/include | ||
|
||
ifeq ($(shell uname -s),Darwin) | ||
LIBGIT2 := $(LIBGIT2_LIB_PATH)/libgit2.$(LIBGIT2_VERSION).dylib | ||
HAS_BREW := $(shell brew --version 2>/dev/null) | ||
ifdef HAS_BREW | ||
HAS_OPENSSL := $(shell brew --prefix [email protected]) | ||
endif | ||
export CGO_LDFLAGS=-L$(LIBGIT2_LIB_PATH) -lssh2 -lssl -lcrypto -lgit2 | ||
else | ||
export CGO_LDFLAGS=-L$(LIBGIT2_LIB_PATH) -L$(LIBGIT2_LIB64_PATH) -lssh2 -lz -lgit2 -lrt -lssl -lcrypto -lz -ldl -pthread | ||
endif | ||
|
||
|
||
|
@@ -56,59 +50,28 @@ else | |
GOBIN=$(shell go env GOBIN) | ||
endif | ||
|
||
ifeq ($(strip ${PKG_CONFIG_PATH}),) | ||
MAKE_PKG_CONFIG_PATH = $(LIBGIT2_LIB_PATH)/pkgconfig | ||
else | ||
MAKE_PKG_CONFIG_PATH = ${PKG_CONFIG_PATH}:$(LIBGIT2_LIB_PATH)/pkgconfig | ||
endif | ||
|
||
ifdef HAS_OPENSSL | ||
MAKE_PKG_CONFIG_PATH := $(MAKE_PKG_CONFIG_PATH):$(HAS_OPENSSL)/lib/pkgconfig | ||
endif | ||
|
||
# Architecture to use envtest with | ||
ENVTEST_ARCH ?= amd64 | ||
|
||
all: build | ||
|
||
build: $(LIBGIT2) ## Build manager binary | ||
ifeq ($(shell uname -s),Darwin) | ||
PKG_CONFIG_PATH=$(MAKE_PKG_CONFIG_PATH) \ | ||
CGO_LDFLAGS="-Wl,-rpath,$(LIBGIT2_LIB_PATH)" \ | ||
go build -o bin/manager main.go | ||
else | ||
PKG_CONFIG_PATH=$(MAKE_PKG_CONFIG_PATH) \ | ||
go build -o bin/manager main.go | ||
endif | ||
|
||
KUBEBUILDER_ASSETS?="$(shell $(ENVTEST) --arch=$(ENVTEST_ARCH) use -i $(ENVTEST_KUBERNETES_VERSION) --bin-dir=$(ENVTEST_ASSETS_DIR) -p path)" | ||
|
||
test: $(LIBGIT2) install-envtest test-api ## Run tests | ||
ifeq ($(shell uname -s),Darwin) | ||
LD_LIBRARY_PATH=$(LIBGIT2_LIB_PATH) \ | ||
PKG_CONFIG_PATH=$(MAKE_PKG_CONFIG_PATH) \ | ||
CGO_LDFLAGS="-Wl,-rpath,$(LIBGIT2_LIB_PATH)" \ | ||
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) \ | ||
go test ./... -coverprofile cover.out | ||
else | ||
LD_LIBRARY_PATH=$(LIBGIT2_LIB_PATH) \ | ||
PKG_CONFIG_PATH=$(MAKE_PKG_CONFIG_PATH) \ | ||
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) \ | ||
go test ./... -coverprofile cover.out | ||
endif | ||
go test ./... \ | ||
-ldflags "-s -w" \ | ||
-coverprofile cover.out \ | ||
-tags 'netgo,osusergo,static_build' | ||
|
||
test-api: ## Run api tests | ||
cd api; go test ./... -coverprofile cover.out | ||
|
||
run: $(LIBGIT2) generate fmt vet manifests ## Run against the configured Kubernetes cluster in ~/.kube/config | ||
ifeq ($(shell uname -s),Darwin) | ||
LD_LIBRARY_PATH=$(LIBGIT2_LIB_PATH) \ | ||
CGO_LDFLAGS="-Wl,-rpath,$(LIBGIT2_LIB_PATH)" \ | ||
go run ./main.go | ||
else | ||
LD_LIBRARY_PATH=$(LIBGIT2_LIB_PATH) \ | ||
go run ./main.go | ||
endif | ||
|
||
|
||
install: manifests ## Install CRDs into a cluster | ||
kustomize build config/crd | kubectl apply -f - | ||
|
@@ -142,16 +105,8 @@ fmt: ## Run go fmt against code | |
cd api; go fmt ./... | ||
|
||
vet: $(LIBGIT2) ## Run go vet against code | ||
ifeq ($(shell uname -s),Darwin) | ||
PKG_CONFIG_PATH=$(MAKE_PKG_CONFIG_PATH) \ | ||
CGO_LDFLAGS="-Wl,-rpath,$(LIBGIT2_LIB_PATH)" \ | ||
go vet ./... | ||
cd api; go vet ./... | ||
else | ||
PKG_CONFIG_PATH=$(MAKE_PKG_CONFIG_PATH) \ | ||
go vet ./... | ||
cd api; go vet ./... | ||
endif | ||
|
||
generate: controller-gen ## Generate API code | ||
cd api; $(CONTROLLER_GEN) object:headerFile="../hack/boilerplate.go.txt" paths="./..." | ||
|
@@ -193,14 +148,8 @@ install-envtest: setup-envtest ## Download envtest binaries locally. | |
libgit2: $(LIBGIT2) ## Detect or download libgit2 library | ||
|
||
$(LIBGIT2): | ||
ifeq (1, $(LIBGIT2_FORCE)) | ||
@{ \ | ||
set -e; \ | ||
mkdir -p $(LIBGIT2_PATH); \ | ||
curl -sL https://raw.githubusercontent.com/fluxcd/golang-with-libgit2/$(LIBGIT2_TAG)/hack/Makefile -o $(LIBGIT2_PATH)/Makefile; \ | ||
INSTALL_PREFIX=$(LIBGIT2_PATH) make -C $(LIBGIT2_PATH) libgit2; \ | ||
} | ||
endif | ||
IMG_TAG=$(LIBGIT2_IMG):$(LIBGIT2_TAG) ./hack/extract-libraries.sh | ||
|
||
|
||
.PHONY: help | ||
help: ## Display this help menu | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euxo pipefail | ||
|
||
IMG_TAG="${IMG_TAG:-.}" | ||
|
||
function extract(){ | ||
PLATFORM=$1 | ||
DIR=$2 | ||
|
||
id=$(docker create --platform="${PLATFORM}" "${IMG_TAG}") | ||
docker cp "${id}":/usr/local - > output.tar.gz | ||
docker rm -v "${id}" | ||
|
||
tar -xf output.tar.gz "local/${DIR}" | ||
rm output.tar.gz | ||
} | ||
|
||
function setup() { | ||
PLATFORM=$1 | ||
DIR=$2 | ||
|
||
extract "${PLATFORM}" "${DIR}" | ||
|
||
NEW_DIR="$(/bin/pwd)/build/libgit2" | ||
INSTALLED_DIR="/usr/local/${DIR}" | ||
|
||
mkdir -p "./build" | ||
|
||
# Make a few movements to account for the change in | ||
# behaviour in tar between MacOS and Linux | ||
mv "local/${DIR}" "libgit2" | ||
rm -rf "local" | ||
mv "libgit2/" "./build" | ||
|
||
# Update the prefix paths included in the .pc files. | ||
# This will make it easier to update to the location in which they will be used. | ||
if [[ $OSTYPE == 'darwin'* ]]; then | ||
# sed has a sight different behaviour in MacOS | ||
find "${NEW_DIR}" -type f -name "*.pc" | xargs -I {} sed -i "" "s;${INSTALLED_DIR};${NEW_DIR};g" {} | ||
else | ||
find "${NEW_DIR}" -type f -name "*.pc" | xargs -I {} sed -i "s;${INSTALLED_DIR};${NEW_DIR};g" {} | ||
fi | ||
} | ||
|
||
function setup_current() { | ||
if [ -d "./build/libgit2" ]; then | ||
echo "Skipping libgit2 setup as it already exists" | ||
exit 0 | ||
fi | ||
|
||
DIR="x86_64-alpine-linux-musl" | ||
PLATFORM="linux/amd64" | ||
|
||
if [[ "$(uname -m)" == armv7* ]]; then | ||
DIR="armv7-alpine-linux-musleabihf" | ||
PLATFORM="linux/arm/v7" | ||
elif [ "$(uname -m)" = "arm64" ] || [ "$(uname -m)" = "aarch64" ]; then | ||
DIR="aarch64-alpine-linux-musl" | ||
PLATFORM="linux/arm64" | ||
fi | ||
|
||
setup "${PLATFORM}" "${DIR}" | ||
} | ||
|
||
setup_current |