-
Notifications
You must be signed in to change notification settings - Fork 2
feat: prerequisites check step as Step 1 in start #51
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| //! Binary and Docker image availability check for cluster startup. | ||
| //! | ||
| //! This module provides a unified check for all required binaries and Docker images | ||
| //! before starting the cluster. It provides clear error messages directing users to | ||
| //! build missing components. | ||
|
|
||
| use super::step::{SetupContext, Step}; | ||
| use crate::constants::{REQUIRED_BINARIES, REQUIRED_DOCKER_IMAGES}; | ||
| use crate::docker::core::image_exists; | ||
| use crate::paths::foc_devnet_bin; | ||
| use std::error::Error; | ||
| use tracing::info; | ||
|
|
||
| /// Check that all required binaries exist in the bin directory. | ||
| /// | ||
| /// This check runs early in cluster startup before any containers are started, | ||
| /// ensuring that we fail fast with a helpful message if binaries are missing. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns an error if any required binary is missing, listing all missing binaries | ||
| /// and providing instructions on how to build them. | ||
| fn check_all_binaries() -> Result<(), Box<dyn Error>> { | ||
| let bin_dir = foc_devnet_bin(); | ||
|
|
||
| let mut missing_binaries = Vec::new(); | ||
| let mut found_binaries = Vec::new(); | ||
|
|
||
| for binary_name in REQUIRED_BINARIES { | ||
| let binary_path = bin_dir.join(binary_name); | ||
| if binary_path.exists() { | ||
| found_binaries.push(*binary_name); | ||
| } else { | ||
| missing_binaries.push(*binary_name); | ||
| } | ||
| } | ||
|
|
||
| // Log what we found | ||
| for binary in &found_binaries { | ||
| info!("✓ Binary '{}' found", binary); | ||
| } | ||
|
|
||
| // If any binaries are missing, return an error with instructions | ||
| if !missing_binaries.is_empty() { | ||
| let missing_list = missing_binaries.join("', '"); | ||
| return Err(format!( | ||
| "Missing required binaries: '{}'\n\nPlease build them with 'foc-devnet build <name>' \ | ||
| (e.g., 'foc-devnet build lotus' or 'foc-devnet build curio')", | ||
| missing_list | ||
| ) | ||
| .into()); | ||
| } | ||
|
|
||
| info!("✓ All required binaries are available"); | ||
| Ok(()) | ||
| } | ||
redpanda-f marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /// Check that all required Docker images exist. | ||
| /// | ||
| /// This check runs early in cluster startup before any containers are started, | ||
| /// ensuring that we fail fast with a helpful message if Docker images are missing. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns an error if any required Docker image is missing, listing all missing images | ||
| /// and providing instructions on how to build them. | ||
| fn check_all_docker_images() -> Result<(), Box<dyn Error>> { | ||
| let mut missing_images = Vec::new(); | ||
| let mut found_images = Vec::new(); | ||
|
|
||
| for image_name in REQUIRED_DOCKER_IMAGES { | ||
| let exists = image_exists(image_name) | ||
| .map_err(|e| format!("Failed to check Docker image '{}': {}", image_name, e))?; | ||
|
|
||
| if exists { | ||
| found_images.push(*image_name); | ||
| } else { | ||
| missing_images.push(*image_name); | ||
| } | ||
| } | ||
|
|
||
| // Log what we found | ||
| for image in &found_images { | ||
| info!("✓ Docker image '{}' found", image); | ||
| } | ||
|
|
||
| // If any images are missing, return an error with instructions | ||
| if !missing_images.is_empty() { | ||
| let missing_list = missing_images.join("', '"); | ||
| return Err(format!( | ||
| "Missing required Docker images: '{}'\n\nPlease run 'foc-devnet init' to build all Docker images.", | ||
| missing_list | ||
| ) | ||
| .into()); | ||
| } | ||
|
|
||
| info!("✓ All required Docker images are available"); | ||
| Ok(()) | ||
| } | ||
|
|
||
| /// Prerequisites check step for cluster startup. | ||
| /// | ||
| /// This step verifies that all required binaries and Docker images are available | ||
| /// before starting any containers. It runs as the very first step in the startup sequence. | ||
| pub struct PrerequisitesCheckStep; | ||
|
|
||
| impl PrerequisitesCheckStep { | ||
| /// Create a new PrerequisitesCheckStep | ||
| pub fn new() -> Self { | ||
| Self | ||
| } | ||
| } | ||
|
|
||
| impl Default for PrerequisitesCheckStep { | ||
| fn default() -> Self { | ||
| Self::new() | ||
| } | ||
| } | ||
|
|
||
| impl Step for PrerequisitesCheckStep { | ||
| fn name(&self) -> &str { | ||
| "Prerequisites Check (Binaries & Docker Images)" | ||
| } | ||
|
|
||
| fn pre_execute(&self, _context: &SetupContext) -> Result<(), Box<dyn Error>> { | ||
| // No pre-checks needed | ||
| Ok(()) | ||
| } | ||
|
|
||
| fn execute(&self, _context: &SetupContext) -> Result<(), Box<dyn Error>> { | ||
| check_all_binaries()?; | ||
| check_all_docker_images()?; | ||
| Ok(()) | ||
| } | ||
|
|
||
| fn post_execute(&self, _context: &SetupContext) -> Result<(), Box<dyn Error>> { | ||
| // No post-checks needed | ||
| Ok(()) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,26 @@ pub const YUGABYTE_DOCKER_IMAGE: &str = "foc-yugabyte"; | |
| pub const CURIO_DOCKER_IMAGE: &str = "foc-curio"; | ||
| pub const PORTAINER_DOCKER_IMAGE: &str = "foc-portainer"; | ||
|
|
||
| /// Required binaries for cluster startup | ||
| pub const REQUIRED_BINARIES: &[&str] = &[ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we also check for Docker as part of #29 ?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not necessary. Docker sock failure is pretty evident in later part of the program anyways. |
||
| "lotus", | ||
| "lotus-miner", | ||
| "lotus-shed", | ||
| "lotus-seed", | ||
| "curio", | ||
| "pdptool", | ||
| "sptool", | ||
| ]; | ||
|
|
||
| /// Required Docker images for cluster startup | ||
| pub const REQUIRED_DOCKER_IMAGES: &[&str] = &[ | ||
rvagg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| LOTUS_DOCKER_IMAGE, | ||
| LOTUS_MINER_DOCKER_IMAGE, | ||
| BUILDER_DOCKER_IMAGE, | ||
| YUGABYTE_DOCKER_IMAGE, | ||
| CURIO_DOCKER_IMAGE, | ||
| ]; | ||
|
|
||
| /// Docker container names (base - will be prefixed with foc-c-<RUN_ID>- in practice) | ||
| pub const LOTUS_CONTAINER: &str = "foc-c-lotus"; | ||
| pub const LOTUS_MINER_CONTAINER: &str = "foc-c-lotus-miner"; | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the README_ADVANCED.md also get updated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not necessary, this is an internal check/guardrail, that is optional. It is done for better UX.