Skip to content

Conversation

David-Petrov
Copy link
Contributor

@David-Petrov David-Petrov commented Jun 26, 2024

Adds the ability to also launch a module by creating and starting a container from a docker image provided for that module.

The config.example.toml is modified to launch an example replica of da_commit which has been dockerized. From the viewpoint of CB, it simply expects a docker image da_commit in the local registry. However, the dockerized version of the example module da_commit is not defined in this repo, but is available here, to more clearly showcase the boundaries between the two different perspectives: CB operator vs. module author.

Nothing has been changed in the business logic of da_commit, only the Cargo.toml has been modified to decouple dependencies for commit-boost's workspace and a Dockerfile has been added.

Before you launch CB, you need to:

  • build the da_commit image locally.
  • have the docker engine running.

IMPORTANT: While this feature of CB is in development, you might have to modify Cargo.toml of the example module to point to the accurate current version of CB before you build the image. At the time of writing, the referred branch is a working version, but things might become incompatible when commits are actively added to the branch.

NOTE: #3 (comment)

pub extra: T,
}

impl<'de, T> Deserialize<'de> for ModuleConfig<T>
Copy link
Contributor Author

@David-Petrov David-Petrov Jun 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This custom deserializer is the quick approach I took to scratch my itch for modelling a strict config structure: exactly one of path or docker_image must be specified in the config.example.toml for a given module - marking the module as either launchable from a raw binary (like it used to be) OR from a docker image (the new addition).

We could choose another approach for modelling the config (i.e. an additional tag specifying the variant, and then the necessary source data (path or docker image id); or similar...)

let full_config_path = std::fs::canonicalize(&config_path).unwrap().to_string_lossy().to_string();
Some(vec![format!("{}:{}", full_config_path, "/config.toml")])
},
network_mode: Some(String::from("host")), // Use the host network
Copy link
Contributor Author

@David-Petrov David-Petrov Jun 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's worth noting here that I'm making substantial use of the host network mode in order to share the networking namespace of the host with the module itself.
This is sacrificing sandboxing for easier configuration.

NOTE: This is a beta feature for Docker desktop (if you're using that), and must be enabled explicitly:

The host networking driver only works on Linux hosts, but is available as a Beta feature, on Docker Desktop version 4.29 and later.

Might not be the best long-term decision, but for simplicity's sake it's closer to native; just like the alternative (previous) approach of launching modules as subprocesses.


[[modules]]
id = "DA_COMMIT"
docker_image="da_commit"
Copy link
Contributor Author

@David-Petrov David-Petrov Jun 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the example image that must be available in the local registry before starting commit-boost.
You can find the example source code in this repo.

NOTE: Whilst we're still in development, you will have to modify the Cargo.toml of the example module to point to a correct source for the cb-... dependencies.

let config = CommitBoostConfig::from_file(&config_path);

// Initialize Docker client
let docker = bollard::Docker::connect_with_local_defaults().expect("Failed to connect to Docker");
Copy link
Contributor Author

@David-Petrov David-Petrov Jun 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, we currently expect that CB and the docker engine run on the same machine.

However, the way we connect to the docker daemon is modifiable if more complex needs arise: ref.

@ltitanb
Copy link
Collaborator

ltitanb commented Jun 26, 2024

Looks good ! Now that we have docker images I would if we should keep the two different sources (Docker and binary)? Would rather remove the binary one and add it back once we're ready to support it again.

@David-Petrov
Copy link
Contributor Author

David-Petrov commented Jun 26, 2024

There are currently no new issues introduced with the support of binary sourced modules. In fact, the current config.example.toml showcases simultaneous inclusion of one copy of da_commit, sourced as a binary, and one copy of da_commit sourced from a docker image. That is, if I'm not missing something from your stance?

You might be right, though, that we might run into difficulties at some point... so I guess we can then remove the binary option.

Does that change perspectives or do we stick to removing binary sources right away?

@ltitanb
Copy link
Collaborator

ltitanb commented Jun 26, 2024

Yep I would remove it for now, would rather keep the codebase simple and lean and add it back once we can support it smoothly

@ltitanb ltitanb merged commit d117483 into Commit-Boost:main Jun 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants