Skip to content

Commit

Permalink
handler: Install nmstate from proper arch (#1188)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
qinqon authored May 17, 2023
1 parent e6bb778 commit 05659df
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion automation/check-patch.setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
1 change: 1 addition & 0 deletions automation/check-patch.unit-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions automation/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions automation/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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} \
Expand Down
4 changes: 2 additions & 2 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions build/Dockerfile.operator
Original file line number Diff line number Diff line change
@@ -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

Expand Down
5 changes: 5 additions & 0 deletions hack/build-push-container.docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions hack/build-push-container.podman.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
12 changes: 12 additions & 0 deletions hack/qemu-user-static.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 05659df

Please sign in to comment.