From 22d1e86568fec7343e4ebbf1703b99e18e326642 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Sun, 6 Aug 2023 15:28:08 +0200 Subject: [PATCH] common: rpm-builddep Signed-off-by: CrazyMax --- common/scripts/rpm-builddep.sh | 38 +++++++++++++++++++++++++++++++ pkg/buildx/Dockerfile | 16 ++----------- pkg/compose/Dockerfile | 16 ++----------- pkg/containerd/Dockerfile | 16 ++----------- pkg/credential-helpers/Dockerfile | 16 ++----------- pkg/docker-cli/Dockerfile | 16 ++----------- pkg/docker-engine/Dockerfile | 16 ++----------- pkg/sbom/Dockerfile | 16 ++----------- pkg/scan/Dockerfile | 16 ++----------- 9 files changed, 54 insertions(+), 112 deletions(-) create mode 100755 common/scripts/rpm-builddep.sh diff --git a/common/scripts/rpm-builddep.sh b/common/scripts/rpm-builddep.sh new file mode 100755 index 00000000..4d62b461 --- /dev/null +++ b/common/scripts/rpm-builddep.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +# Copyright 2023 Docker Packaging authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +arch=$1 +specsDir=$2 + +if [[ -z "$arch" ]] || [[ -z "$specsDir" ]]; then + echo "usage: ./rpm-builddep " >&2 + exit 1 +fi + +set -e + +builddepCmd="" +if command -v dnf &> /dev/null; then + builddepCmd="setarch $arch dnf builddep --nobest" +elif command -v yum-builddep &> /dev/null; then + builddepCmd="yum-builddep --target $arch" +else + echo "unable to detect package manager" >&2 + exit 1 +fi + +set -x +$builddepCmd -y "$specsDir"/*.spec diff --git a/pkg/buildx/Dockerfile b/pkg/buildx/Dockerfile index 9da49b6a..9d2e1549 100644 --- a/pkg/buildx/Dockerfile +++ b/pkg/buildx/Dockerfile @@ -124,20 +124,8 @@ RUN --mount=type=bind,from=common-scripts,source=rpm-init.sh,target=/usr/local/b rpm-init $PKG_RELEASE COPY rpm /root/rpmbuild/SPECS ARG TARGETPLATFORM -RUN < /dev/null; then - builddepCmd="setarch $(xx-info rhel-arch) dnf builddep --nobest" - elif command -v yum-builddep &> /dev/null; then - builddepCmd="yum-builddep --target $(xx-info rhel-arch)" - else - echo >&2 "unable to detect package manager" - exit 1 - fi - set -x - $builddepCmd -y /root/rpmbuild/SPECS/*.spec -EOT +RUN --mount=type=bind,from=common-scripts,source=rpm-builddep.sh,target=/usr/local/bin/rpm-builddep \ + rpm-builddep $(xx-info rhel-arch) /root/rpmbuild/SPECS WORKDIR /root/rpmbuild ARG BUILDX_REF ARG NIGHTLY_BUILD diff --git a/pkg/compose/Dockerfile b/pkg/compose/Dockerfile index dfc0feb2..b925b9e2 100644 --- a/pkg/compose/Dockerfile +++ b/pkg/compose/Dockerfile @@ -127,20 +127,8 @@ RUN --mount=type=bind,from=common-scripts,source=rpm-init.sh,target=/usr/local/b rpm-init $PKG_RELEASE COPY rpm /root/rpmbuild/SPECS ARG TARGETPLATFORM -RUN < /dev/null; then - builddepCmd="setarch $(xx-info rhel-arch) dnf builddep --nobest" - elif command -v yum-builddep &> /dev/null; then - builddepCmd="yum-builddep --target $(xx-info rhel-arch)" - else - echo >&2 "unable to detect package manager" - exit 1 - fi - set -x - $builddepCmd -y /root/rpmbuild/SPECS/*.spec -EOT +RUN --mount=type=bind,from=common-scripts,source=rpm-builddep.sh,target=/usr/local/bin/rpm-builddep \ + rpm-builddep $(xx-info rhel-arch) /root/rpmbuild/SPECS WORKDIR /root/rpmbuild ARG COMPOSE_REF ARG NIGHTLY_BUILD diff --git a/pkg/containerd/Dockerfile b/pkg/containerd/Dockerfile index 6720ccd7..6a1a8673 100644 --- a/pkg/containerd/Dockerfile +++ b/pkg/containerd/Dockerfile @@ -161,20 +161,8 @@ RUN --mount=type=bind,from=common-scripts,source=rpm-init.sh,target=/usr/local/b rpm-init $PKG_RELEASE COPY rpm /root/rpmbuild/SPECS ARG TARGETPLATFORM -RUN < /dev/null; then - builddepCmd="setarch $(xx-info rhel-arch) dnf builddep --nobest" - elif command -v yum-builddep &> /dev/null; then - builddepCmd="yum-builddep --target $(xx-info rhel-arch)" - else - echo >&2 "unable to detect package manager" - exit 1 - fi - set -x - $builddepCmd -y /root/rpmbuild/SPECS/*.spec -EOT +RUN --mount=type=bind,from=common-scripts,source=rpm-builddep.sh,target=/usr/local/bin/rpm-builddep \ + rpm-builddep $(xx-info rhel-arch) /root/rpmbuild/SPECS WORKDIR /root/rpmbuild ARG CONTAINERD_REF ARG NIGHTLY_BUILD diff --git a/pkg/credential-helpers/Dockerfile b/pkg/credential-helpers/Dockerfile index c37b1cdb..b4314549 100644 --- a/pkg/credential-helpers/Dockerfile +++ b/pkg/credential-helpers/Dockerfile @@ -124,20 +124,8 @@ RUN --mount=type=bind,from=common-scripts,source=rpm-init.sh,target=/usr/local/b rpm-init $PKG_RELEASE COPY rpm /root/rpmbuild/SPECS ARG TARGETPLATFORM -RUN < /dev/null; then - builddepCmd="setarch $(xx-info rhel-arch) dnf builddep --nobest" - elif command -v yum-builddep &> /dev/null; then - builddepCmd="yum-builddep --target $(xx-info rhel-arch)" - else - echo >&2 "unable to detect package manager" - exit 1 - fi - set -x - $builddepCmd -y /root/rpmbuild/SPECS/*.spec -EOT +RUN --mount=type=bind,from=common-scripts,source=rpm-builddep.sh,target=/usr/local/bin/rpm-builddep \ + rpm-builddep $(xx-info rhel-arch) /root/rpmbuild/SPECS WORKDIR /root/rpmbuild ARG CREDENTIAL_HELPERS_REF ARG NIGHTLY_BUILD diff --git a/pkg/docker-cli/Dockerfile b/pkg/docker-cli/Dockerfile index d91360e8..712be4a7 100644 --- a/pkg/docker-cli/Dockerfile +++ b/pkg/docker-cli/Dockerfile @@ -139,20 +139,8 @@ RUN --mount=type=bind,from=common-scripts,source=rpm-init.sh,target=/usr/local/b rpm-init $PKG_RELEASE COPY rpm /root/rpmbuild/SPECS ARG TARGETPLATFORM -RUN < /dev/null; then - builddepCmd="setarch $(xx-info rhel-arch) dnf builddep --nobest" - elif command -v yum-builddep &> /dev/null; then - builddepCmd="yum-builddep --target $(xx-info rhel-arch)" - else - echo >&2 "unable to detect package manager" - exit 1 - fi - set -x - $builddepCmd -y /root/rpmbuild/SPECS/*.spec -EOT +RUN --mount=type=bind,from=common-scripts,source=rpm-builddep.sh,target=/usr/local/bin/rpm-builddep \ + rpm-builddep $(xx-info rhel-arch) /root/rpmbuild/SPECS WORKDIR /root/rpmbuild ARG DOCKER_CLI_REF ARG NIGHTLY_BUILD diff --git a/pkg/docker-engine/Dockerfile b/pkg/docker-engine/Dockerfile index b3dadd97..4964e18f 100644 --- a/pkg/docker-engine/Dockerfile +++ b/pkg/docker-engine/Dockerfile @@ -141,20 +141,8 @@ RUN --mount=type=bind,from=common-scripts,source=rpm-init.sh,target=/usr/local/b rpm-init $PKG_RELEASE COPY rpm /root/rpmbuild/SPECS ARG TARGETPLATFORM -RUN < /dev/null; then - builddepCmd="setarch $(xx-info rhel-arch) dnf builddep --nobest" - elif command -v yum-builddep &> /dev/null; then - builddepCmd="yum-builddep --target $(xx-info rhel-arch)" - else - echo >&2 "unable to detect package manager" - exit 1 - fi - set -x - $builddepCmd -y /root/rpmbuild/SPECS/*.spec -EOT +RUN --mount=type=bind,from=common-scripts,source=rpm-builddep.sh,target=/usr/local/bin/rpm-builddep \ + rpm-builddep $(xx-info rhel-arch) /root/rpmbuild/SPECS WORKDIR /root/rpmbuild ARG DOCKER_ENGINE_REF ARG NIGHTLY_BUILD diff --git a/pkg/sbom/Dockerfile b/pkg/sbom/Dockerfile index 1e9d7373..e8878717 100644 --- a/pkg/sbom/Dockerfile +++ b/pkg/sbom/Dockerfile @@ -124,20 +124,8 @@ RUN --mount=type=bind,from=common-scripts,source=rpm-init.sh,target=/usr/local/b rpm-init $PKG_RELEASE COPY rpm /root/rpmbuild/SPECS ARG TARGETPLATFORM -RUN < /dev/null; then - builddepCmd="setarch $(xx-info rhel-arch) dnf builddep --nobest" - elif command -v yum-builddep &> /dev/null; then - builddepCmd="yum-builddep --target $(xx-info rhel-arch)" - else - echo >&2 "unable to detect package manager" - exit 1 - fi - set -x - $builddepCmd -y /root/rpmbuild/SPECS/*.spec -EOT +RUN --mount=type=bind,from=common-scripts,source=rpm-builddep.sh,target=/usr/local/bin/rpm-builddep \ + rpm-builddep $(xx-info rhel-arch) /root/rpmbuild/SPECS WORKDIR /root/rpmbuild ARG SBOM_REF ARG NIGHTLY_BUILD diff --git a/pkg/scan/Dockerfile b/pkg/scan/Dockerfile index ca426c45..ce020410 100644 --- a/pkg/scan/Dockerfile +++ b/pkg/scan/Dockerfile @@ -124,20 +124,8 @@ RUN --mount=type=bind,from=common-scripts,source=rpm-init.sh,target=/usr/local/b rpm-init $PKG_RELEASE COPY rpm /root/rpmbuild/SPECS ARG TARGETPLATFORM -RUN < /dev/null; then - builddepCmd="setarch $(xx-info rhel-arch) dnf builddep --nobest" - elif command -v yum-builddep &> /dev/null; then - builddepCmd="yum-builddep --target $(xx-info rhel-arch)" - else - echo >&2 "unable to detect package manager" - exit 1 - fi - set -x - $builddepCmd -y /root/rpmbuild/SPECS/*.spec -EOT +RUN --mount=type=bind,from=common-scripts,source=rpm-builddep.sh,target=/usr/local/bin/rpm-builddep \ + rpm-builddep $(xx-info rhel-arch) /root/rpmbuild/SPECS WORKDIR /root/rpmbuild ARG SCAN_REF ARG NIGHTLY_BUILD