Skip to content

Commit 7c080a6

Browse files
authored
Packaging: Add venv and packs to deb/rpm packages (#6328)
2 parents 5de36c7 + 1ebd199 commit 7c080a6

File tree

9 files changed

+128
-8
lines changed

9 files changed

+128
-8
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Added
7979
to pants' use of PEX lockfiles. This is not a user-facing addition.
8080
#6118 #6141 #6133 #6120 #6181 #6183 #6200 #6237 #6229 #6240 #6241 #6244 #6251 #6253
8181
#6254 #6258 #6259 #6260 #6269 #6275 #6279 #6278 #6282 #6283 #6273 #6287 #6306 #6307
82-
#6311 #6314 #6315 #6317 #6319 #6312 #6320 #6321 #6323 #6324 #6325 #6326 #6327
82+
#6311 #6314 #6315 #6317 #6319 #6312 #6320 #6321 #6323 #6324 #6325 #6326 #6327 #6328
8383
Contributed by @cognifloyd
8484
* Build of ST2 EL9 packages #6153
8585
Contributed by @amanda11

packaging/BUILD

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ _common_pkg_metadata = dict(
2222
_maintainer = "StackStorm Engineering <[email protected]>" # TODO: update this
2323

2424

25+
def _st2_venv_deps() -> list[str]:
26+
"""Return a list of deps required to build the st2 venv.
27+
28+
The :st2_venv parametrizations depend on parametrizations of :st2.pex,
29+
so, make sure to keep these 3 lists of parametrizations in sync.
30+
"""
31+
return [f":st2_venv@parametrize=py3{m}" for m in ("8", "9", "10", "11")]
32+
33+
2534
def _distro(distro_id: str, **kwargs):
2635
return parametrize(
2736
distro_id,
@@ -38,6 +47,9 @@ nfpm_deb_package(
3847
"./common/systemd:generators",
3948
"./common:dirs",
4049
"./common:symlinks",
50+
*_st2_venv_deps(),
51+
":default_packs",
52+
":extra_packs",
4153
],
4254
scripts=dict(
4355
preinstall="deb/scripts/pre-install.sh",
@@ -70,6 +82,12 @@ nfpm_rpm_package(
7082
"./common/systemd:generators",
7183
"./common:dirs",
7284
"./common:symlinks",
85+
*_st2_venv_deps(),
86+
":default_packs",
87+
":extra_packs",
88+
],
89+
ghost_contents=[
90+
"/opt/stackstorm/install/st2.pex", # a symlink (default in post-install; users may modify)
7391
],
7492
scripts=dict(
7593
preinstall="rpm/scripts/pre-install.sh",
@@ -83,7 +101,8 @@ nfpm_rpm_package(
83101
vendor="The StackStorm Project",
84102
packager=_maintainer,
85103
# group="System/Management", # was only useful for EL 5 and earlier
104+
compression="zstd:best", # xz and lzma are ~3x slower than gzip or zstd
86105
**_common_pkg_metadata,
87-
**_distro("el8", compression="xz"),
88-
**_distro("el9", compression="zstd:default"),
106+
**_distro("el8"),
107+
**_distro("el9"),
89108
)

packaging/BUILD.packs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# These are packs that should be installed with the default ST2 install.
2+
_DEFAULT_PACKS = (
3+
"chatops",
4+
"core",
5+
"default",
6+
"linux",
7+
"packs",
8+
)
9+
10+
# These are packs that should NOT be installed with the default ST2 install.
11+
_EXTRA_PACKS = (
12+
"debug",
13+
"examples",
14+
"hello_st2",
15+
)
16+
17+
# :archive_for_npfm targets created by st2_pack_archive() macro (see pants-plugins/macros.py)
18+
target(
19+
name="default_packs",
20+
dependencies=[f"//contrib/{pack}:archive_for_nfpm" for pack in _DEFAULT_PACKS],
21+
)
22+
target(
23+
name="extra_packs",
24+
dependencies=[f"//contrib/{pack}:archive_for_nfpm" for pack in _EXTRA_PACKS],
25+
)

packaging/BUILD.venv

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ python_sources()
2323

2424

2525
def _pex_py3(minor: str, constraint: str = ""):
26+
"""Parametrize :st2.pex for a given python minor version."""
2627
if not constraint:
2728
constraint = f"CPython==3.{minor}.*"
2829
return parametrize(
@@ -71,3 +72,26 @@ pex_binary(
7172
**_pex_py3("10"),
7273
**_pex_py3("11"),
7374
)
75+
76+
77+
def _venv_py3(minor: str):
78+
"""Parametrize :st2_venv for a given python minor version."""
79+
return parametrize(
80+
f"py3{minor}",
81+
dependencies=[f":st2.pex@parametrize=py3{minor}"],
82+
src=f"st2-py3{minor}.pex", # relative to this BUILD file
83+
dst=f"/opt/stackstorm/install/st2-py3{minor}.pex",
84+
)
85+
86+
87+
nfpm_content_file(
88+
name="st2_venv",
89+
description="Pex file that system packages can use to generate /opt/stackstorm/st2",
90+
file_owner="root",
91+
file_group="root",
92+
file_mode="rwxr-x---",
93+
**_venv_py3("8"),
94+
**_venv_py3("9"),
95+
**_venv_py3("10"),
96+
**_venv_py3("11"),
97+
)

packaging/deb/scripts/post-install.sh

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ set -e
2929
# https://www.mankier.com/5/deb-triggers
3030
# https://stackoverflow.com/questions/15276535/dpkg-how-to-use-trigger
3131

32+
# The supported minor versions of python3 (python3.{minor}) in reverse order.
33+
_ST2_PY3_MINOR="11 10 9 8"
34+
3235
# The default set of packs installed with st2.
3336
_ST2_PACKS="
3437
chatops
@@ -93,7 +96,24 @@ systemd_enable_and_restart() {
9396
}
9497

9598
rebuild_st2_venv() {
96-
/opt/stackstorm/install/st2.pex
99+
_pex="/opt/stackstorm/install/st2.pex"
100+
if [ ! -e "${_pex}" ]; then
101+
# symlink does not exist or does not point to a valid file
102+
# (the symlink target might not exist any more if upgrading
103+
# to an st2 version that drops support for an older python)
104+
rm -f "${_pex}"
105+
for minor in ${_ST2_PY3_MINOR}; do
106+
if [ -x "/usr/bin/python3.${minor}" ]; then
107+
ln -s "st2-py3${minor}.pex" "${_pex}"
108+
break
109+
fi
110+
done
111+
if [ ! -e "${_pex}" ]; then
112+
# symlink creation failed; the python dep is somehow missing
113+
return 42
114+
fi
115+
fi
116+
"${_pex}"
97117
}
98118

99119
extract_st2_pack() {

packaging/rpm/scripts/post-install.sh

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ set -e
77
# * on upgrade: $1 > 1
88
# https://docs.fedoraproject.org/en-US/packaging-guidelines/Scriptlets/#_syntax
99

10+
# The supported minor versions of python3 (python3.{minor}) in reverse order.
11+
_ST2_PY3_MINOR="11 10 9 8"
12+
1013
# The default set of packs installed with st2.
1114
_ST2_PACKS="
1215
chatops
@@ -31,7 +34,24 @@ st2workflowengine
3134
"
3235

3336
rebuild_st2_venv() {
34-
/opt/stackstorm/install/st2.pex
37+
_pex="/opt/stackstorm/install/st2.pex"
38+
if [ ! -e "${_pex}" ]; then
39+
# symlink does not exist or does not point to a valid file
40+
# (the symlink target might not exist any more if upgrading
41+
# to an st2 version that drops support for an older python)
42+
rm -f "${_pex}"
43+
for minor in ${_ST2_PY3_MINOR}; do
44+
if [ -x "/usr/bin/python3.${minor}" ]; then
45+
ln -s "st2-py3${minor}.pex" "${_pex}"
46+
break
47+
fi
48+
done
49+
if [ ! -e "${_pex}" ]; then
50+
# symlink creation failed; the python dep is somehow missing
51+
return 42
52+
fi
53+
fi
54+
"${_pex}"
3555
}
3656

3757
extract_st2_pack() {

pants-plugins/macros.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,16 @@ def st2_pack_archive(**kwargs):
170170
output_path=f"packaging/packs/{pack_name}.tgz.run",
171171
)
172172

173+
nfpm_content_file( # noqa: F821
174+
name="archive_for_nfpm",
175+
dependencies=[":archive"],
176+
src=f"packaging/packs/{pack_name}.tgz.run",
177+
dst=f"/opt/stackstorm/install/packs/{pack_name}.tgz.run",
178+
file_owner="root",
179+
file_group=ST2_PACKS_GROUP,
180+
file_mode="rwxr-x---",
181+
)
182+
173183

174184
def st2_shell_sources_and_resources(**kwargs):
175185
"""This creates a shell_sources and a resources target.

pants-plugins/release/packagecloud_rules.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
}
7575

7676

77-
@dataclass
77+
@dataclass(frozen=True)
7878
class PackageCloudNextReleaseRequest:
7979
nfpm_arch: str
8080
distro_id: str
@@ -83,7 +83,7 @@ class PackageCloudNextReleaseRequest:
8383
production: bool
8484

8585

86-
@dataclass
86+
@dataclass(frozen=True)
8787
class PackageCloudNextRelease:
8888
value: Optional[int] = None
8989

pants.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ root_patterns = [
109109
# DEFAULT has values that we can reuse/interpolate below
110110
[DEFAULT]
111111
# This is the range of python versions that we support.
112-
# On update, make sure to also update parametrizations in packaging/BUILD*.
112+
# On update, make sure to also update:
113+
# - the parametrizations in packaging/BUILD and packaging/BUILD.venv
114+
# - the list of python minor versions in packaging/*/scripts/post-install.sh
113115
st2_interpreter_constraints = "CPython>=3.8.1,<3.12"
114116

115117
# This should match the pants interpreter_constraints:

0 commit comments

Comments
 (0)