Preface:
After a period of testing and verification, it was decided to use RPM to deploy Golang services. There are several main ways to deploy code in our group. Python directly uses virtualenv + py code to go online. Lua is directly packaged, Golang is first compiled and generated binary, and then packaged the joint configuration file directly. However, since many of the Golang codes we developed are basic components, many nodes need to be installed and deployed. Then at this time, the way of compiling and packaging and RPM is actually very imaginative, so it is better to reuse the company's mature online rpm-based online system.
I won’t say much below, let’s take a look at the detailed introduction together.
How to use rpm packaging:
# Install RPM dependenciesyum install rpmdevtools #Generate RPM directorycd ~ rpmdev-setuptree
Below is the basic organizational structure of rpm.
├── BUILD ├── BUILDROOT ├── RPMS ├── SOURCES ├── SPECS └── SRPMS
In fact, the most straightforward way to package rpm is to directly edit the SPECS configuration file, compile the go code into binary in the logic of %install, and then CP in, and that's all. Due to time constraints, I will not describe the advanced usage of rpm in detail. Interested friends can view SPECS-related configurations by themselves.
#Brief introduction of software packageSummary: build transcoding #The name of the packageName: transcoding #Main version number of packageVersion: 0.0.1 #The package's subversion numberRelease: 5 #Source code package, by default, will be searched in the SOURCES directory mentioned aboveSource0: %{name}-%{version}. #Authorization AgreementLicense: GPL #Software ClassificationGroup: Development/Tools #Introduction to the content of the software package%description Video transcoding cluster # represents the pre-operation field, the subsequent command will be executed before the source code BUILD%prep #BUILD field will complete the source code compilation operation by directly calling the automatic construction tool in the source code directory.%build #file #Installation Field%install # Binary Execution Filemkdir -p ${RPM_BUILD_ROOT}/usr/bin/ cp -f /devops/app/go/src/transcoding/engine_bin ${RPM_BUILD_ROOT}/usr/bin/transcoding_engine_bin cp -f /devops/app/go/src/transcoding/rest_bin ${RPM_BUILD_ROOT}/usr/bin/transcoding_rest_bin # Configuration Filemkdir -p ${RPM_BUILD_ROOT}/etc/transcoding cp -f /devops/app/go/src/transcoding/etc/ ${RPM_BUILD_ROOT}/etc/transcoding/ # Control scriptmkdir -p ${RPM_BUILD_ROOT}/etc// cp -f /devops/app/go/src/transcoding/bin/ ${RPM_BUILD_ROOT}/etc// #Call the execution script in the source code# File description field, redundant or missing statements may cause errors%files %defattr(-,root,root) /usr/bin/transcoding_engine_bin /usr/bin/transcoding_rest_bin /etc// %dir /etc/transcoding
After editing the SPECS file, start runningrpmbuild
Generate rpm package.
rpmbuild -bb
After compiling, we will take a look at the rpm structure. Right, there is an additional rpm package...
├── BUILD ├── BUILDROOT ├── RPMS │ └── x86_64 │ └── transcoding-0.0.1-5.x86_64.rpm ├── SOURCES ├── SPECS │ └── └── SRPMS
All we have to do is upload the rpm package we generated to our private yum repo source. You can follow your standard online process for the rest of the process.
There are two things to note here:
1. rpm specs
Updated version number, if not updated, it will causeyum update
invalid….
2. If the configuration file contains the account password of db, please do not add it to rpm, even if it is private.yum repo
, not safe...
Summarize
The above is the entire content of this article. I hope that the content of this article has certain reference value for everyone's study or work. If you have any questions, you can leave a message to communicate. Thank you for your support.