GNU/Linux >> Linux の 問題 >  >> Linux

オープンソースアプリケーションをRPMとしてパッケージ化する方法

最近、Red Hat Package Manager(RPM)を使用して独自のソフトウェアをパッケージ化することについて書きました。もう1つの一般的なシナリオは、使用したいソフトウェアが見つかったが、そのためのRPMがないことです。この記事では、サードパーティアプリケーション用のRPMを作成する方法を説明します。

前提条件は次のとおりです。

  • RPMを使用してパッケージを照会し、パッケージをインストールまたは削除する方法に関する基本的な知識があります。そうでない場合は、最初にこれらの概念に精通してから、ここに戻って楽しんでください。
  • ここに含まれている演習を完了するために必要になるため、Make、Git、GCC、およびJavaがインストールされています。必須ではありませんが、私が進むにつれて練習していただければ幸いです。

DNFパッケージマネージャーを使用してMake、GCC、Java 11、およびGitをインストールするには、次のコマンドを実行します。

$ sudo dnf install \
make git gcc-10 \
java-11-openjdk-headless

この例では、NASAの好きなJavaベンチマークであるNAS Parallel Benchmarks(NPB3.0)を使用します。このコードを取得してフォークを作成し、Gradleを使用して改善されたビルドのみを追加しました。手順は次のとおりです。

ステップ1:スケルトンスペックファイルを作成する

$  rpmdev-newspec --output ~/rpmbuild/SPECS/NPB.spec \
--type minimal

/home/josevnz/rpmbuild/SPECS/npb.spec created;
type minimal, rpm version >= 4.16.

結果のファイルは次のようになります:

Name:           npb
Version:        
Release:        1%{?dist}
Summary:        

License:        
URL:            
Source0:        

BuildRequires:  
Requires:       

%description

%prep
%autosetup

%build
%configure
%make_build

%install
rm -rf $RPM_BUILD_ROOT
%make_install


%files
%license add-license-file-here
%doc add-docs-here

%changelog
* Tue Oct 05 2021 Jose Vicente Nunez <[email protected]>
-  

次に、このタスクには適用されないため、このスケルトンファイルから次のタグを削除します。

  • %autosetup: パッチなしで自分でソフトウェアを解凍します
  • %configure および%make_build: 代わりにGradleを使用します

前提条件であるJavaとGradleをインストールします:

$ sudo dnf install java-11-openjdk
$ sudo -i mkdir -p /opt/gradle
$ sudo -i curl --silent --location --fail \
--output /opt/gradle/gradle.zip \
https://services.gradle.org/distributions/gradle-7.2-bin.zip
$ cd /opt/gradle
$ sudo unzip gradle.zip
$ sudo /bin/rm -f /opt/gradle/gradle.zip

これで、specを変更する準備が整いました ファイル。

[Bashシェルスクリプトのチートシートをダウンロードして、その他のヒントを入手してください。 ]

ステップ2:JavaRPMの構成要素を入力します

ビルドの一部としてGradleを追加するなど、いくつかの変更を加えると、次のようになります。

Name:           NPB
Version:        3.0
Release:        1%{?dist}
Summary:        Small set of programs designed to help evaluate the performance of parallel supercomputers

License:        NOSA
URL:            https://www.nas.nasa.gov/software/npb.html
Source0:        https://www.nas.nasa.gov/assets/npb/%{name}%{version}.tar.gz

BuildRequires:  java-11-openjdk-headless,tar,gzip,rpmdevtools,rpmlint
Requires:       java-11-openjdk-headless

# Custom macros (https://rpm-software-management.github.io/rpm/manual/macros.html)
# If you want to see the value of many of these macros, just run this: /usr/bin/rpm --showrc
%global debug_package %{nil}
%global gradle /opt/gradle/gradle-7.2/bin/gradle
%global curl /bin/curl --location --fail --silent --output
%global JAVA_DIR NPB3_0_JAV

%description

The NAS Parallel Benchmarks (NPB) are a small set of programs designed to help evaluate the performance
of parallel supercomputers. The benchmarks are derived from computational fluid dynamics (CFD)
applications and consist of five kernels and three pseudo-applications in the original "pencil-and-paper"
specification (NPB 1). The benchmark suite has been extended to include new benchmarks for unstructured
adaptive meshes, parallel I/O, multi-zone applications, and computational grids. Problem sizes in NPB are
predefined and indicated as different classes. Reference implementations of NPB are available in
commonly-used programming models like MPI and OpenMP (NPB 2 and NPB 3).

%prep
test ! -x %{gradle} && echo "ERROR: Gradle not installed!" && exit 100
# On a production environment you MOST LIKELY point to your private copy of the build artifacts
/bin/curl --location --fail --silent --output %{_sourcedir}/%{name}%{version}.tar.gz  https://www.nas.nasa.gov/assets/npb/%{name}%{version}.tar.gz
%setup -q -n %{name}%{version}

%build
cd %{name}%{version}-JAV
# If you are not familiar with Gradle, you should read the following:
# https://docs.gradle.org/current/userguide/building_java_projects.html#sec:custom_java_source_set_paths
/bin/cat<<GRADLE>build.gradle.kts
// Gradle build file dynamically created for %{name}%{version}
plugins {
    \`java-library\`
}

java {
    toolchain {
        languageVersion.set(JavaLanguageVersion.of(11))
    }   
}

sourceSets {
    main {
        java {
            setSrcDirs(listOf("%{JAVA_DIR}"))
        }
    }   

    test {
        java {
            setSrcDirs(listOf("test"))
        }
    }   
}
GRADLE
%{gradle} clean java jar

%install
/bin/rm -rf %{buildroot}
/bin/mkdir -v -p %{buildroot}/%{_bindir}
/bin/mkdir -v -p %{buildroot}/%{_libdir}
/bin/mkdir -v -p %{buildroot}/%{_pkgdocdir}
/bin/cp -p -v %{_builddir}/%{name}%{version}/%{name}%{version}-JAV/build/libs/%{name}%{version}-JAV.jar %{buildroot}/%{_libdir}

# On a production environment you MOST LIKELY point to your private copy of the build artifacts
%{curl} %{buildroot}/%{_pkgdocdir}/LICENSE https://raw.githubusercontent.com/josevnz/%{name}%{version}-JAV-FORK/main/LICENSE
%{curl} %{buildroot}/%{_pkgdocdir}/README.md https://github.com/josevnz/%{name}%{version}-JAV-FORK/blob/main/%{name}%{version}-JAV/README.md
%{curl} %{buildroot}/%{_bindir}/testAllS https://raw.githubusercontent.com/josevnz/tutorials/main/testAllS
%{curl} %{buildroot}/%{_bindir}/testAllW https://raw.githubusercontent.com/josevnz/tutorials/main/testAllW
/bin/chmod a+xr %{buildroot}/%{_bindir}/{testAllS,testAllW}

%clean
/bin/rm -rf %{buildroot}

%files
%license %{_pkgdocdir}/LICENSE
%doc %{_pkgdocdir}/README.md
%{_libdir}/%{name}%{version}-JAV.jar
%{_bindir}/testAllS
%{_bindir}/testAllW

%changelog
* Tue Oct 05 2021 Jose Vicente Nunez <[email protected]>
- First RPM 

spec ファイルには多くのコメントが付けられており、元のtar.gzをどのように使用したかがわかります。 変更を加えずにファイルを作成し、その上に新しいビルドシステムを追加し、さらに2つのラッパースクリプト(testAIISとtestAIIW)を追加して、インストール後にJavaコードを実行します。

次に、新しいRPMを作成します:

$ rpmbuild -ba ~/rpmbuild/SPECS/npb.spec
Requires: /usr/bin/bash
Checking for unpackaged file(s): /usr/lib/rpm/check-files /home/josevnz/rpmbuild/BUILDROOT/NPB-3.0-1.fc33.x86_64
Wrote: /home/josevnz/rpmbuild/SRPMS/NPB-3.0-1.fc33.src.rpm
Wrote: /home/josevnz/rpmbuild/RPMS/x86_64/NPB-3.0-1.fc33.x86_64.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.JGJ4Ky

ステップ3:カスタムRPMをインストールする

RPMが構築されたら、次のようにインストールできます。

$ sudo rpm -ihv ~/rpmbuild/RPMS/x86_64/NPB-3.0-1.fc33.x86_64.rpm
[sudo] password for josevnz: 
Verifying...              ################## [100%]
Preparing...              ################## [100%]
Updating / installing...
   1:NPB-3.0-1.fc33       ################## [100%]

出力は成功を示します:

/usr/bin/testAllS
+ /usr/lib/jvm/java-11-openjdk-11.0.12.0.7-4.fc33.x86_64/bin/java -classpath
[...]rpmbuild/BUILD/NPB3.0/NPB3.0-JAV/build/libs/NPB3.0-JAV.jar NPB3_0_JAV.BT
-np2 CLASS=S
 NAS Parallel Benchmarks Java version (NPB3_0_JAV)
 Multithreaded Version BT.S np=2
No input file inputbt.data, Using compiled defaults
Size: 12 X 12 X 12
Iterations: 60 dt: 0.01
Time step 1
Time step 20
Time step 40
Time step 60
Verification being performed for class S
accuracy setting for epsilon = 1.0000000000000005E-8
Comparison of RMS-norms of residual
[...]
BT.S: Verification Successful

詳細

RPMを使用してソフトウェアをパッケージ化することは、それが自分のものであろうと他の誰かのオープンソースアプリケーションであろうと、最初は恐ろしいように見えるかもしれませんが、少しの忍耐があれば、すぐにそこに到達します。問題が発生すると、コードを改善する適切な方法も見つかります。以下は、いくつかのリソースと最終的な推奨事項です。

  • 大いに賛成して、Adam Miller、Maxim Svistunov、およびMarieDoleželováによって書かれたRPMパッケージングガイドのコピーを入手してください。それは非常に完全でよく整理されています。真剣に、今それをしなさい;とても良いです。
  • 公式のRPMパッケージガイドとFedoraRPMガイドにも詳細が満載です。ブックマークを付けないでください。
  • rpmlintを使用します。 RPMパッケージを出荷する前に、キャッチして修正できる小さなものがいくつもあることに驚かれることでしょう。
  • 十分ではありませんか? Fedoraには、ソフトウェアをパッケージ化するときに使用できるトリックのリストがあります。
  • もっと喉が渇いた? RPMパッケージングガイドラインを必ず確認してください。

Linux
  1. 私のLinuxストーリー:影響力のあるセキュリティ開発者がオープンソースでどのように始めたか

  2. CheckInstallを使用してソースからパッケージを構築する方法

  3. LinuxRPMパッケージを作成する方法

  1. 地方自治体がオープンソースに移行した方法

  2. Linux用のPythonアプリケーションをパッケージ化する方法

  3. LinuxでAppimageを開く方法

  1. Linuxでオープンソースツールを使用してStreamDeckを使用する方法

  2. Linuxでpkgsrcを使用する方法

  3. Debian – Debianでパッケージのソースリポジトリを知る方法は?