diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 761d312..880993c 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -28,11 +28,16 @@ jobs: run: cargo clippy --all --tests --all-features --no-deps - name: Build run: cargo build --release - - name: Create Release and Upload Artficat + + - name: Build RPM + if: startsWith(github.ref, 'refs/tags/v') + run: ./build-rpm.sh + + - name: Create Release and Upload Artifacts uses: ncipollo/release-action@v1.14.0 if: startsWith(github.ref, 'refs/tags/v') with: - artifacts: "target/release/bpftop" + artifacts: "target/release/bpftop,*-vendor.tar.gz,bpftop-*.rpm" draft: true allowUpdates: true updateOnlyUnreleased: true diff --git a/.gitignore b/.gitignore index 3f5d4dc..5f7646b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,8 @@ target/ root/ deploy.sh perf.data -flamegraph.svg \ No newline at end of file +flamegraph.svg +vendor/ +*.tar.gz +rpmbuild/ +*.rpm \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index cec7ee3..4188d8b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,10 @@ name = "bpftop" version = "0.5.1" edition = "2021" +description = "Dynamic real-time view of running eBPF programs" +license = "Apache-2.0" +license-file = "LICENSE" +authors = ["Jose Fernandez "] [build-dependencies] libbpf-cargo = "0.23.1" diff --git a/build-rpm.sh b/build-rpm.sh new file mode 100755 index 0000000..cfbbff0 --- /dev/null +++ b/build-rpm.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +IMAGE_NAME="rpm-builder" +CONTAINER_NAME="rpm-builder-container" +VERSION=$(grep -m 1 '^version =' Cargo.toml | sed 's/version = "\(.*\)"/\1/') + +git archive --format=tar.gz --prefix=bpftop-$VERSION/ -o v${VERSION}.tar.gz HEAD + +cargo vendor + +tar -czf v${VERSION}-vendor.tar.gz vendor + +rm -rf vendor + +echo "Building docker image" +docker build --build-arg VERSION=$VERSION -t $IMAGE_NAME -f dockerfiles/Dockerfile.rpm . + +echo "Running docker container" +docker run --privileged --name $CONTAINER_NAME -d $IMAGE_NAME tail -f /dev/null + +echo "Building RPM" +docker exec $CONTAINER_NAME mock -r fedora-40-x86_64 --buildsrpm --spec /home/builder/rpmbuild/SPECS/bpftop.spec --sources /home/builder/rpmbuild/SOURCES --resultdir /home/builder/rpmbuild/SRPMS +docker exec $CONTAINER_NAME mock -r fedora-40-x86_64 --rebuild /home/builder/rpmbuild/SRPMS/bpftop-$VERSION-1.fc40.src.rpm --resultdir /home/builder/rpmbuild/RPMS + +echo "Copying RPM to host" +docker cp $CONTAINER_NAME:/home/builder/rpmbuild/RPMS/bpftop-$VERSION-1.fc40.x86_64.rpm . + +echo "Cleaning up" +docker stop $CONTAINER_NAME +docker rm $CONTAINER_NAME \ No newline at end of file diff --git a/dockerfiles/Dockerfile.rpm b/dockerfiles/Dockerfile.rpm new file mode 100644 index 0000000..2de991b --- /dev/null +++ b/dockerfiles/Dockerfile.rpm @@ -0,0 +1,33 @@ +FROM fedora:latest +RUN dnf install -y dnf-plugins-core \ + mock \ + rpm-build \ + rpmdevtools \ + rust2rpm \ + cargo \ + git \ + sudo \ + wget && \ + dnf clean all + +ARG VERSION + +ENV VERSION=$VERSION + +RUN useradd -m builder + +RUN echo 'builder ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/builder + +RUN usermod -a -G mock builder + +USER builder + +WORKDIR /home/builder + +RUN rpmdev-setuptree + +COPY packaging/rpm/bpftop.spec /home/builder/rpmbuild/SPECS/bpftop.spec +COPY v${VERSION}.tar.gz /home/builder/rpmbuild/SOURCES/ +COPY v${VERSION}-vendor.tar.gz /home/builder/rpmbuild/SOURCES/ + +ENTRYPOINT ["/bin/bash"] diff --git a/packaging/rpm/bpftop.spec b/packaging/rpm/bpftop.spec new file mode 100644 index 0000000..8ecd194 --- /dev/null +++ b/packaging/rpm/bpftop.spec @@ -0,0 +1,75 @@ +# Generated by rust2rpm 26 +%bcond_without check + +# prevent library files from being installed +%global cargo_install_lib 0 + +Name: bpftop +Version: 0.5.1 +Release: %autorelease +Summary: Dynamic real-time view of running eBPF programs + +SourceLicense: Apache-2.0 +# 0BSD OR MIT OR Apache-2.0 +# Apache-2.0 +# Apache-2.0 OR BSL-1.0 +# Apache-2.0 OR MIT +# Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT +# BSD-2-Clause +# BSD-2-Clause OR Apache-2.0 OR MIT +# BSD-3-Clause +# BSD-3-Clause OR MIT OR Apache-2.0 +# LGPL-2.1-only OR BSD-2-Clause +# MIT +# MIT OR Apache-2.0 +# MIT OR Zlib OR Apache-2.0 +License: License: (0BSD OR MIT OR Apache-2.0) AND (Apache-2.0) AND (Apache-2.0 OR BSL-1.0) AND (Apache-2.0 OR MIT) AND (Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT) AND (BSD-2-Clause) AND (BSD-2-Clause OR Apache-2.0 OR MIT) AND (BSD-3-Clause) AND (BSD-3-Clause OR MIT OR Apache-2.0) AND (LGPL-2.1-only OR BSD-2-Clause) AND (MIT) AND (MIT OR Apache-2.0) AND (MIT OR Zlib OR Apache-2.0) +# LICENSE.dependencies contains a full license breakdown + +URL: https://github.com/Netflix/%{name} +Source0: https://github.com/Netflix/%{name}/archive/refs/tags/v%{version}.tar.gz +Source1: https://github.com/Netflix/%{name}/releases/download/v%{version}/v%{version}-vendor.tar.gz + +BuildRequires: cargo-rpm-macros >= 26 +BuildRequires: elfutils-libelf-devel +BuildRequires: zlib-devel +BuildRequires: clang + +Requires: elfutils-libelf +Requires: zlib + +%global _description %{expand: +Dynamic real-time view of running eBPF programs.} + +%description %{_description} + +%prep +%autosetup -n %{name}-%{version} -p1 +tar -xzf %{SOURCE1} -C . +%cargo_prep -v vendor + +%generate_buildrequires + +%build +%cargo_build +%{cargo_license_summary} +%{cargo_license} > LICENSE.dependencies +%{cargo_vendor_manifest} > cargo-vendor.txt + +%install +%cargo_install + +%if %{with check} +%check +%cargo_test +%endif + +%files +%license LICENSE +%license LICENSE.dependencies +%license cargo-vendor.txt +%doc README.md +%{_bindir}/bpftop + +%changelog +%autochangelog