Skip to content

Commit 64ff5d2

Browse files
committed
Adding bootstrap mirror configs.
1 parent 798a216 commit 64ff5d2

File tree

2 files changed

+47
-15
lines changed

2 files changed

+47
-15
lines changed

stackinator/builder.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -314,15 +314,14 @@ def generate(self, recipe):
314314
fid.write(global_packages_yaml)
315315

316316
# generate a mirrors.yaml file if build caches have been configured
317-
key_store = self.path / ".gnupg"
318-
mirrors = recipe.mirrors
319-
if mirrors:
320-
mirrors.key_setup(recipe.mirrors, config_path, key_store)
321-
dest = config_path / "mirrors.yaml"
322-
self._logger.debug(f"generate the spack mirrors.yaml: {dest}")
323-
mirrors.create_spack_mirrors_yaml(dest)
324-
325-
# Setup bootstrap mirror configs.
317+
if recipe.mirrors:
318+
recipe.mirrors.key_setup(config_path)
319+
320+
self._logger.debug(f"Generating the spack mirrors.yaml in '{config_path}'")
321+
recipe.mirrors.create_spack_mirrors_yaml(config_path/'mirrors.yaml')
322+
323+
# Setup bootstrap mirror configs.
324+
recipe.mirrors.create_bootstrap_configs(config_path)
326325

327326
# Add custom spack package recipes, configured via Spack repos.
328327
# Step 1: copy Spack repos to store_path where they will be used to

stackinator/mirror.py

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import pathlib
33
import urllib.request
44
import urllib.error
5-
from typing import Optional, List, Dict
5+
from typing import ByteString, Optional, List, Dict
66
import magic
77

88
import yaml
@@ -22,8 +22,10 @@ def __init__(self, system_config_root: pathlib.Path, cmdline_cache: Optional[str
2222

2323
self.mirrors = self._load_mirrors(cmdline_cache)
2424
self._check_mirrors()
25-
26-
self.build_cache_mirrors = [mirror for mirror in self.mirrors if mirror.get('buildcache', False)]
25+
26+
self.build_cache_mirror = ([mirror for mirror in self.mirrors if mirror.get('buildcache', False)]
27+
+ [None]).pop(0)
28+
self.bootstrap_mirrors = [mirror for mirror in self.mirrors if mirror.get('bootstrap', False)]
2729
self.keys = [mirror['key'] for mirror in self.mirrors if mirror.get('key') is not None]
2830

2931
def _load_mirrors(self, cmdline_cache: Optional[str]) -> List[Dict]:
@@ -107,12 +109,43 @@ def create_spack_mirrors_yaml(self, dest: pathlib.Path):
107109
with dest.open("w") as file:
108110
yaml.dump(raw, file, default_flow_style=False)
109111

110-
def bootstrap_setup(self, config_root: pathlib.Path):
112+
def create_bootstrap_configs(self, config_root: pathlib.Path):
111113
"""Create the bootstrap.yaml and bootstrap metadata dirs in our build dir."""
112114

115+
if not self.bootstrap_mirrors:
116+
return
117+
118+
bootstrap_yaml = {
119+
'sources': [],
120+
'trusted': {},
121+
}
122+
123+
for mirror in self.bootstrap_mirrors:
124+
name = mirror['name']
125+
bs_mirror_path = config_root/f'bootstrap/{name}'
126+
# Tell spack where to find the metadata for each bootstrap mirror.
127+
bootstrap_yaml['sources'].append(
128+
{
129+
'name': name,
130+
'metadata': bs_mirror_path,
131+
}
132+
)
133+
# And trust each one
134+
bootstrap_yaml['trusted'][name] = True
135+
136+
# Create the metadata dir and metadata.yaml
137+
bs_mirror_path.mkdir(parents=True)
138+
bs_mirror_yaml = {
139+
'type': 'install',
140+
'info': mirror['url'],
141+
}
142+
with (bs_mirror_path/'metadata.yaml').open('w') as file:
143+
yaml.dump(bs_mirror_yaml, file, default_flow_style=False)
144+
145+
with (config_root/'bootstrap.yaml').open('w') as file:
146+
yaml.dump(bootstrap_yaml, file, default_flow_style=False)
113147

114-
115-
def key_setup(self, key_store: pathlib.Path):
148+
def key_setup(self, config_root: pathlib.Path):
116149
"""Validate mirror keys, relocate to key_store, and update mirror config with new key paths."""
117150

118151
for mirror in self.mirrors:

0 commit comments

Comments
 (0)