Channel installs no longer re-download the same release.
This commit is contained in:
parent
7614af2a45
commit
33ea1e0edd
|
@ -6,6 +6,7 @@ use crate::{
|
||||||
use chrono::{Local, TimeZone};
|
use chrono::{Local, TimeZone};
|
||||||
use console::{style, Emoji};
|
use console::{style, Emoji};
|
||||||
use indicatif::{ProgressBar, ProgressStyle};
|
use indicatif::{ProgressBar, ProgressStyle};
|
||||||
|
use serde_derive::Deserialize;
|
||||||
use solana_client::rpc_client::RpcClient;
|
use solana_client::rpc_client::RpcClient;
|
||||||
use solana_config_program::{config_instruction, get_config_data, ConfigState};
|
use solana_config_program::{config_instruction, get_config_data, ConfigState};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
|
@ -25,6 +26,13 @@ use std::{
|
||||||
use tempdir::TempDir;
|
use tempdir::TempDir;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
#[derive(Deserialize, Debug)]
|
||||||
|
pub struct ReleaseVersion {
|
||||||
|
pub target: String,
|
||||||
|
pub commit: String,
|
||||||
|
channel: String,
|
||||||
|
}
|
||||||
|
|
||||||
static TRUCK: Emoji = Emoji("🚚 ", "");
|
static TRUCK: Emoji = Emoji("🚚 ", "");
|
||||||
static LOOKING_GLASS: Emoji = Emoji("🔍 ", "");
|
static LOOKING_GLASS: Emoji = Emoji("🔍 ", "");
|
||||||
static BULLET: Emoji = Emoji("• ", "* ");
|
static BULLET: Emoji = Emoji("• ", "* ");
|
||||||
|
@ -46,15 +54,15 @@ fn println_name_value(name: &str, value: &str) {
|
||||||
println!("{} {}", style(name).bold(), value);
|
println!("{} {}", style(name).bold(), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Downloads the release archive at `url` to a temporary location. If `expected_sha256` is
|
/// Downloads a file at `url` to a temporary location. If `expected_sha256` is
|
||||||
/// Some(_), produce an error if the release SHA256 doesn't match.
|
/// Some(_), produce an error if the SHA256 of the file contents doesn't match.
|
||||||
///
|
///
|
||||||
/// Returns a tuple consisting of:
|
/// Returns a tuple consisting of:
|
||||||
/// * TempDir - drop this value to clean up the temporary location
|
/// * TempDir - drop this value to clean up the temporary location
|
||||||
/// * PathBuf - path to the downloaded release (within `TempDir`)
|
/// * PathBuf - path to the downloaded file (within `TempDir`)
|
||||||
/// * String - SHA256 of the release
|
/// * String - SHA256 of the release
|
||||||
///
|
///
|
||||||
fn download_to_temp_archive(
|
fn download_to_temp(
|
||||||
url: &str,
|
url: &str,
|
||||||
expected_sha256: Option<&Hash>,
|
expected_sha256: Option<&Hash>,
|
||||||
) -> Result<(TempDir, PathBuf, Hash), Box<dyn std::error::Error>> {
|
) -> Result<(TempDir, PathBuf, Hash), Box<dyn std::error::Error>> {
|
||||||
|
@ -77,7 +85,7 @@ fn download_to_temp_archive(
|
||||||
let url = Url::parse(url).map_err(|err| format!("Unable to parse {}: {}", url, err))?;
|
let url = Url::parse(url).map_err(|err| format!("Unable to parse {}: {}", url, err))?;
|
||||||
|
|
||||||
let temp_dir = TempDir::new(clap::crate_name!())?;
|
let temp_dir = TempDir::new(clap::crate_name!())?;
|
||||||
let temp_file = temp_dir.path().join("release.tar.bz2");
|
let temp_file = temp_dir.path().join("download");
|
||||||
|
|
||||||
let client = reqwest::blocking::Client::new();
|
let client = reqwest::blocking::Client::new();
|
||||||
|
|
||||||
|
@ -162,22 +170,21 @@ fn extract_release_archive(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reads the supported TARGET triple for the given release
|
fn load_release_version(version_yml: &Path) -> Result<ReleaseVersion, String> {
|
||||||
fn load_release_target(release_dir: &Path) -> Result<String, Box<dyn std::error::Error>> {
|
let file = File::open(&version_yml)
|
||||||
use serde_derive::Deserialize;
|
.map_err(|err| format!("Unable to open {:?}: {:?}", version_yml, err))?;
|
||||||
#[derive(Deserialize, Debug)]
|
let version: ReleaseVersion = serde_yaml::from_reader(file)
|
||||||
pub struct ReleaseVersion {
|
.map_err(|err| format!("Unable to parse {:?}: {:?}", version_yml, err))?;
|
||||||
pub target: String,
|
Ok(version)
|
||||||
pub commit: String,
|
|
||||||
channel: String,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Reads the supported TARGET triple for the given release
|
||||||
|
fn load_release_target(release_dir: &Path) -> Result<String, String> {
|
||||||
let mut version_yml = PathBuf::from(release_dir);
|
let mut version_yml = PathBuf::from(release_dir);
|
||||||
version_yml.push("solana-release");
|
version_yml.push("solana-release");
|
||||||
version_yml.push("version.yml");
|
version_yml.push("version.yml");
|
||||||
|
|
||||||
let file = File::open(&version_yml)?;
|
let version = load_release_version(&version_yml)?;
|
||||||
let version: ReleaseVersion = serde_yaml::from_reader(file)?;
|
|
||||||
Ok(version.target)
|
Ok(version.target)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -554,6 +561,14 @@ fn release_channel_download_url(release_channel: &str) -> String {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn release_channel_version_url(release_channel: &str) -> String {
|
||||||
|
format!(
|
||||||
|
"http://release.solana.com/{}/solana-release-{}.yml",
|
||||||
|
release_channel,
|
||||||
|
crate::build_env::TARGET
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn info(config_file: &str, local_info_only: bool) -> Result<Option<UpdateManifest>, String> {
|
pub fn info(config_file: &str, local_info_only: bool) -> Result<Option<UpdateManifest>, String> {
|
||||||
let config = Config::load(config_file)?;
|
let config = Config::load(config_file)?;
|
||||||
|
|
||||||
|
@ -663,8 +678,7 @@ pub fn deploy(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Download the release
|
// Download the release
|
||||||
let (temp_dir, temp_archive, temp_archive_sha256) =
|
let (temp_dir, temp_archive, temp_archive_sha256) = download_to_temp(download_url, None)
|
||||||
download_to_temp_archive(download_url, None)
|
|
||||||
.map_err(|err| format!("Unable to download {}: {}", download_url, err))?;
|
.map_err(|err| format!("Unable to download {}: {}", download_url, err))?;
|
||||||
|
|
||||||
if let Ok(update_manifest) = get_update_manifest(&rpc_client, &update_manifest_keypair.pubkey())
|
if let Ok(update_manifest) = get_update_manifest(&rpc_client, &update_manifest_keypair.pubkey())
|
||||||
|
@ -750,6 +764,7 @@ pub fn update(config_file: &str) -> Result<bool, String> {
|
||||||
let download = if release_dir.join(".ok").exists() {
|
let download = if release_dir.join(".ok").exists() {
|
||||||
// If this release_semver has already been successfully downloaded, no update
|
// If this release_semver has already been successfully downloaded, no update
|
||||||
// needed
|
// needed
|
||||||
|
println!("{} is present, no download required.", release_semver);
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(download_url)
|
Some(download_url)
|
||||||
|
@ -757,17 +772,35 @@ pub fn update(config_file: &str) -> Result<bool, String> {
|
||||||
(download, release_dir)
|
(download, release_dir)
|
||||||
}
|
}
|
||||||
ExplicitRelease::Channel(release_channel) => {
|
ExplicitRelease::Channel(release_channel) => {
|
||||||
let download_url = release_channel_download_url(release_channel);
|
let version_url = release_channel_version_url(release_channel);
|
||||||
|
|
||||||
|
let (_temp_dir, temp_file, _temp_archive_sha256) =
|
||||||
|
download_to_temp(&version_url, None)
|
||||||
|
.map_err(|err| format!("Unable to download {}: {}", version_url, err))?;
|
||||||
|
|
||||||
|
let update_release_version = load_release_version(&temp_file)?;
|
||||||
|
|
||||||
let release_dir = config.release_dir(&release_channel);
|
let release_dir = config.release_dir(&release_channel);
|
||||||
// Note: There's currently no mechanism to check for an updated binary for a release
|
let current_release_version =
|
||||||
// channel so a download always occurs.
|
load_release_version(&release_dir.join("solana-release").join("version.yml"))?;
|
||||||
(Some(download_url), release_dir)
|
|
||||||
|
let download = if update_release_version.commit == current_release_version.commit {
|
||||||
|
// Same commit, no update required
|
||||||
|
println!(
|
||||||
|
"Latest {} build is already present, no download required.",
|
||||||
|
release_channel
|
||||||
|
);
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(release_channel_download_url(release_channel))
|
||||||
|
};
|
||||||
|
(download, release_dir)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(download_url) = download {
|
if let Some(download_url) = download {
|
||||||
let (_temp_dir, temp_archive, _temp_archive_sha256) =
|
let (_temp_dir, temp_archive, _temp_archive_sha256) =
|
||||||
download_to_temp_archive(&download_url, None)
|
download_to_temp(&download_url, None)
|
||||||
.map_err(|err| format!("Unable to download {}: {}", download_url, err))?;
|
.map_err(|err| format!("Unable to download {}: {}", download_url, err))?;
|
||||||
extract_release_archive(&temp_archive, &release_dir).map_err(|err| {
|
extract_release_archive(&temp_archive, &release_dir).map_err(|err| {
|
||||||
format!(
|
format!(
|
||||||
|
@ -797,7 +830,7 @@ pub fn update(config_file: &str) -> Result<bool, String> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let release_dir = config.release_dir(&update_manifest.download_sha256.to_string());
|
let release_dir = config.release_dir(&update_manifest.download_sha256.to_string());
|
||||||
let (_temp_dir, temp_archive, _temp_archive_sha256) = download_to_temp_archive(
|
let (_temp_dir, temp_archive, _temp_archive_sha256) = download_to_temp(
|
||||||
&update_manifest.download_url,
|
&update_manifest.download_url,
|
||||||
Some(&update_manifest.download_sha256),
|
Some(&update_manifest.download_sha256),
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue