From 05659dfce0da0fe032f93d02140b547fefa4b974 Mon Sep 17 00:00:00 2001 From: Enrique Llorente Pastora Date: Wed, 17 May 2023 17:32:39 +0200 Subject: [PATCH] handler: Install nmstate from proper arch (#1188) The handler was installing a amd64 image, this change remove the optimization of forcing the platform at build stage to do crosscompiling so last stage is using the proper architecture, this way the rpm is installed from the proper arch. Signed-off-by: Enrique Llorente --- Makefile | 2 +- automation/check-patch.setup.sh | 1 - automation/check-patch.unit-test.sh | 1 + automation/publish.sh | 1 + automation/release.sh | 1 + build/Dockerfile | 4 ++-- build/Dockerfile.operator | 4 ++-- hack/build-push-container.docker.sh | 5 +++++ hack/build-push-container.podman.sh | 4 ++++ hack/qemu-user-static.sh | 12 ++++++++++++ 10 files changed, 29 insertions(+), 6 deletions(-) create mode 100755 hack/qemu-user-static.sh diff --git a/Makefile b/Makefile index fafa4201e0..b4e09862ec 100644 --- a/Makefile +++ b/Makefile @@ -91,7 +91,7 @@ INDEX_IMG ?= $(IMAGE_REGISTRY)/$(IMAGE_REPO)/kubernetes-nmstate-operator-index:$ SKIP_IMAGE_BUILD ?= false -all: check handler +all: check handler operator check: lint vet whitespace-check gofmt-check diff --git a/automation/check-patch.setup.sh b/automation/check-patch.setup.sh index 2f57e081f9..2c0d7a3ddb 100755 --- a/automation/check-patch.setup.sh +++ b/automation/check-patch.setup.sh @@ -16,7 +16,6 @@ else echo "Gimme not installed using existing golang version $(go --version)" fi -export ARCHS="amd64 arm64" export TMP_PROJECT_PATH=$tmp_dir/kubernetes-nmstate export E2E_LOGS=${TMP_PROJECT_PATH}/test_logs/e2e export ARTIFACTS=${ARTIFACTS-$tmp_dir/artifacts} diff --git a/automation/check-patch.unit-test.sh b/automation/check-patch.unit-test.sh index 1c01fa922e..a408bc4430 100755 --- a/automation/check-patch.unit-test.sh +++ b/automation/check-patch.unit-test.sh @@ -10,6 +10,7 @@ main() { source automation/check-patch.setup.sh cd ${TMP_PROJECT_PATH} + export ARCHS="amd64 arm64" make all make UNIT_TEST_ARGS="--output-dir=$ARTIFACTS --no-color --compilers=2" test/unit } diff --git a/automation/publish.sh b/automation/publish.sh index 4c38b22140..c614b4908f 100755 --- a/automation/publish.sh +++ b/automation/publish.sh @@ -12,6 +12,7 @@ image_registry=${IMAGE_REGISTRY:-quay.io} image_repo=${IMAGE_REPO:-nmstate} source automation/check-patch.setup.sh +export ARCHS="amd64 arm64" cd ${TMP_PROJECT_PATH} push_knmstate_containers() { diff --git a/automation/release.sh b/automation/release.sh index 14728b8090..17836122b7 100755 --- a/automation/release.sh +++ b/automation/release.sh @@ -10,6 +10,7 @@ git config credential.helper '!f() { sleep 1; echo "username=${GITHUB_USER}"; echo "password=${GITHUB_TOKEN}"; }; f' source automation/check-patch.setup.sh +export ARCHS="amd64 arm64" cd ${TMP_PROJECT_PATH} make \ IMAGE_REGISTRY=${IMAGE_REGISTRY:-quay.io} \ diff --git a/build/Dockerfile b/build/Dockerfile index 8dae4a9434..2a8e008be8 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -1,9 +1,9 @@ ARG GO_VERSION=1.18 -FROM --platform=linux/amd64 registry.access.redhat.com/ubi9/go-toolset:${GO_VERSION} AS build +FROM registry.access.redhat.com/ubi9/go-toolset:${GO_VERSION} AS build COPY . . -RUN --mount=type=cache,target=/root/.cache/go-build CGO_ENABLED=false GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o manager ./cmd/handler +RUN --mount=type=cache,target=/root/.cache/go-build CGO_ENABLED=false go build -o manager ./cmd/handler FROM quay.io/centos/centos:stream9 diff --git a/build/Dockerfile.operator b/build/Dockerfile.operator index bbe56681df..0d8aa2002e 100644 --- a/build/Dockerfile.operator +++ b/build/Dockerfile.operator @@ -1,9 +1,9 @@ ARG GO_VERSION=1.18 -FROM --platform=linux/amd64 registry.access.redhat.com/ubi9/go-toolset:${GO_VERSION} AS build +FROM registry.access.redhat.com/ubi9/go-toolset:${GO_VERSION} AS build COPY . . -RUN --mount=type=cache,target=/root/.cache/go-build CGO_ENABLED=false GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o manager ./cmd/operator +RUN --mount=type=cache,target=/root/.cache/go-build CGO_ENABLED=false go build -o manager ./cmd/operator FROM registry.access.redhat.com/ubi9/ubi-minimal diff --git a/hack/build-push-container.docker.sh b/hack/build-push-container.docker.sh index c483870af5..f80c33f9d6 100755 --- a/hack/build-push-container.docker.sh +++ b/hack/build-push-container.docker.sh @@ -10,6 +10,11 @@ fi hack/init-buildx.sh ARCHS=${ARCHS:-$(go env GOARCH)} + +if [ "${ARCHS}" != "$(go env GOARCH)" ]; then + hack/qemu-user-static.sh +fi + PLATFORM="" for arch in $ARCHS; do diff --git a/hack/build-push-container.podman.sh b/hack/build-push-container.podman.sh index 787601a68c..83c9cea846 100755 --- a/hack/build-push-container.podman.sh +++ b/hack/build-push-container.podman.sh @@ -14,6 +14,10 @@ fi ARCHS=${ARCHS:-$(go env GOARCH)} +if [ "${ARCHS}" != "$(go env GOARCH)" ]; then + hack/qemu-user-static.sh +fi + buildah rmi ${IMAGE} 2>/dev/null || true buildah manifest rm ${IMAGE} 2>/dev/null || true buildah manifest create ${IMAGE} diff --git a/hack/qemu-user-static.sh b/hack/qemu-user-static.sh new file mode 100755 index 0000000000..fd2aa48437 --- /dev/null +++ b/hack/qemu-user-static.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +set -xe + +# If qemu-static has already been registered as a runner for foreign +# binaries, for example by installing qemu-user and qemu-user-binfmt +# packages on Fedora or by having already run this script earlier, +# then we shouldn't alter the existing configuration to avoid the +# risk of possibly breaking it +if ! grep -E '^enabled$' /proc/sys/fs/binfmt_misc/qemu-aarch64 2>/dev/null; then + ${IMAGE_BUILDER} run --rm --privileged multiarch/qemu-user-static --reset -p yes +fi