Skip to content

Commit

Permalink
chore: update containers (#242)
Browse files Browse the repository at this point in the history
* chore: update containers to minotari

As part of updating launchpad to use stage- and main-net, we need to
update the containers used, as well as bring configuratino up-to-date.

This PR is primarily focussed on updating the containers:
- use Github package repos instead of quay.io
- use stagenet instead of esme as default
- use ver 0.52 (this must change to stagenet-latest soon, but tags
  aren't up yet)

docs:

- Parsing the code, adding some helpful docs as I go.

behaviour changes:

- Config files are not deleted on startup. This is important. Users
should be able to tweak settings between launches and have them persist.

* chore: update node version

CI fails with node v16, since it's really old and presumably not
supported anymore.

Also updating the GHA since there's still a permissions error.
  • Loading branch information
CjS77 authored Nov 16, 2023
1 parent ba59da4 commit 5b150fc
Show file tree
Hide file tree
Showing 23 changed files with 123 additions and 82 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ jobs:
uses: actions/checkout@v3

- name: Node.js setup
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 16
node-version: "20"
cache: 'yarn'

- name: Rust setup (native)
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/reusable-ci-jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@
- name: Cache rust dependencies
uses: Swatinem/rust-cache@v1
- name: setup node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: "16"
node-version: "20"
- name: ubuntu dependencies
if: ${{ inputs.build-tari }}
run: |
Expand Down Expand Up @@ -152,9 +152,9 @@
- name: checkout
uses: actions/checkout@v2
- name: setup node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: "16"
node-version: "20"
- name: Install Yarn
run: npm install -g yarn
- name: log javascript environment
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/reusable-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ jobs:
- name: toolchain
uses: actions-rs/toolchain@v1
- name: setup node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: "16"
node-version: "20"
- uses: Swatinem/rust-cache@v1
- name: ubuntu dependencies
run: |
Expand Down
20 changes: 10 additions & 10 deletions backend/src/docker/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,36 +142,36 @@ impl From<LogOutput> for LogMessage {
/// Supported networks for the launchpad
#[derive(Serialize, Debug, Deserialize, Clone, Copy)]
pub enum TariNetwork {
Dibbler,
Esmeralda,
Igor,
Nextnet,
Stagenet,
Mainnet,
}

impl TariNetwork {
pub fn lower_case(self) -> &'static str {
match self {
Self::Dibbler => "dibbler",
Self::Esmeralda => "esmeralda",
Self::Igor => "igor",
Self::Nextnet => "nextnet",
Self::Stagenet => "stagenet",
Self::Mainnet => "mainnet",
}
}

pub fn upper_case(self) -> &'static str {
match self {
Self::Dibbler => "DIBBLER",
Self::Esmeralda => "ESMERALDA",
Self::Igor => "IGOR",
Self::Nextnet => "NEXTNET",
Self::Stagenet => "STAGENET",
Self::Mainnet => "MAINNET",
}
}
}

/// Default network is Esme. This will change after mainnet launch
/// Default network is Stagenet. This will change after mainnet launch
impl Default for TariNetwork {
fn default() -> Self {
Self::Esmeralda
Self::Stagenet
}
}

Expand All @@ -180,9 +180,9 @@ impl TryFrom<&str> for TariNetwork {

fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"dibbler" => Ok(TariNetwork::Dibbler),
"esmeralda" => Ok(TariNetwork::Esmeralda),
"igor" => Ok(TariNetwork::Igor),
"nextnet" => Ok(TariNetwork::Nextnet),
"stagenet" => Ok(TariNetwork::Stagenet),
"mainnet" => Ok(TariNetwork::Mainnet),
_ => Err(DockerWrapperError::UnsupportedNetwork),
}
Expand Down
3 changes: 1 addition & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ use tari_sdm_assets::configurator::Configurator;
#[tokio::main]
async fn main() -> Result<(), Error> {
let mut configurator = Configurator::init()?;
configurator.clean_configuration().await?;
configurator.init_configuration().await?;
configurator.init_configuration(false).await?;

let workdir = configurator.base_path();
env::set_current_dir(workdir)?;
Expand Down
7 changes: 6 additions & 1 deletion libs/protocol/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pub enum TaskStatus {
Pending,
Progress(TaskProgress),
Active,
// TODO: Add failed with a reason?
Failed(String),
}

impl TaskStatus {
Expand All @@ -145,6 +145,10 @@ impl TaskStatus {
pub fn is_inactive(&self) -> bool {
matches!(self, Self::Inactive)
}

pub fn is_failed(&self) -> bool {
matches!(self, Self::Failed(_))
}
}

impl fmt::Display for TaskStatus {
Expand All @@ -154,6 +158,7 @@ impl fmt::Display for TaskStatus {
Self::Pending => write!(f, "Pending"),
Self::Progress(value) => write!(f, "Progress({} - {}%)", value.stage, value.pct),
Self::Active => write!(f, "Active"),
Self::Failed(reason) => write!(f, "Failed. Reason: {}", reason),
}
}
}
Expand Down
14 changes: 5 additions & 9 deletions libs/protocol/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl MmProxyConfig {
pub struct LaunchpadSettings {
/// The directory to use for config, id files and logs
pub data_directory: PathBuf,
/// The Tari network to use. Default = esmeralda
/// The Tari network to use. Default = stagenet
pub tari_network: TariNetwork,
/// The tor control password to share among containers.
pub tor_control_password: String,
Expand Down Expand Up @@ -155,29 +155,26 @@ pub struct UnsupportedNetwork(String);
/// Supported networks for the launchpad
#[derive(Serialize, Debug, Deserialize, Clone, Copy)]
pub enum TariNetwork {
Dibbler,
Esmeralda,
Igor,
Nextnet,
Stagenet,
Mainnet,
}

impl TariNetwork {
pub fn lower_case(self) -> &'static str {
match self {
Self::Dibbler => "dibbler",
Self::Esmeralda => "esmeralda",
Self::Igor => "igor",
Self::Nextnet => "nextnet",
Self::Stagenet => "stagenet",
Self::Mainnet => "mainnet",
}
}

pub fn upper_case(self) -> &'static str {
match self {
Self::Dibbler => "DIBBLER",
Self::Esmeralda => "ESMERALDA",
Self::Igor => "IGOR",
Self::Nextnet => "NEXTNET",
Self::Stagenet => "STAGENET",
Self::Mainnet => "MAINNET",
}
Expand All @@ -196,9 +193,8 @@ impl TryFrom<&str> for TariNetwork {

fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"dibbler" => Ok(TariNetwork::Dibbler),
"esmeralda" => Ok(TariNetwork::Esmeralda),
"igor" => Ok(TariNetwork::Igor),
"nextnet" => Ok(TariNetwork::Nextnet),
"mainnet" => Ok(TariNetwork::Mainnet),
other => Err(UnsupportedNetwork(other.to_owned())),
}
Expand Down
67 changes: 36 additions & 31 deletions libs/sdm-assets/src/configurator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,53 +78,58 @@ impl Configurator {
// Ok(config)
// }

async fn create_dir(&mut self, folder: &Path) -> Result<(), Error> {
if !folder.exists() {
fs::create_dir_all(&folder).await?;
/// Create directory if it doesn't exist. Returns `true` if the directory was created.
async fn create_dir<P: AsRef<Path>>(&mut self, folder: P) -> Result<bool, Error> {
if folder.as_ref().exists() {
Ok(false)
} else {
fs::create_dir_all(folder).await?;
Ok(true)
}
Ok(())
}

async fn create_sub_dir(&mut self, folder: &Path, sub_path: &str) -> Result<PathBuf, Error> {
async fn create_sub_dir(&mut self, folder: &Path, sub_path: &str) -> Result<bool, Error> {
let mut path = folder.to_path_buf();
path.push(sub_path);
if !path.exists() {
fs::create_dir_all(&path).await?;
}
Ok(path)
self.create_dir(sub_path).await
}

async fn store_file(&mut self, folder: &Path, file: &ConfigFile) -> Result<(), Error> {
let mut path = folder.to_path_buf();
async fn store_file<P: AsRef<Path>>(&mut self, folder: P, file: &ConfigFile, overwrite: bool) -> Result<(), Error> {
let mut path = folder.as_ref().to_path_buf();
path.push(file.filename);
if !path.exists() {
if overwrite || !path.exists() {
fs::write(path, file.data).await?;
}
Ok(())
}

pub async fn clean_configuration(&mut self) -> Result<(), Error> {
let base_dir = self.base_dir.clone();
let config_dir = self.create_sub_dir(&base_dir, "config").await?;
tokio::fs::remove_dir_all(config_dir).await?;
Ok(())
}

pub async fn init_configuration(&mut self) -> Result<(), Error> {
/// Initialize configuration files
///
/// If `overwrite` is `true`, then existing files will be overwritten.
pub async fn init_configuration(&mut self, overwrite: bool) -> Result<(), Error> {
// base path
let base_dir = self.base_dir.clone();
self.create_dir(&base_dir).await?;
let config_dir = self.create_sub_dir(&base_dir, "config").await?;
let _ = self.create_dir(&base_dir).await?;
let mut config_dir = base_dir.clone();
config_dir.push("config");
let new_config_dir = self.create_dir(&config_dir).await?;
// config files
self.store_file(&config_dir, &CONFIG_TOML).await?;
self.store_file(&config_dir, &DEFAULTS_INI).await?;
self.store_file(&config_dir, &LOGS4RS_YML).await?;
self.store_file(&config_dir, &LOKI_YML).await?;
self.store_file(&config_dir, &PROMTAIL_YML).await?;
self.store_file(&config_dir, &PROVISION_YML).await?;

self.create_sub_dir(&base_dir, "log").await?;
self.store_file(&config_dir, &LOG4RS_CLI_YML).await?;
self.store_file(&config_dir, &CONFIG_TOML, new_config_dir || overwrite)
.await?;
self.store_file(&config_dir, &DEFAULTS_INI, new_config_dir || overwrite)
.await?;
self.store_file(&config_dir, &LOGS4RS_YML, new_config_dir || overwrite)
.await?;
self.store_file(&config_dir, &LOKI_YML, new_config_dir || overwrite)
.await?;
self.store_file(&config_dir, &PROMTAIL_YML, new_config_dir || overwrite)
.await?;
self.store_file(&config_dir, &PROVISION_YML, new_config_dir || overwrite)
.await?;

let new_log_dir = self.create_sub_dir(&base_dir, "log").await?;
self.store_file(&config_dir, &LOG4RS_CLI_YML, new_log_dir || overwrite)
.await?;

// TODO: Use `enum` here...
// images
Expand Down
4 changes: 2 additions & 2 deletions libs/sdm-launchpad/src/bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl LaunchpadWorker {
in_rx: mpsc::UnboundedReceiver<Action>,
out_tx: mpsc::UnboundedSender<Reaction>,
) -> Result<(), Error> {
let mut scope = SdmScope::connect("esmeralda")?;
let mut scope = SdmScope::connect("stagenet")?;
scope.add_network(networks::LocalNet::default())?;
scope.add_volume(volumes::SharedVolume::default())?;
scope.add_volume(volumes::SharedGrafanaVolume::default())?;
Expand Down Expand Up @@ -125,7 +125,7 @@ impl LaunchpadWorker {
async fn load_configuration(&mut self) -> Result<(), Error> {
let mut configurator = Configurator::init()?;
let data_directory = configurator.base_path().clone();
configurator.init_configuration().await?;
configurator.init_configuration(false).await?;
let wallet_config = WalletConfig {
password: "123".to_string(),
};
Expand Down
9 changes: 7 additions & 2 deletions libs/sdm-launchpad/src/resources/images/l2_base_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ impl ManagedContainer for TariBaseNode {
}

fn image_name(&self) -> &str {
"tari_base_node"
"minotari_node"
}

fn tag(&self) -> &str {
"v0.49.2_20230628_e0e4ebc"
"0.52"
}

fn reconfigure(&mut self, config: Option<&LaunchpadConfig>) -> Option<bool> {
Expand Down Expand Up @@ -136,6 +136,7 @@ impl ManagedContainer for TariBaseNode {
}
}

/// A helper struct to track the progress of the initial block download.
struct Checker {
progress: SyncProgress,
identity_sent: bool,
Expand All @@ -155,6 +156,10 @@ impl Checker {

#[async_trait]
impl ContainerChecker<LaunchpadProtocol> for Checker {
/// The interval hook in the base node checker is used to query the base node via gRPC for the current sync
/// progress. The progress is then reported to the SDM via the `CheckerEvent::Progress` event.
/// The task is reported as complete (`READY`) once the `sync_state` value from the `get_sync_progress` RPC call
/// is `Done`.
async fn on_interval(&mut self, ctx: &mut CheckerContext<LaunchpadProtocol>) -> Result<(), Error> {
if self.ready {
return Ok(());
Expand Down
4 changes: 2 additions & 2 deletions libs/sdm-launchpad/src/resources/images/l2_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ impl ManagedContainer for TariWallet {
}

fn image_name(&self) -> &str {
"tari_wallet"
"minotari_console_wallet"
}

fn tag(&self) -> &str {
"v0.49.2_20230628_e0e4ebc"
"0.52"
}

fn reconfigure(&mut self, config: Option<&LaunchpadConfig>) -> Option<bool> {
Expand Down
4 changes: 2 additions & 2 deletions libs/sdm-launchpad/src/resources/images/l3_miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ impl ManagedContainer for TariSha3Miner {
}

fn image_name(&self) -> &str {
"tari_sha3_miner"
"minotari_sha3_miner"
}

fn tag(&self) -> &str {
"v0.49.2_20230628_e0e4ebc"
"0.52"
}

fn reconfigure(&mut self, config: Option<&LaunchpadConfig>) -> Option<bool> {
Expand Down
4 changes: 2 additions & 2 deletions libs/sdm-launchpad/src/resources/images/l5_mmproxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ impl ManagedContainer for MmProxy {
}

fn image_name(&self) -> &str {
"tari_mm_proxy"
"minotari_merge_mining_proxy"
}

fn tag(&self) -> &str {
"v0.49.2_20230628_e0e4ebc"
"0.52"
}

fn reconfigure(&mut self, config: Option<&LaunchpadConfig>) -> Option<bool> {
Expand Down
2 changes: 1 addition & 1 deletion libs/sdm-launchpad/src/resources/images/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub use l8_grafana::Grafana;
pub use l8_loki::Loki;
pub use l8_promtail::Promtail;

static DEFAULT_REGISTRY: &str = "quay.io/tarilabs";
static DEFAULT_REGISTRY: &str = "ghcr.io/tari-project";
static GRAFANA_REGISTRY: &str = "grafana";

static GENERAL_VOLUME: &str = "/var/tari";
Expand Down
5 changes: 5 additions & 0 deletions libs/sdm/src/image/checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ impl<P: ManagedProtocol> CheckerContext<P> {
}
}

/// Polls a container for the logs and stats, and executes the related hooks for the event. If no events are
/// received for 1 second, the `on_interval` hook is called. The default implementation of all of the hooks do nothing.
///
/// In each of the hooks, a mutable reference to a `CheckerContext` is provided, which can be used to access / update
/// the log and stats history, and update the progress of a task.
#[async_trait]
pub trait ContainerChecker<P: ManagedProtocol>: Send {
async fn entrypoint(mut self: Box<Self>, mut ctx: CheckerContext<P>) {
Expand Down
Loading

0 comments on commit 5b150fc

Please sign in to comment.