Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/build_rpm_from_dir
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash
set -euo pipefail

srcdir=$1; shift
name=$1; shift
outdir=$1; shift

sha256=$(cd "${srcdir}" && find . ! -type d -print0 | xargs -0 -r sha256sum \
| sha256sum | cut -f 1 -d ' ')

latest_rpm=$(find "$outdir/" -iname "$name-*.rpm" | sort -Vr | head -n 1)

if rpm -qp "$latest_rpm" --qf '%{DESCRIPTION}' | grep -q "(sha256:$sha256)"; then
echo "Re-using ${latest_rpm} ($sha256)."
exit 0
fi

# shellcheck disable=SC2154
cat > "$name.spec" << EOF
Name: $name
Version: $(date +%s)
Release: ${sha256::7}
BuildArch: noarch
Summary: $summary overlay
License: $license
# this shows up then in rpm -qi (XXX: don't hardcode this)
URL: https://github.com/coreos/fedora-coreos-config

BuildRequires: rsync

%description
%{summary} (sha256:$sha256)

%build
# Nothing to build

%install
rsync -av "${srcdir}/" %{buildroot}

%files
$(cd "${srcdir}" && find . ! -type d | cut -c 2-)
EOF

rm -rf rpms
rpmbuild -ba \
--define "_sourcedir $PWD" \
--define "_specdir $PWD" \
--define "_builddir $PWD/.build" \
--define "_srcrpmdir $PWD/rpms" \
--define "_rpmdir $PWD/rpms" \
--define "_buildrootdir $PWD/.buildroot" "$name.spec"
cp rpms/noarch/*.rpm "$outdir"
13 changes: 11 additions & 2 deletions src/cmdlib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,14 @@ prepare_build() {
# Also grab rojig summary for image upload descriptions
name=$(jq -r '.rojig.name' < "${manifest_tmp_json}")
summary=$(jq -r '.rojig.summary' < "${manifest_tmp_json}")
license=$(jq -r '.rojig.license' < "${manifest_tmp_json}")
ref=$(jq -r '.ref' < "${manifest_tmp_json}")
ref_is_temp=""
if [ "${ref}" = "null" ]; then
ref="tmpref-${name}"
ref_is_temp=1
fi
export name ref summary
export name ref summary license
rm -f "${manifest_tmp_json}"

# This dir is no longer used
Expand Down Expand Up @@ -182,7 +183,7 @@ runcompose() {
local overridesdir=${workdir}/overrides
local tmp_overridesdir=${TMPDIR}/override
local override_manifest="${tmp_overridesdir}"/coreos-assembler-override-manifest.yaml
if [ -d "${overridesdir}"/rpm ] || [ -n "${ref_is_temp}" ]; then
if [ -d "${overridesdir}"/rpm ] || [ -n "${ref_is_temp}" ] || [ -d "${configdir}/overlay" ]; then
mkdir "${tmp_overridesdir}"
cat > "${override_manifest}" <<EOF
include: ${workdir}/src/config/manifest.yaml
Expand All @@ -196,6 +197,14 @@ EOF
if [ -n "${ref_is_temp}" ]; then
echo 'ref: "'"${ref}"'"' >> "${override_manifest}"
fi
if [ -d "${configdir}/overlay" ]; then
cat >> "${override_manifest}" <<EOF
packages:
- ${name}-overlay
EOF
mkdir tmp/overlay-build
(cd tmp/overlay-build && "${DIR}"/build_rpm_from_dir "${configdir}/overlay" "${name}-overlay" "${workdir}/overrides/rpm")
fi
if [ -d "${overridesdir}"/rpm ]; then
(cd "${overridesdir}"/rpm && createrepo_c .)
echo "Using RPM overrides from: ${overridesdir}/rpm"
Expand Down