Skip to content

Commit

Permalink
Upload lockfile when deploying (#1965)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse-Bakker authored Sep 1, 2023
1 parent a0b5e86 commit 420af04
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
3 changes: 3 additions & 0 deletions dozer-cli/src/cli/cloud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ pub struct DeployCommandArgs {
/// List of secrets which will be used in deployment
#[arg(short, long, value_parser = parse_key_val)]
pub secrets: Vec<Secret>,

#[arg(long = "no-lock", action = ArgAction::SetFalse)]
pub locked: bool,
}

pub fn default_num_api_instances() -> i32 {
Expand Down
3 changes: 3 additions & 0 deletions dozer-cli/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ pub enum CloudError {

#[error("Application not found")]
ApplicationNotFound,

#[error("{LOCK_FILE} not found. Run `dozer build` before deploying, or pass '--no-lock'.")]
LockfileNotFound,
}

#[derive(Debug, Error)]
Expand Down
29 changes: 24 additions & 5 deletions dozer-cli/src/simple/cloud_orchestrator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::cloud_app_context::CloudAppContext;
use crate::cloud_helper::list_files;

use crate::errors::OrchestrationError::FailedToReadOrganisationName;
use crate::errors::{map_tonic_error, CloudError, CloudLoginError, OrchestrationError};
use crate::errors::{map_tonic_error, CliError, CloudError, CloudLoginError, OrchestrationError};
use crate::progress_printer::{
get_delete_steps, get_deploy_steps, get_update_steps, ProgressPrinter,
};
Expand All @@ -16,14 +16,15 @@ use crate::simple::cloud::monitor::monitor_app;
use crate::simple::token_layer::TokenLayer;
use crate::simple::SimpleOrchestrator;
use crate::CloudOrchestrator;
use dozer_types::constants::DEFAULT_CLOUD_TARGET_URL;
use dozer_types::constants::{DEFAULT_CLOUD_TARGET_URL, LOCK_FILE};
use dozer_types::grpc_types::cloud::{
dozer_cloud_client::DozerCloudClient, CreateAppRequest, CreateSecretRequest, DeleteAppRequest,
DeleteSecretRequest, GetSecretRequest, GetStatusRequest, ListAppRequest, ListSecretsRequest,
LogMessageRequest, UpdateAppRequest, UpdateSecretRequest,
};
use dozer_types::grpc_types::cloud::{
DeploymentStatus, SetCurrentVersionRequest, SetNumApiInstancesRequest, UpsertVersionRequest,
DeploymentStatus, File, SetCurrentVersionRequest, SetNumApiInstancesRequest,
UpsertVersionRequest,
};
use dozer_types::log::info;
use dozer_types::prettytable::{row, table};
Expand Down Expand Up @@ -78,9 +79,26 @@ impl CloudOrchestrator for SimpleOrchestrator {
};

let cloud_config = self.config.cloud.as_ref();
let lockfile_path = self.lockfile_path();
self.runtime.block_on(async move {
let mut client = get_cloud_client(&cloud, cloud_config).await?;
let files = list_files(config_paths)?;
let mut files = list_files(config_paths)?;
if deploy.locked {
let lockfile_contents = tokio::fs::read_to_string(lockfile_path)
.await
.map_err::<OrchestrationError, _>(|e| {
if e.kind() == std::io::ErrorKind::NotFound {
CloudError::LockfileNotFound.into()
} else {
CliError::Io(e).into()
}
})?;
let lockfile = File {
name: LOCK_FILE.to_owned(),
content: lockfile_contents,
};
files.push(lockfile);
}
let (app_id_to_start, mut steps) = match app_id {
None => {
let mut steps = ProgressPrinter::new(get_deploy_steps());
Expand Down Expand Up @@ -130,7 +148,8 @@ impl CloudOrchestrator for SimpleOrchestrator {
&mut steps,
deploy.secrets,
)
.await
.await?;
Ok::<(), OrchestrationError>(())
})?;
Ok(())
}
Expand Down

0 comments on commit 420af04

Please sign in to comment.