fpm 安装与使用

1
2
build RPM with fpm, without bullshit
—————— can.

fpm是基于ruby的打包工具, 相对于繁琐的rpmbuild命令加上繁琐的.spec文件编写确实要方便很多

而网上的教程也是一堆bullshit :),故在此总结一下

fpm安装

环境:CentOS 7

  • 安装ruby环境(虽然现在看可能没必要执行)

    1
    2
    3
    yum install -y ruby ruby-devel rubygem
    gem update --system
    gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
  • 安装rvm(Ruby虚拟环境,好比Python的venv)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    cd /usr/local/src
    curl -sSL https://github.com/rvm/rvm/tarball/stable -o rvm-stable.tar.gz
    tar -xzvf rvm-stable.tar.gz
    mv rvm-stable-xxx rvm
    cd rvm
    ./install --auto-dotfiles
    source /usr/local/rvm/scripts/rvm
    # 查看rvm可安装版本
    rvm list known
    # 这里安装2.3.8
    rvm install 3.1.0
    # 设置默认版本
    rvm use 2.3.8 --default
  • 安装fpm

    1
    2
    gem install fpm
    gem install json

fpm使用

通过telegraf的打包命令讲一些核心的参数,其他请参考 fpm -h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
ARCH=$1
if [ "$ARCH" == "arm" ]; then
ARCH="aarch64"
cp resource/telegraf_arm telegraf/usr/bin/telegraf
elif [ "$ARCH" == "x86" ]; then
ARCH="amd64"
cp resource/telegraf_x86 telegraf/usr/bin/telegraf
else
echo "invalid argument. just support 'amd64' or 'arm'"
fi
DATE=`date '+%Y%m%d%H%M%S'`
DESC=`git log -1 --pretty=format:"%s"`
fpm -f -s dir \
--log error \
--vendor InfluxData \
--url https://github.com/influxdata/telegraf \
--license MIT \
--maintainer obs \
--config-files /etc/telegraf/telegraf.conf \
--config-files /etc/logrotate.d/telegraf \
--after-install scripts/post-install.sh \
--before-install scripts/pre-install.sh \
--after-remove scripts/post-remove.sh \
--before-remove scripts/pre-remove.sh \
--description "${DESC}" \
--name telegraf \
-a ${ARCH} \
-t rpm \
--version 1.15.4_WoCloud \
--iteration ${DATE} \
-C telegraf \
-p . \
--depends coreutils \
--depends shadow-utils
  • -C {DIR} : 将DIR目录内所有内容打包
  • -s dir : 将目录所有内容打包
  • -p : 生成包的位置
  • -a : 架构名称,amd64 或者 aarch64等等
  • –config-files 配置文件(会被替换)
  • –depends 依赖的rpm