Skip to content

Conversation

@cognifloyd
Copy link
Member

@cognifloyd cognifloyd commented Mar 27, 2025

This PR is working towards doing packaging via pantsbuild. Eventually, I hope to archive and stop using st2-packages.git.

The pants nfpm backend was activated in #6321. This PR adds an nfpm_deb_package target and an nfpm_rpm_package target with basic metadata like packager, package description, homepage, etc. I added review comments to address each piece of this metadata, where it came from in st2-packages, and what documentation is relevant for this BUILD target field.

st2/packaging/BUILD

Lines 33 to 34 in 2ef489b

nfpm_deb_package(
name="st2.deb",

st2/packaging/BUILD

Lines 61 to 62 in 2ef489b

nfpm_rpm_package(
name="st2.rpm",

Beyond this metdata, I also included the deb maintainer scripts and rpm scriptlets--the pre-install, post-install, pre-remove, and post-remove scripts--added in these PRs:

To add them, the scripts have to be in dependencies (deps on other BUILD targets--package deps will be in a later PR), and the script has to be registered in the scripts field:

st2/packaging/BUILD

Lines 35 to 46 in 2ef489b

dependencies=[
"./deb/scripts",
],
scripts=dict(
preinstall="deb/scripts/pre-install.sh",
postinstall="deb/scripts/post-install.sh",
preremove="deb/scripts/pre-remove.sh",
postremove="deb/scripts/post-remove.sh",
# config="",
# templates="",
# rules="",
),

st2/packaging/BUILD

Lines 63 to 74 in 2ef489b

dependencies=[
"./rpm/scripts",
],
scripts=dict(
preinstall="rpm/scripts/pre-install.sh",
postinstall="rpm/scripts/post-install.sh",
preremove="rpm/scripts/pre-remove.sh",
postremove="rpm/scripts/post-remove.sh",
# pretrans="",
# posttrans="",
# verify="",
),

The scripts field is documented here:

Note that there are 3 more possible deb-specific scripts (config, templates, rules) and 3 more possible rpm-specific scripts (pretrans, posttrans, verify). I left a comment so that we can add those later if we have a reason to do so.

File Triggers

This section is informational. It is related to the deb maintainer scripts registered in this PR, so I mention it in this PR even though this PR does not implement file triggers.

In deb packages, triggers would tell dpkg to run our post-install script when, for example, the python binary is updated which would allow the post-install script to rebuild the venv. However, nFPM currently does not have support for that for rpm. For rpm, the underlying rpmpack library needs to be updated to support adding file triggers. To that end, I filed this feature request:

As I mentioned in that issue, I can probably work on adding that to rpmpack at some point, but I need to finish the rest of the pants+packaging stuff for st2 first.

@cognifloyd cognifloyd added this to the pants milestone Mar 27, 2025
@cognifloyd cognifloyd self-assigned this Mar 27, 2025
@pull-request-size pull-request-size bot added the size/M PR that changes 30-99 lines. Good size to review. label Mar 27, 2025
Comment on lines +6 to +10
_pkg_description = """
StackStorm Event-driven automation
Package is full standalone st2 installation including all components
in a pre-built venv.
"""
_common_pkg_metadata = dict(
package_name="st2",
description=_pkg_description,
homepage="https://stackstorm.com",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +15 to +16
# https://jfearn.fedorapeople.org/en-US/RPM/4/html-single/RPM_Guide/index.html#idp3030720
license="Apache-2.0", # TODO: nFPM is putting this under Copyright tag instead of License
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +18 to +19
# arch used to be "any", but that was not correct as the venv has compiled packages.
arch="amd64", # NOTE: parametrize this if adding support for arm64 or other arch.
Copy link
Member Author

@cognifloyd cognifloyd Mar 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From:

Also, this uses the ARCH defined in golang which gets translated to the package-specific architecture. So, amd64 becomes x86_64 for rpm, but remains amd64 for deb. This page shows how that translation happens (though the doc is slightly incorrect here as amd64 does not get translated to x86_64 for deb files): https://nfpm.goreleaser.com/goarch-to-pkg/

See:

version="", # injected by pants-plugins/release
# arch used to be "any", but that was not correct as the venv has compiled packages.
arch="amd64", # NOTE: parametrize this if adding support for arm64 or other arch.
platform="linux",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just needed for nfpm. I included it here to be explicit instead of relying on the default value linux. 🤷 We can drop this line if anyone doesn't like it here.

See:

"Vcs-Git": "git://github.com/stackstorm/st2.git",
"Vcs-Browser": "https://github.com/stackstorm/st2",
},
section="python",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Vcs-Browser": "https://github.com/stackstorm/st2",
},
section="python",
priority="optional",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def _distro(distro_id: str, **kwargs):
return parametrize(
distro_id,
distro_id=distro_id,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the distro_id field added in #6324.

# posttrans="",
# verify="",
),
vendor="The StackStorm Project",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is new. It was not in st2-packages.git. It is not used in Fedora, so we don't have to include it.

See: https://www.pantsbuild.org/stable/reference/targets/nfpm_rpm_package#vendor

),
vendor="The StackStorm Project",
packager=_maintainer,
# group="System/Management", # was only useful for EL 5 and earlier
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From (rpm): https://github.com/StackStorm/st2-packages/blob/d4d2d8dfdf1c88412e5d58635adb87da9c671952/rpmspec/st2pkg_toptags.spec#L15

We no longer support EL 5 or earlier, so we should probably just drop this line instead of commenting it out. Right?

Suggested change
# group="System/Management", # was only useful for EL 5 and earlier

See: https://www.pantsbuild.org/stable/reference/targets/nfpm_rpm_package#group

@cognifloyd cognifloyd marked this pull request as ready for review March 27, 2025 22:27
@cognifloyd cognifloyd requested a review from a team March 31, 2025 17:44
@guzzijones guzzijones merged commit dc4dd91 into master Apr 2, 2025
85 checks passed
@guzzijones guzzijones deleted the packaging-nfpm_packages branch April 2, 2025 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement pantsbuild size/M PR that changes 30-99 lines. Good size to review. st2-packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants