Skip to content

Commit ae799b0

Browse files
test and save foundry packages
1 parent 9aa06fc commit ae799b0

2 files changed

Lines changed: 157 additions & 2 deletions

File tree

configuration/builders/sequences/foundry/autobake.py

Lines changed: 97 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
1+
import os
2+
13
from configuration.builders.infra.runtime import (
24
BuildSequence,
35
DockerConfig,
46
InContainer,
57
)
8+
from configuration.steps.commands.base import URL, BashCommand
69
from configuration.steps.commands.download import GitInitFromCommit
7-
from configuration.steps.commands.foundry import BuildPlugin
10+
from configuration.steps.commands.foundry import (
11+
BuildPlugin,
12+
InstallBuiltPackages,
13+
RunPluginMTRSuite,
14+
)
815
from configuration.steps.commands.packages import (
916
InstallDEBPackages,
1017
InstallRPMPackages,
18+
SavePackages,
1119
SetupDEBRepoFromURL,
1220
SetupRPMRepoFromURL,
1321
)
14-
from configuration.steps.remote import ShellStep
22+
from configuration.steps.remote import PropFromShellStep, ShellStep
1523

1624
_MARIADB_VERSION_ENV = [("MARIADB_VERSION", "%(prop:mariadb_version)s")]
1725

@@ -30,9 +38,49 @@ def _clone_foundry_step(config: DockerConfig):
3038
)
3139

3240

41+
def _capture_foundry_revision_step(config: DockerConfig):
42+
# foundry_force_scheduler never gives us a concrete revision (see
43+
# _clone_foundry_step), so read back the commit that actually got
44+
# checked out -- needed to tell apart saved packages built from
45+
# different foundry/plugin source revisions.
46+
return InContainer(
47+
PropFromShellStep(
48+
command=BashCommand(cmd="git rev-parse --short HEAD"),
49+
property="foundry_revision",
50+
),
51+
docker_environment=config,
52+
)
53+
54+
55+
def _save_packages_step(config: DockerConfig, package_glob: str):
56+
# The same builder gets triggered once per mariadb_version (and, on a
57+
# different run, for a different plugin, or a different foundry commit)
58+
# -- all three need to be in the destination path, or a later run
59+
# silently overwrites an earlier one's saved packages.
60+
# mariadb_version-tarbuildnum is kept as a single segment so it reads
61+
# unambiguously as "the tarbuildnum for this mariadb_version", not some
62+
# unrelated build number.
63+
destination = (
64+
"/packages/foundry/%(prop:mariadb_version)s-%(prop:tarbuildnum)s/%(prop:plugin)s"
65+
"/%(prop:foundry_revision)s/%(prop:buildername)s"
66+
)
67+
url = (
68+
f"{os.environ['ARTIFACTS_URL']}/foundry/%(prop:mariadb_version)s-%(prop:tarbuildnum)s"
69+
"/%(prop:plugin)s/%(prop:foundry_revision)s/%(prop:buildername)s"
70+
)
71+
return InContainer(
72+
ShellStep(
73+
command=SavePackages(packages=[package_glob], destination=destination),
74+
url=URL(url=url, url_text="Packages"),
75+
),
76+
docker_environment=config,
77+
)
78+
79+
3380
def deb(config: DockerConfig, repo_file_url: str):
3481
sequence = BuildSequence()
3582
sequence.add_step(_clone_foundry_step(config))
83+
sequence.add_step(_capture_foundry_revision_step(config))
3684
sequence.add_step(
3785
InContainer(
3886
ShellStep(command=SetupDEBRepoFromURL(repo_file_url)),
@@ -53,12 +101,36 @@ def deb(config: DockerConfig, repo_file_url: str):
53101
docker_environment=config,
54102
)
55103
)
104+
sequence.add_step(
105+
InContainer(
106+
ShellStep(command=InstallBuiltPackages("DEB")),
107+
docker_environment=config,
108+
container_commit=True,
109+
)
110+
)
111+
sequence.add_step(_save_packages_step(config, "*.deb"))
112+
sequence.add_step(
113+
InContainer(
114+
ShellStep(
115+
command=InstallDEBPackages(packages=["mariadb-server", "mariadb-test"])
116+
),
117+
docker_environment=config,
118+
container_commit=True,
119+
)
120+
)
121+
sequence.add_step(
122+
InContainer(
123+
ShellStep(command=RunPluginMTRSuite("/usr/share/mysql/mysql-test")),
124+
docker_environment=config,
125+
)
126+
)
56127
return sequence
57128

58129

59130
def rpm(config: DockerConfig, repo_file_url: str):
60131
sequence = BuildSequence()
61132
sequence.add_step(_clone_foundry_step(config))
133+
sequence.add_step(_capture_foundry_revision_step(config))
62134
sequence.add_step(
63135
InContainer(
64136
ShellStep(command=SetupRPMRepoFromURL(repo_file_url)),
@@ -79,4 +151,27 @@ def rpm(config: DockerConfig, repo_file_url: str):
79151
docker_environment=config,
80152
)
81153
)
154+
sequence.add_step(
155+
InContainer(
156+
ShellStep(command=InstallBuiltPackages("RPM")),
157+
docker_environment=config,
158+
container_commit=True,
159+
)
160+
)
161+
sequence.add_step(_save_packages_step(config, "*.rpm"))
162+
sequence.add_step(
163+
InContainer(
164+
ShellStep(
165+
command=InstallRPMPackages(packages=["MariaDB-server", "MariaDB-test"])
166+
),
167+
docker_environment=config,
168+
container_commit=True,
169+
)
170+
)
171+
sequence.add_step(
172+
InContainer(
173+
ShellStep(command=RunPluginMTRSuite("/usr/share/mysql-test")),
174+
docker_environment=config,
175+
)
176+
)
82177
return sequence

configuration/steps/commands/foundry.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,63 @@ def as_cmd_arg(self) -> list[str]:
1616
"-exc",
1717
util.Interpolate(f"cmake -D{self.package_type}=1 -P run.cmake %(prop:plugin)s"),
1818
]
19+
20+
21+
class InstallBuiltPackages(Command):
22+
# Installs whatever run.cmake just built (copied next to run.cmake, see
23+
# run.cmake's `file(COPY ${packages} DESTINATION "${b}/..")`).
24+
def __init__(self, package_type: str, workdir: PurePath = PurePath(".")):
25+
self.package_type = package_type
26+
super().__init__(
27+
name=f"Install built plugin packages ({package_type})",
28+
workdir=workdir,
29+
user="root",
30+
)
31+
32+
def as_cmd_arg(self) -> list[str]:
33+
if self.package_type == "RPM":
34+
install_cmd = "dnf install -y ./*.rpm"
35+
else:
36+
install_cmd = "apt-get install -y ./*.deb"
37+
return ["bash", "-exc", f"set -euo pipefail\n{install_cmd}"]
38+
39+
40+
class RunPluginMTRSuite(Command):
41+
# Discovers the plugin's own MTR suite(s) the way mtr-suites.sh does --
42+
# any directory under a mysql-test/ (or mysql-test/suite/) directory in
43+
# the plugin's fetched source (<plugin>.build/) that has a suite.opt --
44+
# copies them into the installed suite tree, and runs them. A plugin
45+
# with no MTR suite is skipped rather than failing the build.
46+
def __init__(self, mtr_base_dir: str, workdir: PurePath = PurePath(".")):
47+
self.mtr_base_dir = mtr_base_dir
48+
super().__init__(name="Run plugin MTR suite", workdir=workdir, user="root")
49+
50+
def as_cmd_arg(self) -> list[str]:
51+
return [
52+
"bash",
53+
"-exc",
54+
util.Interpolate(
55+
f"""
56+
set -euo pipefail
57+
58+
plugin_build="%(prop:plugin)s.build"
59+
suites=""
60+
for mt in $(find "$plugin_build" -type d -name mysql-test 2>/dev/null); do
61+
for d in "$mt"/*/ "$mt"/suite/*/; do
62+
[ -f "${{d}}suite.opt" ] || continue
63+
name=$(basename "$d")
64+
cp -r "$d" "{self.mtr_base_dir}/suite/$name"
65+
suites="$suites,$name"
66+
done
67+
done
68+
suites=$(echo "$suites" | sed 's/^,//')
69+
70+
if [ -z "$suites" ]; then
71+
echo "No MTR suite found for plugin %(prop:plugin)s -- skipping"
72+
exit 0
73+
fi
74+
75+
perl {self.mtr_base_dir}/mysql-test-run.pl --suite="$suites" --user=root
76+
"""
77+
),
78+
]

0 commit comments

Comments
 (0)