Skip to content

Commit 2d617b6

Browse files
committed
Enable skipping target validation for offline or to bypass delays
Signed-off-by: itowlson <ivan.towlson@fermyon.com>
1 parent 036595b commit 2d617b6

File tree

5 files changed

+15
-8
lines changed

5 files changed

+15
-8
lines changed

crates/build/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use subprocess::{Exec, Redirection};
1717
use crate::manifest::component_build_configs;
1818

1919
/// If present, run the build command of each component.
20-
pub async fn build(manifest_file: &Path, component_ids: &[String]) -> Result<()> {
20+
pub async fn build(manifest_file: &Path, component_ids: &[String], skip_target_checks: bool) -> Result<()> {
2121
let (components, deployment_targets, manifest) = component_build_configs(manifest_file)
2222
.await
2323
.with_context(|| {
@@ -37,7 +37,8 @@ pub async fn build(manifest_file: &Path, component_ids: &[String]) -> Result<()>
3737
build_result?;
3838

3939
if let Ok(manifest) = &manifest {
40-
if !deployment_targets.is_empty() {
40+
let should_check_targets = !skip_target_checks && !deployment_targets.is_empty();
41+
if should_check_targets {
4142
let resolution_context =
4243
spin_environments::ResolutionContext::new(manifest_file.parent().unwrap()).await?;
4344
spin_environments::validate_application_against_environment_ids(
@@ -163,6 +164,6 @@ mod tests {
163164
#[tokio::test]
164165
async fn can_load_even_if_trigger_invalid() {
165166
let bad_trigger_file = test_data_root().join("bad_trigger.toml");
166-
build(&bad_trigger_file, &[]).await.unwrap();
167+
build(&bad_trigger_file, &[], true).await.unwrap();
167168
}
168169
}

src/commands/build.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ pub struct BuildCommand {
2727
#[clap(short = 'c', long, multiple = true)]
2828
pub component_id: Vec<String>,
2929

30+
/// By default, if the application manifest specifies one or more deployment targets, Spin
31+
/// checks that all components are compatible with those deployment targets. Specify
32+
/// this option to bypass those target checks.
33+
#[clap(long = "skip-target-checks", alias = "skip-target-check", takes_value = false)]
34+
skip_target_checks: bool,
35+
3036
/// Run the application after building.
3137
#[clap(name = BUILD_UP_OPT, short = 'u', long = "up")]
3238
pub up: bool,
@@ -38,7 +44,7 @@ pub struct BuildCommand {
3844
impl BuildCommand {
3945
pub async fn run(self) -> Result<()> {
4046
let manifest_file = spin_common::paths::resolve_manifest_file_path(&self.app_source)?;
41-
spin_build::build(&manifest_file, &self.component_id).await?;
47+
spin_build::build(&manifest_file, &self.component_id, self.skip_target_checks).await?;
4248

4349
if self.up {
4450
let mut cmd = UpCommand::parse_from(

src/commands/registry.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub struct Push {
5050
)]
5151
pub insecure: bool,
5252

53-
/// Specifies to perform `spin build` before pushing the application.
53+
/// Specifies to perform `spin build` (with the default options) before pushing the application.
5454
#[clap(long, takes_value = false, env = ALWAYS_BUILD_ENV)]
5555
pub build: bool,
5656

@@ -73,7 +73,7 @@ impl Push {
7373
pub async fn run(self) -> Result<()> {
7474
let app_file = spin_common::paths::resolve_manifest_file_path(&self.app_source)?;
7575
if self.build {
76-
spin_build::build(&app_file, &[]).await?;
76+
spin_build::build(&app_file, &[], false).await?;
7777
}
7878

7979
let annotations = if self.annotations.is_empty() {

src/commands/up.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub struct UpCommand {
107107
#[clap(long, takes_value = false)]
108108
pub direct_mounts: bool,
109109

110-
/// For local apps, specifies to perform `spin build` before running the application.
110+
/// For local apps, specifies to perform `spin build` (with the default options) before running the application.
111111
///
112112
/// This is ignored on remote applications, as they are already built.
113113
#[clap(long, takes_value = false, env = ALWAYS_BUILD_ENV)]

src/commands/up/app_source.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl AppSource {
5959

6060
pub async fn build(&self) -> anyhow::Result<()> {
6161
match self {
62-
Self::File(path) => spin_build::build(path, &[]).await,
62+
Self::File(path) => spin_build::build(path, &[], false).await,
6363
_ => Ok(()),
6464
}
6565
}

0 commit comments

Comments
 (0)