Skip to content

Commit 81ecfd6

Browse files
patricearruda84MongoDB Bot
authored and
MongoDB Bot
committed
SERVER-104338: Update packager.py and packager_enterprise.py script to build crypt packages. (#35905)
GitOrigin-RevId: 1e2aab2084fd6e7ff99cdf6301e80b900cc70c41
1 parent 23df9c8 commit 81ecfd6

File tree

2 files changed

+59
-15
lines changed

2 files changed

+59
-15
lines changed

buildscripts/packager.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,13 @@ def get_args(distros, arch_choices):
453453
required=True,
454454
type=lambda x: is_valid_file(parser, x),
455455
)
456+
parser.add_argument(
457+
"-c",
458+
"--crypt_spec",
459+
help="use the crypt spec to build the requested package",
460+
required=False,
461+
action="store_true",
462+
)
456463

457464
args = parser.parse_args()
458465

buildscripts/packager_enterprise.py

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,45 @@ def suffix(self):
5959
else:
6060
return "-enterprise" if int(self.ver.split(".")[1]) % 2 == 0 else "-enterprise-unstable"
6161

62+
def move_required_contents(self):
63+
"""Move the required contents to the current working directory.
64+
65+
Below in the for loop it's the required list of files that needs
66+
to be moved from the extracted tarball to the current working
67+
directory. The root path of the tarball content starts with
68+
mongodb-linux-<suffix> so we glob since the suffix of the root path
69+
is not a fixed text.
70+
"""
71+
release_dir = glob("mongodb-linux-*")[0]
72+
for release_file in (
73+
"bin",
74+
"LICENSE-Enterprise.txt",
75+
"README",
76+
"THIRD-PARTY-NOTICES",
77+
"MPL-2",
78+
):
79+
os.rename("%s/%s" % (release_dir, release_file), release_file)
80+
os.rmdir(release_dir)
81+
82+
83+
class EnterpriseCryptSpec(EnterpriseSpec):
84+
"""EnterpriseCryptSpec class."""
85+
86+
def suffix(self):
87+
"""Suffix."""
88+
if int(self.ver.split(".")[1]) == 0:
89+
return "-enterprise-crypt-v1"
90+
return "-enterprise-unstable-crypt-v1"
91+
92+
def move_required_contents(self):
93+
"""Move the required contents to the current working directory
94+
95+
The files that were extracted from the tarball file are already
96+
in the current working directory. It does not have a mongodb-linux-...
97+
as the root content of the tarball file is flat.
98+
"""
99+
pass
100+
62101

63102
class EnterpriseDistro(packager.Distro):
64103
"""EnterpriseDistro class."""
@@ -174,7 +213,7 @@ def main():
174213

175214
args = packager.get_args(distros, ARCH_CHOICES)
176215

177-
spec = EnterpriseSpec(args.server_version, args.metadata_gitspec, args.release_number)
216+
spec = get_enterprise_spec(args)
178217

179218
oldcwd = os.getcwd()
180219
srcdir = oldcwd + "/../"
@@ -211,6 +250,13 @@ def main():
211250
os.chdir(oldcwd)
212251

213252

253+
def get_enterprise_spec(args):
254+
"""Get the EnterpriseSpec."""
255+
if args.crypt_spec:
256+
return EnterpriseCryptSpec(args.server_version, args.metadata_gitspec, args.release_number)
257+
return EnterpriseSpec(args.server_version, args.metadata_gitspec, args.release_number)
258+
259+
214260
def tarfile(build_os, arch, spec):
215261
"""Return the location where we store the downloaded tarball for this package."""
216262
return "dl/mongodb-linux-%s-enterprise-%s-%s.tar.gz" % (spec.version(), build_os, arch)
@@ -236,30 +282,21 @@ def setupdir(distro, build_os, arch, spec):
236282

237283
def unpack_binaries_into(build_os, arch, spec, where):
238284
"""Unpack the tarfile for (build_os, arch, spec) into directory where."""
239-
rootdir = os.getcwd()
285+
root_dir = os.getcwd()
240286
packager.ensure_dir(where)
241287
# Note: POSIX tar doesn't require support for gtar's "-C" option,
242288
# and Python's tarfile module prior to Python 2.7 doesn't have the
243289
# features to make this detail easy. So we'll just do the dumb
244290
# thing and chdir into where and run tar there.
245291
os.chdir(where)
246292
try:
247-
packager.sysassert(["tar", "xvzf", rootdir + "/" + tarfile(build_os, arch, spec)])
248-
release_dir = glob("mongodb-linux-*")[0]
249-
for releasefile in (
250-
"bin",
251-
"LICENSE-Enterprise.txt",
252-
"README",
253-
"THIRD-PARTY-NOTICES",
254-
"MPL-2",
255-
):
256-
os.rename("%s/%s" % (release_dir, releasefile), releasefile)
257-
os.rmdir(release_dir)
293+
packager.sysassert(["tar", "xvzf", root_dir + "/" + tarfile(build_os, arch, spec)])
294+
spec.move_required_contents()
258295
except Exception:
259296
exc = sys.exc_info()[1]
260-
os.chdir(rootdir)
297+
os.chdir(root_dir)
261298
raise exc
262-
os.chdir(rootdir)
299+
os.chdir(root_dir)
263300

264301

265302
def make_package(distro, build_os, arch, spec, srcdir):

0 commit comments

Comments
 (0)