Skip to content

updates bootstrap to include version4 #2404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 54 additions & 18 deletions bootstrap/bootstrap/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bootstrap/bootstrap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ will do a multiple stage bootstrap. Currently this is only two stages:
## How to works

- 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
- After internet service is fully started, bootstrap will start to download flists needed to for zos node to work properly
- After internet service is fully started, bootstrap will start to download flists needed for zos node to work properly
- As described above bootstrap run in two stages:
- 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
- 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
116 changes: 9 additions & 107 deletions bootstrap/bootstrap/src/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,63 +8,16 @@ use super::workdir::WorkDir;
use super::zfs::Zfs;
use super::zinit;
use anyhow::{Context, Result};
use config::{RunMode, Version};
use config::Version;
use retry;

const ZOS_REPO: &str = "tf-zos";
const BIN_REPO_V2: &str = "tf-zos-bins";
const BIN_REPO_V3: &str = "tf-zos-v3-bins";

const FLIST_INFO_FILE: &str = "/tmp/flist.info";
const FLIST_NAME_FILE: &str = "/tmp/flist.name";
const FLIST_TAG_FILE: &str = "/tmp/tag.info";
const BOOTSTAP_FLIST: &str = "bootstrap:latest.flist";

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

fn bootstrap_zos(cfg: &config::Config) -> Result<()> {
let flist = match &cfg.runmode {
RunMode::Prod => match &cfg.version {
Version::V3 => "zos:production-3:latest.flist",
},
RunMode::Dev => match &cfg.version {
Version::V3 => "zos:development-3:latest.flist",
},
RunMode::Test => match &cfg.version {
Version::V3 => "zos:testing-3:latest.flist",
},
RunMode::QA => match &cfg.version {
Version::V3 => "zos:qa-3:latest.flist",
},
};

debug!("using flist: {}/{}", ZOS_REPO, flist);
let repo = hub::Repo::new(ZOS_REPO);
let flist = retry::retry(retry::delay::Exponential::from_millis(200), || {
info!("get flist info: {}", flist);
let info = match repo.get(flist) {
Ok(info) => info,
Err(err) => {
error!("failed to get info: {}", err);
bail!("failed to get info: {}", err);
}
};

Ok(info)
});

let flist = match flist {
Ok(flist) => flist,
Err(e) => bail!("failed to download flist: {:?}", e),
};

// write down boot info for other system components (like upgraded)
flist.write(FLIST_INFO_FILE)?;
std::fs::write(FLIST_NAME_FILE, format!("{}/{}", ZOS_REPO, flist.name))?;

install_package(&flist)
}

/// update stage make sure we are running latest
/// version of bootstrap
pub fn update(_cfg: &config::Config) -> Result<()> {
Expand Down Expand Up @@ -116,11 +69,16 @@ pub fn install(cfg: &config::Config) -> Result<()> {
let repo = Repo::new(ZOS_REPO);

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

let mut listname = runmode.clone();
match cfg.version {
Version::V3 => {}
Version::V4 => listname = format!("{}-v4", runmode),
}
// we need to list all taglinks
let mut tag = None;
for list in repo.list()? {
if list.kind == Kind::TagLink && list.name == runmode {
if list.kind == Kind::TagLink && list.name == listname {
tag = Some(list);
break;
}
Expand All @@ -133,12 +91,7 @@ pub fn install(cfg: &config::Config) -> Result<()> {
let result = WorkDir::run(WORKDIR, || -> Result<()> {
match tag {
None => {
// old style bootstrap.
// we need to install binaries and zos from 2 different
// places
// we also track which binaries are installed individually
install_packages_old(cfg)?;
bootstrap_zos(cfg)
bail!("no tag found attached to this version")
}
Some(tag) => {
// new style bootstrap
Expand All @@ -160,57 +113,6 @@ pub fn install(cfg: &config::Config) -> Result<()> {
result
}

fn install_packages_old(cfg: &config::Config) -> Result<()> {
let name = match cfg.version {
Version::V3 => BIN_REPO_V3,
};

let repo = match cfg.runmode {
config::RunMode::Prod => name.into(),
config::RunMode::Dev => format!("{}.dev", name),
config::RunMode::Test => format!("{}.test", name),
config::RunMode::QA => format!("{}.qanet", name),
};

let client = hub::Repo::new(&repo);
let packages = retry::retry(retry::delay::Exponential::from_millis(200), || {
info!("list packages in: {}", BIN_REPO_V2);
//the full point of this match is the logging.
let packages = match client.list() {
Ok(info) => info,
Err(err) => {
error!("failed to list repo '{}': {}", BIN_REPO_V2, err);
bail!("failed to list repo '{}': {}", BIN_REPO_V2, err);
}
};

Ok(packages)
});

let packages = match packages {
Ok(packages) => packages,
Err(err) => bail!("failed to list '{}': {:?}", BIN_REPO_V2, err),
};

let mut map = std::collections::HashMap::new();
for package in packages.iter() {
match install_package(package) {
Ok(_) => {}
Err(err) => warn!("failed to install package '{}': {}", package.url, err),
};

map.insert(format!("{}/{}", repo, package.name), package.clone());
}

let output = std::fs::OpenOptions::new()
.create(true)
.write(true)
.open("/tmp/bins.info")?;
serde_json::to_writer(&output, &map)?;

Ok(())
}

fn install_packages(packages: &[Flist]) -> Result<()> {
for package in packages {
install_package(&package)?;
Expand Down
4 changes: 3 additions & 1 deletion bootstrap/bootstrap/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ impl Display for RunMode {
#[derive(Debug)]
pub enum Version {
V3,
V4,
}

fn runmode() -> Result<RunMode> {
Expand Down Expand Up @@ -64,6 +65,7 @@ fn version() -> Result<Version> {
Some(input) => match input {
Some(input) => match input.as_ref() {
"v3" => Version::V3,
"v4" => Version::V4,
m => {
bail!("unknown version: {}", m);
}
Expand Down Expand Up @@ -119,7 +121,7 @@ impl Config {
}

Ok(Config {
stage: stage,
stage,
debug: matches.occurrences_of("debug") > 0,
runmode: runmode()?,
version: version()?,
Expand Down
5 changes: 3 additions & 2 deletions bootstrap/bootstrap/src/kparams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ mod tests {

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