Skip to content

Commit

Permalink
Merge pull request #128 from itowlson/buildinfo-exterminate-no-buildi…
Browse files Browse the repository at this point in the history
…nfo-exterminate-exterminate-exterminate

Remove deploy --buildinfo and --no-buildinfo flags
  • Loading branch information
itowlson authored Oct 12, 2023
2 parents 04f3028 + b436873 commit 1e10bb6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 70 deletions.
72 changes: 8 additions & 64 deletions src/commands/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ use cloud_openapi::models::{
ResourceLabel,
};
use oci_distribution::{token_cache, Reference, RegistryOperation};
use rand::Rng;
use semver::BuildMetadata;
use spin_common::{arg_parser::parse_kv, sloth};
use spin_http::{app_info::AppInfo, routes::RoutePattern};
use spin_manifest::ApplicationTrigger;
Expand All @@ -38,7 +36,6 @@ use crate::{
use crate::{
commands::login::{LoginCommand, LoginConnection},
opts::*,
parse_buildinfo,
};

use super::sqlite::database_has_link;
Expand Down Expand Up @@ -82,22 +79,6 @@ pub struct DeployCommand {
)]
pub registry_source: Option<String>,

/// Disable attaching buildinfo
#[clap(
long = "no-buildinfo",
conflicts_with = BUILDINFO_OPT,
env = "SPIN_DEPLOY_NO_BUILDINFO"
)]
pub no_buildinfo: bool,

/// Build metadata to append to the oci tag
#[clap(
name = BUILDINFO_OPT,
long = "buildinfo",
parse(try_from_str = parse_buildinfo),
)]
pub buildinfo: Option<BuildMetadata>,

/// For local apps, specifies to perform `spin build` before deploying the application.
///
/// This is ignored on remote applications, as they are already built.
Expand Down Expand Up @@ -193,15 +174,6 @@ impl DeployCommand {

let client = CloudClient::new(connection_config.clone());

let buildinfo = if !self.no_buildinfo {
match &self.buildinfo {
Some(i) => Some(i.clone()),
None => Some(random_buildinfo()),
}
} else {
None
};

let dir = tempfile::tempdir()?;

let application = self.load_cloud_app(dir.path()).await?;
Expand All @@ -214,22 +186,12 @@ impl DeployCommand {
std::env::set_var("SPIN_OCI_SKIP_INLINED_FILES", "true");

let digest = self
.push_oci(
application.clone(),
buildinfo.clone(),
connection_config.clone(),
)
.push_oci(application.clone(), connection_config.clone())
.await?;

let name = sanitize_app_name(application.name()?);
let storage_id = format!("oci://{}", name);
let version = sanitize_app_version(
&(format!(
"{}-{}",
application.version()?,
buildinfo.clone().context("Cannot parse build info")?
)),
);
let version = sanitize_app_version(application.version()?);

println!("Deploying...");

Expand Down Expand Up @@ -545,7 +507,6 @@ impl DeployCommand {
async fn push_oci(
&self,
application: DeployableApp,
buildinfo: Option<BuildMetadata>,
connection_config: ConnectionConfig,
) -> Result<Option<String>> {
let mut client = spin_oci::Client::new(connection_config.insecure, None).await?;
Expand All @@ -557,23 +518,12 @@ impl DeployCommand {
.context("Unable to derive host from cloud URL")?;
let cloud_registry_host = format!("registry.{cloud_host}");

let reference = match buildinfo {
Some(buildinfo) => {
format!(
"{}/{}:{}",
cloud_registry_host,
&sanitize_app_name(application.name()?),
&sanitize_app_version(&(application.version()?.to_owned() + "-" + &buildinfo),)
)
}
None => {
format!(
"{}/{}",
cloud_registry_host,
&sanitize_app_name(application.name()?)
)
}
};
let reference = format!(
"{}/{}:{}",
cloud_registry_host,
&sanitize_app_name(application.name()?),
&sanitize_app_version(application.version()?)
);

let oci_ref = Reference::try_from(reference.as_ref())
.context(format!("Could not parse reference '{reference}'"))?;
Expand Down Expand Up @@ -1021,12 +971,6 @@ impl DeployableComponent {
}
}

fn random_buildinfo() -> BuildMetadata {
let random_bytes: [u8; 4] = rand::thread_rng().gen();
let random_hex: String = random_bytes.iter().map(|b| format!("{:x}", b)).collect();
BuildMetadata::new(&format!("r{random_hex}")).unwrap()
}

fn build_app_base_url(app_domain: &str, cloud_url: &Url) -> Result<Url> {
// HACK: We assume that the scheme (https vs http) of apps will match that of Cloud...
let scheme = cloud_url.scheme();
Expand Down
5 changes: 0 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use commands::{
sqlite::SqliteCommand,
variables::VariablesCommand,
};
use semver::BuildMetadata;

/// Returns build information, similar to: 0.1.0 (2be4034 2022-03-31).
const VERSION: &str = concat!(
Expand Down Expand Up @@ -68,7 +67,3 @@ async fn main() -> Result<(), Error> {
CloudCli::Unlink(cmd) => cmd.run().await,
}
}

pub(crate) fn parse_buildinfo(buildinfo: &str) -> Result<BuildMetadata> {
Ok(BuildMetadata::new(buildinfo)?)
}
1 change: 0 additions & 1 deletion src/opts.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
pub const DEFAULT_MANIFEST_FILE: &str = spin_common::paths::DEFAULT_MANIFEST_FILE;
pub const APP_MANIFEST_FILE_OPT: &str = "APP_MANIFEST_FILE";
pub const APPLICATION_OPT: &str = "APPLICATION";
pub const BUILDINFO_OPT: &str = "BUILDINFO";
pub const FROM_REGISTRY_OPT: &str = "REGISTRY_REFERENCE";
pub const INSECURE_OPT: &str = "INSECURE";
pub const CLOUD_SERVER_URL_OPT: &str = "CLOUD_SERVER_URL";
Expand Down

0 comments on commit 1e10bb6

Please sign in to comment.