From 5be7bae0900a622e83c3f9e629cefdedb7a496e2 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Fri, 12 Jun 2020 08:50:48 +0200 Subject: [PATCH] add RPMBUILD_BASE_DIR to configure the base dir used for rpmbuild --- Dockerfile | 5 ++++- README.md | 18 ++++++++++++------ overlay/usr/local/bin/rpmbuild | 11 +++++++---- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4e1a1e3..c2da798 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,6 +6,8 @@ LABEL maintainer="Robert Kaussow " \ org.label-schema.vendor="Robert Kaussow" \ org.label-schema.schema-version="1.0" +ENV RPMBUILD_BASE_DIR=/drone/src + RUN yum install -q -y \ dash \ gcc gcc-c++ \ @@ -35,11 +37,12 @@ RUN yum install -q -y \ yum-utils rpm-build rpmdevtools \ epel-release && \ rpm --import https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7 && \ + ln -s dash /bin/sh && \ yum clean all ADD overlay/ / USER root -WORKDIR /drone/src +WORKDIR ${RPMBUILD_BASE_DIR} CMD [] diff --git a/README.md b/README.md index be83585..2ef0f3a 100644 --- a/README.md +++ b/README.md @@ -6,18 +6,24 @@ Simple Docker image based on CentOS 7 to build RPM packages. +## Environment variables + +```Shell +RPMBUILD_BASE_DIR=/drone/src +``` + ## How to use There are two wrapper scripts around the rpmbuild command you could use: -- `/bin/rpmbuild-official`: This will simply forward your command to the official binary at `/usr/bin/rpmbuild` -- `/bin/rpmbuil`: This is a modified wrapper to prepare the environment before calling rpmbuil +- `/usr/local/bin/rpmbuild-official`: This will simply forward your command to the official binary at `/usr/bin/rpmbuild` +- `/usr/local/bin/rpmbuil`: This is a modified wrapper to prepare the environment before calling rpmbuil -The wrapper `/bin/rpmbuil` will do the following: +The wrapper `/usr/local/bin/rpmbuil` will do the following: -- create `$(pwd)/dist` -- create rpmbuild folder structure (`BUILDRPMS|SOURCES|SPECS|SRPMS`) under `$(pwd)/dist` -- sync local patchfiles from `$(pwd)/patch` to `$(pwd)/dist/SOURCES` +- create `$RPMBUILD_BASE_DIR/dist` +- create rpmbuild folder structure (`BUILDRPMS|SOURCES|SPECS|SRPMS`) under `$RPMBUILD_BASE_DIR/dist` +- sync local patchfiles from `$RPMBUILD_BASE_DIR/patch` to `$RPMBUILD_BASE_DIR/dist/SOURCES` if the `patch` folder exist - call `/bin/rpmbuil` with the given parameters ## License diff --git a/overlay/usr/local/bin/rpmbuild b/overlay/usr/local/bin/rpmbuild index 7ecc6fe..df5b6b9 100755 --- a/overlay/usr/local/bin/rpmbuild +++ b/overlay/usr/local/bin/rpmbuild @@ -1,11 +1,14 @@ #!/usr/bin/env sh set -eo pipefail -DIR=$(pwd) +mkdir -p "${RPMBUILD_BASE_DIR%/}/dist" +mkdir -p "${RPMBUILD_BASE_DIR%/}/dist" -mkdir -p ./dist -echo '%_topdir '"${DIR%/}"'/dist' > /root/.rpmmacros +echo '%_topdir '"${RPMBUILD_BASE_DIR%/}"'/dist' > /root/.rpmmacros rpmdev-setuptree -rsync -q -av "${DIR%/}/patch/" "${DIR%/}/dist/SOURCES" + +if [ -d "$DIR" ]; then + rsync -q -av "${RPMBUILD_BASE_DIR%/}/patch/" "${RPMBUILD_BASE_DIR%/}/dist/SOURCES" +fi exec /usr/bin/rpmbuild "$@"