Skip to content

Commit cd1c3cc

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

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
@@ -29,6 +29,12 @@ pub struct BuildCommand {
2929
#[clap(short = 'c', long, multiple = true)]
3030
pub component_id: Vec<String>,
3131

32+
/// By default, if the application manifest specifies one or more deployment targets, Spin
33+
/// checks that all components are compatible with those deployment targets. Specify
34+
/// this option to bypass those target checks.
35+
#[clap(long = "skip-target-checks", alias = "skip-target-check", takes_value = false)]
36+
skip_target_checks: bool,
37+
3238
/// Run the application after building.
3339
#[clap(name = BUILD_UP_OPT, short = 'u', long = "up")]
3440
pub up: bool,
@@ -43,7 +49,7 @@ impl BuildCommand {
4349
spin_common::paths::find_manifest_file_path(self.app_source.as_ref())?;
4450
notify_if_nondefault_rel(&manifest_file, distance);
4551

46-
spin_build::build(&manifest_file, &self.component_id).await?;
52+
spin_build::build(&manifest_file, &self.component_id, self.skip_target_checks).await?;
4753

4854
if self.up {
4955
let mut cmd = UpCommand::parse_from(

src/commands/registry.rs

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

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

@@ -75,7 +75,7 @@ impl Push {
7575
notify_if_nondefault_rel(&app_file, distance);
7676

7777
if self.build {
78-
spin_build::build(&app_file, &[]).await?;
78+
spin_build::build(&app_file, &[], false).await?;
7979
}
8080

8181
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
@@ -108,7 +108,7 @@ pub struct UpCommand {
108108
#[clap(long, takes_value = false)]
109109
pub direct_mounts: bool,
110110

111-
/// For local apps, specifies to perform `spin build` before running the application.
111+
/// For local apps, specifies to perform `spin build` (with the default options) before running the application.
112112
///
113113
/// This is ignored on remote applications, as they are already built.
114114
#[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
@@ -58,7 +58,7 @@ impl AppSource {
5858

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

0 commit comments

Comments
 (0)