introduction
I wrote an article beforeHow to fuck rpm bag by hand, this timego
How cool is language packing?
Each component version
# git version is less than 2 can't do itgit 2.2.1 go 1.13.6
Prepare
- rpmbuild command
sudo yum install -y gcc make rpm-build redhat-rpm-config vim lrzsz
- git version 2.2.1 Install first using source
yum install git -y
If the installation is foundgit
Install manually if the version is wrong
- Compiled go files or files waiting to be installed (not limited to go package) Of course, you are not ready to run files to make a fuss.
start
You need a json file to tell the system which files you want to put intorpm
In the bag,build
, What to do before and after installation.
Here to fightopenstack-exporter
As an example (a go program)
{ "name": "openstack-exporter", "version": "0.9.0", "release": "release", "arch": "amd64", "summary": "RPM_SUMMARY", "description": "RPM_SUMMARY", "license": "", "url": "/", "postinst": "ci/package/rpm/postinst", "files": [ { "from": "./bin/LinuxAmd64/!name!", "to": "/usr/local/bin/", "base": "", "type": "" }, { "from": "!name!.service", "to": "/usr/lib/systemd/system/", "base": "", "type": "" }, { "from": "", "to": "/etc/openstack/", "base": "", "type": "" } ] }
Core configuration meaning:
- "name": "openstack-exporter" represents your
rpm
Service name, you canrpm -e openstack-exporter
Uninstall him directly. - "arch": "amd64" kernel: x86_64, other kernels can also be used.
- files to copy
rpm
Files in the package,from
to
From a local file to a directory in the package. - "postinst": "ci/package/rpm/postinst" The script content after installation and execution
systemctl daemon-reload
I plan to use this servicesystemctl
Hosted, if you don't need to delete it
Service configuration
This is forsystemctl
Used, the copy path is also written on it/usr/lib/systemd/system/
Configuration file name: service name+.service
[Unit] Description=openstack exporter After= [Service] Environment= User=root Group=root PermissionsStartOnly=true ExecStart=/usr/local/bin/openstack-exporter default Restart=always LimitNOFILE=65535 WorkingDirectory=/ [Install] WantedBy=
The meaning is not what I want to say today, so I will not explain it. Of course you can also use any daemon to host your services.
run
I prefer to use itgo
The package is placed in a public directory, for example/root/go
The binary obtained after compilation is used when the system command is used, it only needs to be executed.
echo "export PATH=\$PATH:/root/go/bin" >> /etc/bashrc export PATH=$PATH:/root/go/bin
/root/go
It is the defaultGOPATH
, you can ignore it.
Installgo-bin-rpm
Order
GOPATH=/root/go mkdir -p $GOPATH/src//mh-cbon/go-bin-rpm cd $GOPATH/src//mh-cbon/go-bin-rpm git clone /mh-cbon/ . glide install go install
Packaging only one line of command
go-bin-rpm generate -f rpm_linux_amd64.json -o ./rpms/openstack-exporter-0.9.0_amd64.rpm
Summarize
To package this component, you need to prepare
-
json
Files are used to describe which files are copied to the actual installed directory, and which commands are run before and after packaging. - Register files required by the corresponding daemon
We also learned to create a new directory specifically to preventgo
Language co-package and compiledgo
Binary files, used as new commands.
If you encapsulate this thing into continuous integration, you know how cool it will be.
The above is the detailed explanation of the implementation of the beauty of Go language to quickly build RPM package. For more information about the RPM package of Go language, please pay attention to my other related articles!