Skip to content

Commit 712a314

Browse files
ashraffoudamaxux
authored andcommitted
updates bootstrap to include version4
Signed-off-by: Ashraf Fouda <[email protected]>
1 parent 934ea53 commit 712a314

File tree

5 files changed

+70
-129
lines changed

5 files changed

+70
-129
lines changed

bootstrap/bootstrap/Cargo.lock

+54-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bootstrap/bootstrap/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ will do a multiple stage bootstrap. Currently this is only two stages:
1717
## How to works
1818

1919
- Bootstrap is used by [0-initramfs](https://github.com/threefoldtech/0-initramfs/blob/development-zos-v3/packages/modules.sh) to basically add `internet` and `bootstrap` services to the base image
20-
- After internet service is fully started, bootstrap will start to download flists needed to for zos node to work properly
20+
- After internet service is fully started, bootstrap will start to download flists needed for zos node to work properly
2121
- As described above bootstrap run in two stages:
2222
- The first stage is used to update bootstrap itself, and it is done like that to avoid re-building the image if we only changed the bootstrap code. this update is basically done from `tf-autobuilder` repo in the [hub/tf-autobuilder](https://hub.grid.tf/tf-autobuilder) and download the latest bootstrap flist
2323
- For the second stage bootstrap will download the flists for that env. bootstrap cares about `runmode` argument that we pass during the start of the node. for example if we passed `runmode=dev` it will get the the tag `development` under [hub/tf-zos](https://hub.grid.tf/tf-zos) each tag is linked to a sub-directory where all flists for this env exists to be downloaded and installed on the node

bootstrap/bootstrap/src/bootstrap.rs

+9-107
Original file line numberDiff line numberDiff line change
@@ -8,63 +8,16 @@ use super::workdir::WorkDir;
88
use super::zfs::Zfs;
99
use super::zinit;
1010
use anyhow::{Context, Result};
11-
use config::{RunMode, Version};
11+
use config::Version;
1212
use retry;
1313

1414
const ZOS_REPO: &str = "tf-zos";
15-
const BIN_REPO_V2: &str = "tf-zos-bins";
16-
const BIN_REPO_V3: &str = "tf-zos-v3-bins";
1715

18-
const FLIST_INFO_FILE: &str = "/tmp/flist.info";
19-
const FLIST_NAME_FILE: &str = "/tmp/flist.name";
2016
const FLIST_TAG_FILE: &str = "/tmp/tag.info";
2117
const BOOTSTAP_FLIST: &str = "bootstrap:latest.flist";
2218

2319
const WORKDIR: &str = "/tmp/bootstrap";
2420

25-
fn bootstrap_zos(cfg: &config::Config) -> Result<()> {
26-
let flist = match &cfg.runmode {
27-
RunMode::Prod => match &cfg.version {
28-
Version::V3 => "zos:production-3:latest.flist",
29-
},
30-
RunMode::Dev => match &cfg.version {
31-
Version::V3 => "zos:development-3:latest.flist",
32-
},
33-
RunMode::Test => match &cfg.version {
34-
Version::V3 => "zos:testing-3:latest.flist",
35-
},
36-
RunMode::QA => match &cfg.version {
37-
Version::V3 => "zos:qa-3:latest.flist",
38-
},
39-
};
40-
41-
debug!("using flist: {}/{}", ZOS_REPO, flist);
42-
let repo = hub::Repo::new(ZOS_REPO);
43-
let flist = retry::retry(retry::delay::Exponential::from_millis(200), || {
44-
info!("get flist info: {}", flist);
45-
let info = match repo.get(flist) {
46-
Ok(info) => info,
47-
Err(err) => {
48-
error!("failed to get info: {}", err);
49-
bail!("failed to get info: {}", err);
50-
}
51-
};
52-
53-
Ok(info)
54-
});
55-
56-
let flist = match flist {
57-
Ok(flist) => flist,
58-
Err(e) => bail!("failed to download flist: {:?}", e),
59-
};
60-
61-
// write down boot info for other system components (like upgraded)
62-
flist.write(FLIST_INFO_FILE)?;
63-
std::fs::write(FLIST_NAME_FILE, format!("{}/{}", ZOS_REPO, flist.name))?;
64-
65-
install_package(&flist)
66-
}
67-
6821
/// update stage make sure we are running latest
6922
/// version of bootstrap
7023
pub fn update(_cfg: &config::Config) -> Result<()> {
@@ -116,11 +69,16 @@ pub fn install(cfg: &config::Config) -> Result<()> {
11669
let repo = Repo::new(ZOS_REPO);
11770

11871
let runmode = cfg.runmode.to_string();
119-
// we need to list all taglinks inside the repo
12072

73+
let mut listname = runmode.clone();
74+
match cfg.version {
75+
Version::V3 => {}
76+
Version::V4 => listname = format!("{}-v4", runmode),
77+
}
78+
// we need to list all taglinks
12179
let mut tag = None;
12280
for list in repo.list()? {
123-
if list.kind == Kind::TagLink && list.name == runmode {
81+
if list.kind == Kind::TagLink && list.name == listname {
12482
tag = Some(list);
12583
break;
12684
}
@@ -133,12 +91,7 @@ pub fn install(cfg: &config::Config) -> Result<()> {
13391
let result = WorkDir::run(WORKDIR, || -> Result<()> {
13492
match tag {
13593
None => {
136-
// old style bootstrap.
137-
// we need to install binaries and zos from 2 different
138-
// places
139-
// we also track which binaries are installed individually
140-
install_packages_old(cfg)?;
141-
bootstrap_zos(cfg)
94+
bail!("no tag found attached to this version")
14295
}
14396
Some(tag) => {
14497
// new style bootstrap
@@ -160,57 +113,6 @@ pub fn install(cfg: &config::Config) -> Result<()> {
160113
result
161114
}
162115

163-
fn install_packages_old(cfg: &config::Config) -> Result<()> {
164-
let name = match cfg.version {
165-
Version::V3 => BIN_REPO_V3,
166-
};
167-
168-
let repo = match cfg.runmode {
169-
config::RunMode::Prod => name.into(),
170-
config::RunMode::Dev => format!("{}.dev", name),
171-
config::RunMode::Test => format!("{}.test", name),
172-
config::RunMode::QA => format!("{}.qanet", name),
173-
};
174-
175-
let client = hub::Repo::new(&repo);
176-
let packages = retry::retry(retry::delay::Exponential::from_millis(200), || {
177-
info!("list packages in: {}", BIN_REPO_V2);
178-
//the full point of this match is the logging.
179-
let packages = match client.list() {
180-
Ok(info) => info,
181-
Err(err) => {
182-
error!("failed to list repo '{}': {}", BIN_REPO_V2, err);
183-
bail!("failed to list repo '{}': {}", BIN_REPO_V2, err);
184-
}
185-
};
186-
187-
Ok(packages)
188-
});
189-
190-
let packages = match packages {
191-
Ok(packages) => packages,
192-
Err(err) => bail!("failed to list '{}': {:?}", BIN_REPO_V2, err),
193-
};
194-
195-
let mut map = std::collections::HashMap::new();
196-
for package in packages.iter() {
197-
match install_package(package) {
198-
Ok(_) => {}
199-
Err(err) => warn!("failed to install package '{}': {}", package.url, err),
200-
};
201-
202-
map.insert(format!("{}/{}", repo, package.name), package.clone());
203-
}
204-
205-
let output = std::fs::OpenOptions::new()
206-
.create(true)
207-
.write(true)
208-
.open("/tmp/bins.info")?;
209-
serde_json::to_writer(&output, &map)?;
210-
211-
Ok(())
212-
}
213-
214116
fn install_packages(packages: &[Flist]) -> Result<()> {
215117
for package in packages {
216118
install_package(&package)?;

bootstrap/bootstrap/src/config.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ impl Display for RunMode {
2828
#[derive(Debug)]
2929
pub enum Version {
3030
V3,
31+
V4,
3132
}
3233

3334
fn runmode() -> Result<RunMode> {
@@ -64,6 +65,7 @@ fn version() -> Result<Version> {
6465
Some(input) => match input {
6566
Some(input) => match input.as_ref() {
6667
"v3" => Version::V3,
68+
"v4" => Version::V4,
6769
m => {
6870
bail!("unknown version: {}", m);
6971
}
@@ -119,7 +121,7 @@ impl Config {
119121
}
120122

121123
Ok(Config {
122-
stage: stage,
124+
stage,
123125
debug: matches.occurrences_of("debug") > 0,
124126
runmode: runmode()?,
125127
version: version()?,

bootstrap/bootstrap/src/kparams.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ mod tests {
4040

4141
#[test]
4242
fn test_parse() -> Result<(), Error> {
43-
let input: &str = "initrd=initramfs-linux.img root=UUID=10f9e7bb-ba63-4fbd-a95e-c78b5496cfbe rootflags=subvol=root rw b43.allhwsupport=1";
43+
let input: &str = "initrd=initramfs-linux.img version=v3 root=UUID=10f9e7bb-ba63-4fbd-a95e-c78b5496cfbe rootflags=subvol=root rw b43.allhwsupport=1";
4444
let result = parse(input.as_bytes())?;
45-
assert_eq!(result.len(), 5);
45+
assert_eq!(result.len(), 6);
4646
assert_eq!(result["rw"], None);
47+
assert_eq!(result["version"], Some(String::from("v3")));
4748
assert_eq!(result["rootflags"], Some(String::from("subvol=root")));
4849
Ok(())
4950
}

0 commit comments

Comments
 (0)