Skip to content

Commit

Permalink
switch docker tag to commit/release-version (#42)
Browse files Browse the repository at this point in the history
* rm --tag and replace with commit/release version, use build-type skip for skip-docker-build

* address comments
  • Loading branch information
gregcusack authored May 23, 2024
1 parent c72446d commit f2ea49d
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 66 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ cargo run --bin cluster --
--slots-per-epoch <slots-per-epoch>
# docker config
--registry <docker-registry> # e.g. gregcusack
--tag <docker-image-tag> # e.g. v1
--base-image <base-image> # e.g. ubuntu:20.04
--image-name <docker-image-name> # e.g. cluster-image
# validator config
Expand Down
2 changes: 1 addition & 1 deletion src/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct DockerImage {
registry: String,
validator_type: ValidatorType,
image_name: String,
tag: String,
tag: String, // commit (`abcd1234`) or version (`v1.18.12`)
}

impl DockerImage {
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pub fn cat_file(path: &PathBuf) -> std::io::Result<()> {
let mut file = File::open(path)?;
let mut contents = String::new();
file.read_to_string(&mut contents)?;
info!("{:?}:\n{contents}", path.file_name());
debug!("{:?}:\n{contents}", path.file_name());

Ok(())
}
Expand Down
30 changes: 7 additions & 23 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ fn parse_matches() -> clap::ArgMatches {
.takes_value(true)
.possible_values(BuildType::VARIANTS)
.default_value(BuildType::Release.into())
.help("Specifies the build type: skip, debug, or release."),
.help("Specifies the build type: skip, debug, or release.
Skip -> Will not build release or local repo and will not push to container registry"),
)
.arg(
Arg::with_name("release_channel")
Expand Down Expand Up @@ -145,11 +146,6 @@ fn parse_matches() -> clap::ArgMatches {
.help("Genesis config. bootstrap validator stake sol"),
)
//Docker config
.arg(
Arg::with_name("skip_docker_build")
.long("skip-docker-build")
.help("Skips build Docker images"),
)
.arg(
Arg::with_name("registry_name")
.long("registry")
Expand All @@ -161,7 +157,7 @@ fn parse_matches() -> clap::ArgMatches {
Arg::with_name("image_name")
.long("image-name")
.takes_value(true)
.default_value("k8s-cluster-image")
.default_value("k8s-image")
.help("Docker image name. Will be prepended with validator_type (bootstrap or validator)"),
)
.arg(
Expand All @@ -171,13 +167,6 @@ fn parse_matches() -> clap::ArgMatches {
.default_value("ubuntu:20.04")
.help("Docker base image"),
)
.arg(
Arg::with_name("image_tag")
.long("tag")
.takes_value(true)
.default_value("latest")
.help("Docker image tag."),
)
// Bootstrap/Validator Config
.arg(
Arg::with_name("limit_ledger_size")
Expand Down Expand Up @@ -429,9 +418,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

let build_config = BuildConfig::new(
deploy_method.clone(),
build_type,
build_type.clone(),
solana_root.get_root_path(),
!matches.is_present("skip_docker_build"),
);

let genesis_flags = GenesisFlags {
Expand Down Expand Up @@ -538,8 +526,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.into());
}

build_config.prepare().await?;
info!("Setup Validator Environment");
let image_tag = build_config.prepare().await?;
info!("Setup Validator Environment. Image tag: {image_tag}");

let config_directory = solana_root.get_root_path().join("config-k8s");
let mut genesis = Genesis::new(config_directory.clone(), genesis_flags);
Expand Down Expand Up @@ -586,10 +574,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

let registry_name = matches.value_of("registry_name").unwrap().to_string();
let image_name = matches.value_of("image_name").unwrap().to_string();
let image_tag = matches
.value_of("image_tag")
.unwrap_or_default()
.to_string();

let mut cluster_images = ClusterImages::default();

Expand Down Expand Up @@ -631,7 +615,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
cluster_images.set_item(client, ValidatorType::Client(client_index));
}

if build_config.docker_build() {
if build_type != BuildType::Skip {
for v in cluster_images.get_all() {
docker.build_image(solana_root.get_root_path(), v.image())?;
info!("Built {} image", v.validator_type());
Expand Down
75 changes: 36 additions & 39 deletions src/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub enum DeployMethod {
ReleaseChannel(String),
}

#[derive(PartialEq, EnumString, IntoStaticStr, VariantNames)]
#[derive(PartialEq, EnumString, IntoStaticStr, VariantNames, Clone)]
#[strum(serialize_all = "lowercase")]
pub enum BuildType {
Skip, // use Agave build from the previous run
Expand All @@ -29,51 +29,42 @@ pub struct BuildConfig {
deploy_method: DeployMethod,
build_type: BuildType,
solana_root_path: PathBuf,
docker_build: bool,
}

impl BuildConfig {
pub fn new(
deploy_method: DeployMethod,
build_type: BuildType,
solana_root_path: &Path,
docker_build: bool,
) -> Self {
BuildConfig {
deploy_method,
build_type,
solana_root_path: solana_root_path.to_path_buf(),
docker_build,
}
}

pub fn docker_build(&self) -> bool {
self.docker_build
}

pub async fn prepare(&self) -> Result<(), Box<dyn Error>> {
if self.build_type == BuildType::Skip {
info!("skipping build");
return Ok(());
}
pub async fn prepare(&self) -> Result<String, Box<dyn Error>> {
match &self.deploy_method {
DeployMethod::ReleaseChannel(channel) => {
if self.build_type == BuildType::Skip {
return Ok(channel.clone());
}
let tar_directory = self.setup_tar_deploy(channel).await?;
info!("Successfully setup tar file");
cat_file(&tar_directory.join("version.yml"))?;
Ok(channel.clone())
}
DeployMethod::Local(_) => {
self.build()?;
let image_tag = self.build()?;
Ok(image_tag)
}
}
info!("Completed Prepare Deploy");
Ok(())
}

async fn setup_tar_deploy(&self, release_channel: &String) -> Result<PathBuf, Box<dyn Error>> {
let file_name = "solana-release";
let tar_filename = format!("{file_name}.tar.bz2");
info!("tar file: {tar_filename}");
self.download_release_from_channel(&tar_filename, release_channel)
.await?;

Expand All @@ -90,30 +81,32 @@ impl BuildConfig {
Ok(release_dir)
}

fn build(&self) -> Result<(), Box<dyn Error>> {
fn build(&self) -> Result<String, Box<dyn Error>> {
let start_time = Instant::now();
let build_variant = if self.build_type == BuildType::Debug {
"--debug"
} else {
""
};

let install_directory = self.solana_root_path.join("farf");
let install_script = self.solana_root_path.join("scripts/cargo-install-all.sh");
match std::process::Command::new(install_script)
.arg(install_directory)
.arg(build_variant)
.arg("--validator-only")
.status()
{
Ok(result) => {
if result.success() {
info!("Successfully built validator")
} else {
return Err("Failed to build validator".into());
if self.build_type != BuildType::Skip {
let build_variant = if self.build_type == BuildType::Debug {
"--debug"
} else {
""
};

let install_directory = self.solana_root_path.join("farf");
let install_script = self.solana_root_path.join("scripts/cargo-install-all.sh");
match std::process::Command::new(install_script)
.arg(install_directory)
.arg(build_variant)
.arg("--validator-only")
.status()
{
Ok(result) => {
if result.success() {
info!("Successfully built validator")
} else {
return Err("Failed to build validator".into());
}
}
Err(err) => return Err(Box::new(err)),
}
Err(err) => return Err(Box::new(err)),
}

let solana_repo = Repository::open(self.solana_root_path.as_path())?;
Expand All @@ -126,12 +119,14 @@ impl BuildConfig {

// Check if current commit is associated with a tag
let mut note = branch;
let mut commit_tag = None;
for tag in (&solana_repo.tag_names(None)?).into_iter().flatten() {
// Get the target object of the tag
let tag_object = solana_repo.revparse_single(tag)?.id();
// Check if the commit associated with the tag is the same as the current commit
if tag_object == commit {
info!("The current commit is associated with tag: {tag}");
commit_tag = Some(tag.to_string());
note = tag_object.to_string();
break;
}
Expand All @@ -142,8 +137,10 @@ impl BuildConfig {
std::fs::write(self.solana_root_path.join("farf/version.yml"), content)
.expect("Failed to write version.yml");

let label = commit_tag.unwrap_or_else(|| commit.to_string()[..8].to_string());

info!("Build took {:.3?} seconds", start_time.elapsed());
Ok(())
Ok(label)
}

async fn download_release_from_channel(
Expand Down
2 changes: 1 addition & 1 deletion src/startup_scripts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ run_delegate_stake() {
echo "delegated stake"
fi
solana --url $LOAD_BALANCER_RPC_URL --keypair $IDENTITY_FILE stakes validator-accounts/stake.json
solana --url $LOAD_BALANCER_RPC_URL --keypair $IDENTITY_FILE stake-account validator-accounts/stake.json
}
echo "get airdrop and create vote account"
Expand Down

0 comments on commit f2ea49d

Please sign in to comment.