GitLab CI template for RPM¶
This project implements a GitLab CI/CD template to build RPM packages.
Usage¶
This template can be used both as a CI/CD component
or using the legacy include:project
syntax.
Use as a CI/CD component¶
Add the following to your .gitlab-ci.yml
:
include:
# 1: include the component
- component: $CI_SERVER_FQDN/to-be-continuous/rpm/gitlab-ci-rpm@1.0.1
# 2: set/override component inputs
inputs:
# ⚠ this is only an example
spec-file: rpm/myapp.spec
Use as a CI/CD template (legacy)¶
Add the following to your .gitlab-ci.yml
:
include:
# 1: include the template
- project: "to-be-continuous/rpm"
ref: "1.0.1"
file: "/templates/gitlab-ci-rpm.yml"
variables:
# 2: set/override template variables
# ⚠ this is only an example
RPM_SPEC_FILE: rpm/myapp.spec
Global configuration¶
The RPM template uses some global configuration used throughout all jobs.
Jobs¶
rpm-build
job¶
This job builds the RPM package from a SPEC file.
It uses the following variable:
Input / Variable | Description | Default value |
---|---|---|
build-image / RPM_BUILD_IMAGE |
The Docker image used to run rpmbuild .(only define if different from default image) |
$RPM_BASE_IMAGE |
source-dir / RPM_SOURCE_DIR |
The RPM sourcedir path (contains sources) |
. |
build-opts / RPM_BUILD_OPTS |
rpmbuild options used to build the RPM package |
-ba |
The result of the build will be saved as a build artifact in the following output folder structure:
rpmbuild
├─ RPMS
│ ├─ ...
├─ SRPMS
│ ├─ ...
Any further job in the pipeline may retieve the built RPM package(s) in those folders (for instance to install them or publish them to some RPM repository).
Custom macros support¶
If a .rpmmacros
file is found at the root of your repository, it will be automatically loaded by the template (in addition to the default macros).
Sources automatic download¶
The template also automatically downloads any URL source declared in the SPEC file ( without performing
any integrity check: be cautious).
BuildRequires automatic install¶
Prior to building the RPM package, the template first downloads all the dependencies statically declared in the SPEC file.
The template also supports dynamic BuildRequires
generation relying on the %generate_buildrequires
stage (for exemple when using the
%pyproject_buildrequires
macro provided by python3-devel
) by automatically installing unsatisfied dependencies and retrying the build.
%{tbc_version}
macro¶
The template detects when a pipeline is running in a software release context:
- if a Git tag has been created and pushed,
- if the semantic-release template is used in conjunction with the
semantic-release-info
feature, and a next version has been detected (SEMREL_INFO_NEXT_VERSION
).
In any of those cases, the template defines the detected version as the %{tbc_version}
macro.
If this is useful in your project, you are free to use it for example with the following Version expression in your SPEC file:
# the bellow expression allows to retrieve the version
# determined by to-be-continuous when defined
# if not, '0.0.1~dev' is used as default
Version: %{?tbc_version}%{!?tbc_version:0.0.1~dev}
rpm-lint
job¶
This job performs a lint analysis of your SPEC file, mapped to the build
stage.
It uses the following variables:
Input / Variable | Description | Default value |
---|---|---|
lint-image / RPM_LINT_IMAGE |
The Docker image used to run rpmlint .(only define if different from default image) |
$RPM_BASE_IMAGE |
lint-disabled / RPM_LINT_DISABLED |
Set to true to disable the lint analysis |
none (enabled) |
lint-opts / RPM_LINT_OPTS |
rpmlint options |
--info |
If a rpmlint rc file (rpmlintrc
, .rpmlintrc
or .rpmlint
) is found in your source-dir
/ RPM_SOURCE_DIR
or at the root of your repository,
it will be automatically used by the template.
Extra - Recommended resources¶
Here are some recommended resources about RPM packaging:
- RPM official website
- RPM Packaging Guide
- Fedora Packaging Guidelines With many language-specific guides: