Update test to run against static libraries
Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
This commit is contained in:
parent
01a2eaac8c
commit
b343008a94
|
@ -1,35 +0,0 @@
|
||||||
ARG BASE_VARIANT=bullseye
|
|
||||||
ARG GO_VERSION=1.17
|
|
||||||
ARG XX_VERSION=1.1.0
|
|
||||||
|
|
||||||
ARG LIBGIT2_IMG=ghcr.io/fluxcd/golang-with-libgit2
|
|
||||||
ARG LIBGIT2_TAG=libgit2-1.1.1-4
|
|
||||||
|
|
||||||
FROM tonistiigi/xx:${XX_VERSION} AS xx
|
|
||||||
FROM ${LIBGIT2_IMG}:${LIBGIT2_TAG} as libgit2
|
|
||||||
|
|
||||||
FROM golang:${GO_VERSION}-${BASE_VARIANT} as gostable
|
|
||||||
|
|
||||||
# Copy the build utiltiies
|
|
||||||
COPY --from=xx / /
|
|
||||||
COPY --from=libgit2 /Makefile /libgit2/
|
|
||||||
|
|
||||||
# Install the libgit2 build dependencies
|
|
||||||
RUN make -C /libgit2 cmake
|
|
||||||
|
|
||||||
RUN make -C /libgit2 dependencies
|
|
||||||
|
|
||||||
# Compile and install libgit2
|
|
||||||
RUN FLAGS=$(xx-clang --print-cmake-defines) make -C /libgit2 libgit2
|
|
||||||
|
|
||||||
# Use the GitHub Actions uid:gid combination for proper fs permissions
|
|
||||||
RUN groupadd -g 116 test && \
|
|
||||||
useradd -u 1001 --gid test --shell /bin/sh --create-home test
|
|
||||||
|
|
||||||
# Run as test user
|
|
||||||
USER test
|
|
||||||
|
|
||||||
# Set path to envtest binaries.
|
|
||||||
ENV PATH="/github/workspace/envtest:${PATH}"
|
|
||||||
|
|
||||||
ENTRYPOINT ["/bin/sh", "-c"]
|
|
|
@ -1,12 +0,0 @@
|
||||||
name: 'Run tests'
|
|
||||||
description: 'Run tests in docker container'
|
|
||||||
inputs:
|
|
||||||
command:
|
|
||||||
description: 'Command to run inside the container'
|
|
||||||
required: true
|
|
||||||
default: 'make test'
|
|
||||||
runs:
|
|
||||||
using: 'docker'
|
|
||||||
image: 'Dockerfile'
|
|
||||||
args:
|
|
||||||
- ${{ inputs.command }}
|
|
|
@ -1,5 +1,4 @@
|
||||||
name: build
|
name: build
|
||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
push:
|
push:
|
||||||
|
@ -10,11 +9,15 @@ permissions:
|
||||||
contents: read # for actions/checkout to fetch code
|
contents: read # for actions/checkout to fetch code
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test-linux-amd64:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: checkout
|
- name: checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
- name: Setup Go
|
||||||
|
uses: actions/setup-go@v2
|
||||||
|
with:
|
||||||
|
go-version: 1.17.x
|
||||||
- name: Restore go cache
|
- name: Restore go cache
|
||||||
uses: actions/cache@v1
|
uses: actions/cache@v1
|
||||||
with:
|
with:
|
||||||
|
@ -24,8 +27,6 @@ jobs:
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-go-
|
${{ runner.os }}-go-
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
uses: ./.github/actions/run-tests
|
run: make test
|
||||||
env:
|
|
||||||
GOPATH: /github/home/go
|
|
||||||
- name: Verify
|
- name: Verify
|
||||||
run: make verify
|
run: make verify
|
||||||
|
|
|
@ -31,3 +31,4 @@ testbin
|
||||||
|
|
||||||
# Exclude all libgit2 related files
|
# Exclude all libgit2 related files
|
||||||
hack/libgit2/
|
hack/libgit2/
|
||||||
|
build/
|
||||||
|
|
83
Makefile
83
Makefile
|
@ -27,30 +27,23 @@ SOURCE_VER ?= v0.21.0
|
||||||
# Change this if you bump the image-reflector-controller/api version in go.mod.
|
# Change this if you bump the image-reflector-controller/api version in go.mod.
|
||||||
REFLECTOR_VER ?= v0.15.0
|
REFLECTOR_VER ?= v0.15.0
|
||||||
|
|
||||||
# Version of libgit2 the controller should depend on.
|
|
||||||
LIBGIT2_VERSION ?= 1.1.1
|
|
||||||
|
|
||||||
# Repository root based on Git metadata.
|
# Repository root based on Git metadata.
|
||||||
REPOSITORY_ROOT := $(shell git rev-parse --show-toplevel)
|
REPOSITORY_ROOT := $(shell git rev-parse --show-toplevel)
|
||||||
|
|
||||||
# libgit2 related magical paths
|
LIBGIT2_PATH := $(REPOSITORY_ROOT)/build/libgit2
|
||||||
# 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
|
|
||||||
LIBGIT2_LIB_PATH := $(LIBGIT2_PATH)/lib
|
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))
|
export CGO_ENABLED=1
|
||||||
LIBGIT2_FORCE ?= 1
|
export LIBRARY_PATH=$(LIBGIT2_LIB_PATH):$(LIBGIT2_LIB64_PATH)
|
||||||
endif
|
export PKG_CONFIG_PATH=$(LIBGIT2_LIB_PATH)/pkgconfig:$(LIBGIT2_LIB64_PATH)/pkgconfig
|
||||||
|
export CGO_CFLAGS=-I$(LIBGIT2_PATH)/include
|
||||||
|
|
||||||
ifeq ($(shell uname -s),Darwin)
|
ifeq ($(shell uname -s),Darwin)
|
||||||
LIBGIT2 := $(LIBGIT2_LIB_PATH)/libgit2.$(LIBGIT2_VERSION).dylib
|
export CGO_LDFLAGS=-L$(LIBGIT2_LIB_PATH) -lssh2 -lssl -lcrypto -lgit2
|
||||||
HAS_BREW := $(shell brew --version 2>/dev/null)
|
else
|
||||||
ifdef HAS_BREW
|
export CGO_LDFLAGS=$(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) pkg-config --libs --static --cflags libssh2 openssl libgit2)
|
||||||
HAS_OPENSSL := $(shell brew --prefix openssl@1.1)
|
|
||||||
endif
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
|
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
|
||||||
|
@ -60,15 +53,6 @@ else
|
||||||
GOBIN=$(shell go env GOBIN)
|
GOBIN=$(shell go env GOBIN)
|
||||||
endif
|
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
|
|
||||||
|
|
||||||
TEST_CRDS := controllers/testdata/crds
|
TEST_CRDS := controllers/testdata/crds
|
||||||
|
|
||||||
|
@ -106,41 +90,21 @@ ${CACHE}/imagepolicies_${REFLECTOR_VER}.yaml:
|
||||||
|
|
||||||
KUBEBUILDER_ASSETS?="$(shell $(ENVTEST) --arch=$(ENVTEST_ARCH) use -i $(ENVTEST_KUBERNETES_VERSION) --bin-dir=$(ENVTEST_ASSETS_DIR) -p path)"
|
KUBEBUILDER_ASSETS?="$(shell $(ENVTEST) --arch=$(ENVTEST_ARCH) use -i $(ENVTEST_KUBERNETES_VERSION) --bin-dir=$(ENVTEST_ASSETS_DIR) -p path)"
|
||||||
test: $(LIBGIT2) test-api test_deps generate fmt vet manifests api-docs install-envtest ## Run tests
|
test: $(LIBGIT2) test-api test_deps generate fmt vet manifests api-docs install-envtest ## 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) \
|
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) \
|
||||||
go test ./... -coverprofile cover.out
|
go test ./... \
|
||||||
else
|
-ldflags "-s -w" \
|
||||||
LD_LIBRARY_PATH=$(LIBGIT2_LIB_PATH) \
|
-coverprofile cover.out \
|
||||||
PKG_CONFIG_PATH=$(MAKE_PKG_CONFIG_PATH) \
|
-tags 'netgo,osusergo,static_build'
|
||||||
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) \
|
|
||||||
go test ./... -coverprofile cover.out
|
|
||||||
endif
|
|
||||||
|
|
||||||
test-api: ## Run api tests
|
test-api: ## Run api tests
|
||||||
cd api; go test ./... -coverprofile cover.out
|
cd api; go test ./... -coverprofile cover.out
|
||||||
|
|
||||||
manager: $(LIBGIT2) generate fmt vet ## Build manager binary
|
manager: $(LIBGIT2) generate fmt vet ## Build manager binary
|
||||||
ifeq ($(shell uname -s),Darwin)
|
go run ./main.go
|
||||||
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) \
|
|
||||||
CGO_LDFLAGS="-Wl,-rpath,$(LIBGIT2_LIB_PATH)" \
|
|
||||||
go build -o bin/manager main.go
|
|
||||||
endif
|
|
||||||
|
|
||||||
|
|
||||||
run: $(LIBGIT2) generate fmt vet manifests # Run against the configured Kubernetes cluster in ~/.kube/config
|
run: $(LIBGIT2) generate fmt vet manifests # Run against the configured Kubernetes cluster in ~/.kube/config
|
||||||
ifeq ($(shell uname -s),Darwin)
|
|
||||||
CGO_LDFLAGS="-Wl,-rpath,$(LIBGIT2_LIB_PATH)" \
|
|
||||||
go run ./main.go --log-level=${LOG_LEVEL} --log-encoding=console
|
go run ./main.go --log-level=${LOG_LEVEL} --log-encoding=console
|
||||||
else
|
|
||||||
go run ./main.go --log-level=${LOG_LEVEL} --log-encoding=console
|
|
||||||
endif
|
|
||||||
|
|
||||||
install: manifests ## Install CRDs into a cluster
|
install: manifests ## Install CRDs into a cluster
|
||||||
kustomize build config/crd | kubectl apply -f -
|
kustomize build config/crd | kubectl apply -f -
|
||||||
|
@ -173,16 +137,8 @@ fmt: ## Run go fmt against code
|
||||||
cd api; go fmt ./...
|
cd api; go fmt ./...
|
||||||
|
|
||||||
vet: $(LIBGIT2) ## Run go vet against code
|
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 ./...
|
go vet ./...
|
||||||
cd api; 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 code
|
generate: controller-gen ## Generate code
|
||||||
|
@ -211,14 +167,7 @@ controller-gen: ## Download controller-gen locally if necessary.
|
||||||
libgit2: $(LIBGIT2) ## Detect or download libgit2 library
|
libgit2: $(LIBGIT2) ## Detect or download libgit2 library
|
||||||
|
|
||||||
$(LIBGIT2):
|
$(LIBGIT2):
|
||||||
ifeq (1, $(LIBGIT2_FORCE))
|
IMG_TAG=$(LIBGIT2_IMG):$(LIBGIT2_TAG) ./hack/extract-libraries.sh
|
||||||
@{ \
|
|
||||||
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
|
|
||||||
|
|
||||||
# Find or download gen-crd-api-reference-docs
|
# Find or download gen-crd-api-reference-docs
|
||||||
GEN_CRD_API_REFERENCE_DOCS = $(shell pwd)/bin/gen-crd-api-reference-docs
|
GEN_CRD_API_REFERENCE_DOCS = $(shell pwd)/bin/gen-crd-api-reference-docs
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue