Skip to content

Commit

Permalink
add x86_64-unknown-linux-musl for build
Browse files Browse the repository at this point in the history
  • Loading branch information
orelvis15 committed Jul 24, 2022
1 parent a4c9bc1 commit 497ee65
Show file tree
Hide file tree
Showing 15 changed files with 157 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
os: ubuntu-latest
artifact_name: target/release/cvm
asset_name: cvm-x86_64
target: x86_64-unknown-linux-gnu
target: x86_64-unknown-linux-musl
- name: rpi
os: ubuntu-latest
artifact_name: target/release/cvm
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## cvm v0.3.0
- add download cardano bins for hydra

## cvm v0.2.0
- add versionate remote config

Expand Down
2 changes: 1 addition & 1 deletion 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 Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cvm"
version = "0.2.1"
version = "0.3.0"
edition = "2021"
authors = ["Orelvis Lago Vasallo"]
description = "CLI for version control in cardano pools"
Expand Down
4 changes: 2 additions & 2 deletions config/config_remote.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ others_files = ["cardano-submit-api", "cardano-api", "cardano-api-test", "cardan
[download_install]
base_url = "https://hydra.iohk.io/build/"
end_url = "/download/1/cardano-node-{version}-linux.tar.gz"
versions = ["1.35.0"]
build_id = ["16994721"]
versions = ["1.35.0", "1.34.1", "1.34.0", "1.33.0", "1.32.1", "1.31.0"]
build_id = ["16994721", "13065769", "12997298", "9941151", "9116140", "8110920"]

#Services items

Expand Down
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

if [[ $(id -u) == 0 ]] ; then echo "Rlease don't run as root" ; exit 1 ; fi
if [[ $(id -u) == 0 ]] ; then echo "Please don't run as root" ; exit 1 ; fi

repo="https://api.github.com/repos/orelvis15/cvm/releases/latest"
env="https://raw.githubusercontent.com/orelvis15/cvm/master/env"
Expand Down
19 changes: 19 additions & 0 deletions src/subcommands/commands_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ pub fn command_config() -> ArgMatches {
.about("Start the environment to be able to build a Cardano node")
.arg(get_arg_network())
.arg(get_arg_force_init())
.arg(get_arg_build_init())
)
.subcommand(Command::new(CommandsConfig::INSTALL.to_string())
.about("Build the cardano node and make it available for use")
.arg(get_arg_version())
.arg(get_arg_build_install())
)
.subcommand(Command::new(CommandsConfig::USE.to_string())
.about("Change the current cardano-node to the new version")
Expand Down Expand Up @@ -58,6 +60,20 @@ fn get_arg_network() -> Arg<'static> {
Arg::new(Args::NETWORK._to_string()).default_value(Args::LATEST._to_string()).takes_value(true)
}

fn get_arg_build_install() -> Arg<'static> {
Arg::new(Args::BUILD._to_string())
.short('b')
.long(Args::BUILD._to_string())
.help("Build cardano-node locally")
}

fn get_arg_build_init() -> Arg<'static> {
Arg::new(Args::BUILD._to_string())
.short('b')
.long(Args::BUILD._to_string())
.help("Prepare server for build cardano-node")
}

fn get_arg_force_init() -> Arg<'static> {
Arg::new(Args::FORCE._to_string())
.short('f')
Expand Down Expand Up @@ -107,6 +123,7 @@ pub enum Args {
VERSION,
LATEST,
FORCE,
BUILD,
}

impl Args {
Expand All @@ -116,6 +133,7 @@ impl Args {
Args::VERSION => { "version" }
Args::LATEST => { "latest" }
Args::FORCE => { "force" }
Args::BUILD => { "build" }
}
}
}
Expand All @@ -127,6 +145,7 @@ impl Display for Args {
Args::VERSION => write!(f, "version"),
Args::LATEST => write!(f, "latest"),
Args::FORCE => write!(f, "force"),
Args::BUILD => write!(f, "build"),
}
}
}
31 changes: 20 additions & 11 deletions src/subcommands/subcommands_impl/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::subcommands::subcommand_strategy::CommandStrategy;
use crate::subcommands::commands_config::Args;
use crate::config::state_config::{reset_init, set_init_network, set_init_success};
use crate::message::message::Message;
use crate::task::task::Success;
use crate::task::task::{Success, Task};
use crate::task::task_impl::commons::permission_task::{PermissionAction, PermissionTask};
use crate::task::task_impl::init::create_folder_structure_task::CreateFolderStructure;
use crate::task::task_impl::init::download_config_files_task::DownloadConfigFilesTask;
Expand All @@ -21,34 +21,43 @@ use crate::utils::folders::Folder;
const MAINNET: &str = "mainnet";
const TESTNET: &str = "testnet";

pub struct Init{}
pub struct Init {}

impl CommandStrategy for Init {
fn start(command: &ArgMatches) -> Result<Success, Message> {

let config = config::remote_config::get_remote_config()?;
let mut term = Term { stdout: stdout() };

let mut network = MAINNET;

if let Some(value) = command.get_one::<String>(Args::NETWORK._to_string()){
if let Some(value) = command.get_one::<String>(Args::NETWORK._to_string()) {
if value == TESTNET {
network = TESTNET
}
}

if command.contains_id(Args::FORCE._to_string()){
if command.contains_id(Args::FORCE._to_string()) {
reset_init()?;
};

TaskManager::default().start(vec![
let mut tasks: Vec<Box<dyn Task>> = vec![
Box::new(PermissionTask { input_data: PermissionAction::CheckWrite(vec![Folder::get_workspaces_dir().to_string()]) }),
Box::new(InstallDependenciesTask::default()),
Box::new(InstallHanskellGhcTask::default()),
Box::new(CreateFolderStructure::default()),
Box::new(Installlibsecp256k1Task::default()),
Box::new(DownloadConfigFilesTask { network: network.to_string() }),
], &config, &mut term, L1)?;
];

if command.contains_id(Args::BUILD._to_string()) {
tasks.append(&mut vec![
Box::new(InstallHanskellGhcTask::default()),
Box::new(Installlibsecp256k1Task::default()),
]);
} else {
tasks.append(&mut vec![
Box::new(CreateFolderStructure::default()),
Box::new(DownloadConfigFilesTask { network: network.to_string() }),
]);
}

TaskManager::default().start(tasks, &config, &mut term, L1)?;

set_init_network(network.to_string())?;
set_init_success(true)
Expand Down
32 changes: 23 additions & 9 deletions src/subcommands/subcommands_impl/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ use crate::{Message, CommandStrategy, Term, MessageData, url_build, config};
use crate::config::state_config::get_state;
use crate::message::message::MessageKind;
use crate::task::task_impl::commons::folder_manager_task::{FolderManagerAction, FolderManagerTask};
use crate::task::task_impl::install::build_cardano_node_task::BuildCardanoNodeTask;
use crate::task::task_impl::install::copy_bin_task::{CopyBinInputData, CopyBinTask};
use crate::task::task_impl::install::build::build_cardano_node_task::BuildCardanoNodeTask;
use crate::task::task_impl::install::build::copy_bin_task::{CopyBinInputData, CopyBinTask};
use crate::task::task_impl::install::download::download_install_task::DownloadInstallTask;
use crate::task_manager::task_manager::TaskManager;
use crate::term::log_level::LogLevel::L1;
use crate::utils::folders::Folder;
Expand All @@ -20,7 +21,6 @@ pub struct Install {}

impl CommandStrategy for Install {
fn start(command: &ArgMatches) -> Result<Success, Message> {

let config = config::remote_config::get_remote_config()?;
let mut term = Term { stdout: stdout() };

Expand Down Expand Up @@ -60,11 +60,25 @@ impl CommandStrategy for Install {
let mut build_cardano_task = BuildCardanoNodeTask::default();
build_cardano_task.version = version.to_string();

TaskManager::default().start(vec![
Box::new(build_cardano_task),
Box::new(FolderManagerTask { input_data: FolderManagerAction::Create(vec![(bin_folder.clone(), version.clone())]) }),
Box::new(CopyBinTask { input_data: CopyBinInputData { files_names: config.binaries.required_files.clone(),
origin_path: cardano_folder.clone(), version: version.clone(), bin_folder: bin_folder.clone(), version_folder: version_folder.clone() } }),
], &config, &mut term, L1)
if command.contains_id(Args::BUILD._to_string()) {
TaskManager::default().start(vec![
Box::new(build_cardano_task),
Box::new(FolderManagerTask { input_data: FolderManagerAction::Create(vec![(bin_folder.clone(), version.clone())]) }),
Box::new(CopyBinTask {
input_data: CopyBinInputData {
files_names: config.binaries.required_files.clone(),
origin_path: cardano_folder.clone(),
version: version.clone(),
bin_folder: bin_folder.clone(),
version_folder: version_folder.clone(),
}
}),
], &config, &mut term, L1)
} else {
TaskManager::default().start(vec![
Box::new(FolderManagerTask { input_data: FolderManagerAction::Create(vec![(bin_folder.clone(), version.clone())]) }),
Box::new(DownloadInstallTask { version }),
], &config, &mut term, L1)
}
}
}
2 changes: 2 additions & 0 deletions src/task/task_impl/commons/run_command_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ pub enum Cmd {
Systemctl,
DaemonReload,
Update,
V2Update,
Clean,
Help,
Sudo,
Expand Down Expand Up @@ -214,6 +215,7 @@ impl Cmd {
Cmd::Clean => {"clean".to_string()}
Cmd::Help => {"help".to_string()}
Cmd::Sudo => {"sudo".to_string()}
Cmd::V2Update => {"v2-update".to_string()}
}
}
}
3 changes: 3 additions & 0 deletions src/task/task_impl/install/build/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod build_cardano_node_task;
pub mod copy_bin_task;
pub mod install_libsodium_task;
74 changes: 74 additions & 0 deletions src/task/task_impl/install/download/download_install_task.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#![allow(dead_code, unused_variables)]

extern crate strfmt;

use std::collections::HashMap;
use std::fs::File;
use flate2::read::GzDecoder;
use tar::Archive;
use crate::env::Env;
use crate::{Message, MessageData, Success, Term, url_build};
use crate::config::remote_config::{DownloadInstall, RemoteConfig};
use crate::message::message::MessageKind;
use crate::task::task::Task;
use crate::task::task_type::TaskType;
use crate::utils::download_manager::download_in_path;
use crate::utils::folders::Folder;
use strfmt::strfmt;

pub struct DownloadInstallTask {
pub version: String,
}

impl Task for DownloadInstallTask {
fn prepare(self: &mut Self, env: &mut Env, config: &RemoteConfig, term: &mut Term) -> Result<bool, Message> {
Ok(true)
}

fn run(self: &Self, env: &mut Env, config: &RemoteConfig, term: &mut Term) -> Result<Success, Message> {
let bin_name = "cnode.tar.gz";
let bin_folder = Folder::get_path(Folder::BIN, &config);
let version_folder = url_build(vec![&bin_folder, &self.version], false);

let url = build_download_url(&config.download_install, &self.version)?;
let file = download_in_path(&url, version_folder.clone(), bin_name.to_string())?;

decompress(&file, &version_folder)
}

fn check(self: &Self, env: &mut Env, config: &RemoteConfig, term: &mut Term) -> Result<Success, Message> {
Ok(Success {})
}

fn get_type(self: &Self) -> TaskType {
TaskType::DownloadInstall("".to_string())
}
}

fn decompress(file_uri: &String, folder: &String) -> Result<Success, Message> {
let file = File::open(file_uri)?;
let tar = GzDecoder::new(file);
let mut archive = Archive::new(tar);
archive.unpack(folder)?;
Ok(Success {})
}

fn build_download_url(data: &DownloadInstall, version: &String) -> Result<String, Message> {
let version_position = &data.versions.iter().position(|item| item == version);
if version_position.is_none() {
return Err(Message::VersionExist(MessageData {
message: "The version does not exist yet".to_string(),
kind: MessageKind::Info,
..Default::default()
}));
}

let mut vars = HashMap::new();
vars.insert("version".to_string(), version);

let end_url_with_version = strfmt(&data.end_url, &vars).unwrap();
let build_id = data.build_id.get(version_position.unwrap()).unwrap();

let url_result = format!("{}{}{}", &data.base_url, build_id, &end_url_with_version);
Ok(url_result)
}
1 change: 1 addition & 0 deletions src/task/task_impl/install/download/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod download_install_task;
5 changes: 2 additions & 3 deletions src/task/task_impl/install/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
pub mod build_cardano_node_task;
pub mod copy_bin_task;
pub mod install_libsodium_task;
pub mod build;
pub mod download;
5 changes: 4 additions & 1 deletion src/task/task_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::fmt;
use std::fmt::Formatter;
use crate::task::task_impl::commons::run_command_task::RunCommandInputData;
use crate::task::task_impl::install::copy_bin_task::CopyBinInputData;
use crate::task::task_impl::install::build::copy_bin_task::CopyBinInputData;
use crate::task::task_impl::r#use::use_version_task::UserVersionData;
use crate::task::task_impl::update::check_update_task::CheckUpdateData;

Expand All @@ -27,6 +27,7 @@ pub enum TaskType {
FolderManager(String),
FileManager(String),
Permission(String),
DownloadInstall(String),
}

impl Default for TaskType {
Expand Down Expand Up @@ -56,6 +57,7 @@ impl TaskType {
TaskType::FileManager(text) => { text.to_string() }
TaskType::UpdateConfigFiles => {"Updating configuration files".to_string() }
TaskType::Libsecp256k1 => {"Installing libsecp256k1".to_string()}
TaskType::DownloadInstall(version) => {format!("Downloading version {}", version)}
}
}
}
Expand Down Expand Up @@ -91,6 +93,7 @@ impl fmt::Display for TaskType {
TaskType::FileManager(_) => write!(f, "Task: File_Manager"),
TaskType::UpdateConfigFiles => write!(f, "Task: Update_Config_File"),
TaskType::Libsecp256k1 => write!(f, "Task: Libsecp256k1"),
TaskType::DownloadInstall(_) => write!(f, "Task: Donwload installer"),
}
}
}

0 comments on commit 497ee65

Please sign in to comment.