通过 rpmbuild 打包 rpm

本文介绍如何使用rpmbuild工具从源代码构建RPM包,包括编译、打包、安装等步骤,适用于在Linux环境下进行软件部署。

通过 rpmbuild 打包 rpm 文件的命令

    # 编译 my-test-app
    rm -r target
    mvn clean install -Dmaven.test.skip=true
    cd target
    tar -cvzf my-test-app.tar.gz ./my-test-app

    # $rpmbuild 为负责打包的机器,因为我开发机为 mac,而部署机为 linux,故需将文件拷贝到 linux 机器上进行打包 rpm,否则 mac 上生成的 rpm 无法在 linux 上正确安装。
    # 清理 linux 机器上可能存在的文件,在 linux 上安装 rpm-build
    ssh admin@$rpmbuild "cd /home/admin & rm -r my-test-app.spec rpmbuild/SOURCES/my-test-app.tar.gz rpmbuild/RPMS/x86_64/my-test-app-0.0.1.x86_64.rpm rpmbuild/BUILD/my-test-app & mkdir -p /home/admin/rpmbuild/SOURCES & mkdir -p /home/admin/rpmbuild/BUILD/my-test-app & sudo yum install -y rpm-build"

    # 拷贝本地文件到 linux 机器相应文件夹
    scp my-test-app.tar.gz admin@$rpmbuild:/home/admin/rpmbuild/SOURCES
    scp ../src/main/assembly/my-test-app.spec admin@$rpmbuild:/home/admin

    # 执行 rpmbuild,生成 rpm 包
    ssh admin@$rpmbuild "rpmbuild -ba /home/admin/my-test-app.spec"

spec 文件

   

    ### 0. Define section
    ### {buildroot} is by default ~/rpmbuild/BUILDROOT/{Name}-{Version}-{Release}

    ### 1. The introduction section
    Name:           my-test-app
    Version:        0.0.1
    Release:        1%{?dist}
    Summary:        my-test-app
    Group:          my-test-team
    License:        Commercial
    URL:            http://xxxx.com
    Packager:       abc@xxxx.com
    Source0:        my-test-app.tar.gz
    # add Prefix and give a dummy value, the RPM will be relocatable, you can override prefix when installing RPM
    # sudo rpm -ivh ~/rpmbuild/RPMS/x86_64/my-test-app-0.0.1.x86_64.rpm --prefix=/home/admin
    Prefix:         /

    %description
    my-test-app

    ### 2. The Prepare section
    %prep
    # This will unzip sources into ~/rpmbuild/BUILD folder
    tar -xzvf %{sources}

    ### 3. The Build Section
    %build
    # Current folder is ~/rpmbuild/BUILD
    cd ./my-test-app
    mvn package -Dmaven.test.skip -Denv=release

    ### 4. Install Section
    %install
    mkdir -p %{buildroot}/my-test-app
    rsync -av --exclude=**/*DS_Store manager/my-test-app/target/my-test-app/ %{buildroot}/my-test-app

    ### 5. The files to be packaged into RPM
    %files
    # Current folder is {buildroot}
    /my-test-app
    # These files will get the below permissions after you installed RPM
    %attr(4755, admin, admin) /my-test-app/bin/*
    %attr(4755, admin, admin) /my-test-app/script/*

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值