-
Notifications
You must be signed in to change notification settings - Fork 7
Move Edge App deploy orchestration to the server #312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rusko124
wants to merge
2
commits into
master
Choose a base branch
from
feat/server-side-edge-app-deploy
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,171 @@ | ||
| use std::collections::HashMap; | ||
| use std::fmt; | ||
| use std::time::Duration; | ||
|
|
||
| use log::debug; | ||
| use reqwest::StatusCode; | ||
| use serde::{Deserialize, Serialize}; | ||
| use serde_json::Value; | ||
|
|
||
| use crate::api::Api; | ||
| use crate::commands::CommandError; | ||
|
|
||
| const DEPLOY_TIMEOUT_SECONDS: u64 = 60; | ||
|
|
||
| #[derive(Debug, Serialize)] | ||
| pub struct DeployPayload { | ||
| pub manifest: Value, | ||
| pub file_tree: HashMap<String, String>, | ||
| pub delete_missing_settings: bool, | ||
| } | ||
|
|
||
| #[derive(Clone, Debug, Default, PartialEq, Deserialize)] | ||
| pub struct FailedFile { | ||
| pub path: String, | ||
| pub error: String, | ||
| } | ||
|
|
||
| #[derive(Clone, Debug, Default, PartialEq, Deserialize)] | ||
| pub struct OutstandingFiles { | ||
| #[serde(default)] | ||
| pub missing: Vec<String>, | ||
| #[serde(default)] | ||
| pub pending: Vec<String>, | ||
| #[serde(default)] | ||
| pub failed: Vec<FailedFile>, | ||
| } | ||
|
|
||
| pub fn describe_failed_files(files: &[FailedFile]) -> String { | ||
| files | ||
| .iter() | ||
| .map(|file| format!("{}: {}", file.path, file.error)) | ||
| .collect::<Vec<_>>() | ||
| .join("; ") | ||
| } | ||
|
|
||
| impl fmt::Display for OutstandingFiles { | ||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| let mut parts = Vec::new(); | ||
| if !self.missing.is_empty() { | ||
| parts.push(format!("not uploaded: {}", self.missing.join(", "))); | ||
| } | ||
| if !self.pending.is_empty() { | ||
| parts.push(format!("still processing: {}", self.pending.join(", "))); | ||
| } | ||
| if !self.failed.is_empty() { | ||
| parts.push(format!("failed: {}", describe_failed_files(&self.failed))); | ||
| } | ||
| write!(f, "{}", parts.join("; ")) | ||
| } | ||
| } | ||
|
|
||
| #[derive(Clone, Debug, Default, PartialEq, Deserialize)] | ||
| pub struct SettingsDiff { | ||
| #[serde(default)] | ||
| pub create: Vec<String>, | ||
| #[serde(default)] | ||
| pub update: Vec<String>, | ||
| #[serde(default)] | ||
| pub delete: Vec<String>, | ||
| } | ||
|
|
||
| #[derive(Clone, Debug, Default, PartialEq, Deserialize)] | ||
| pub struct DeployDiff { | ||
| #[serde(default)] | ||
| pub settings: SettingsDiff, | ||
| } | ||
|
|
||
| #[derive(Clone, Debug, Default, PartialEq, Deserialize)] | ||
| pub struct DeployPreview { | ||
| pub deploy_needed: bool, | ||
| #[serde(default)] | ||
| pub outstanding: OutstandingFiles, | ||
| #[serde(default)] | ||
| pub diff: DeployDiff, | ||
| } | ||
|
|
||
| #[derive(Clone, Debug, Default, PartialEq, Deserialize)] | ||
| pub struct DeployResult { | ||
| pub revision: u32, | ||
| pub created: bool, | ||
| #[serde(default)] | ||
| pub published: bool, | ||
| #[serde(default)] | ||
| pub channel: String, | ||
| } | ||
|
|
||
| impl Api { | ||
| pub fn deploy_preview( | ||
| &self, | ||
| app_id: &str, | ||
| payload: &DeployPayload, | ||
| ) -> Result<DeployPreview, CommandError> { | ||
| let (status, body) = self.post_deploy(app_id, "deploy/preview", payload)?; | ||
| if status != StatusCode::OK { | ||
| return Err(CommandError::WrongResponseStatus(status.as_u16())); | ||
| } | ||
|
|
||
| Ok(serde_json::from_value(body)?) | ||
| } | ||
|
|
||
| pub fn deploy( | ||
| &self, | ||
| app_id: &str, | ||
| payload: &DeployPayload, | ||
| ) -> Result<DeployResult, CommandError> { | ||
| #[derive(Deserialize)] | ||
| struct Conflict { | ||
| #[serde(default)] | ||
| outstanding: OutstandingFiles, | ||
| } | ||
|
|
||
| let (status, body) = self.post_deploy(app_id, "deploy", payload)?; | ||
| match status { | ||
| StatusCode::OK => Ok(serde_json::from_value(body)?), | ||
| StatusCode::CONFLICT => { | ||
| let conflict: Conflict = serde_json::from_value(body)?; | ||
| Err(CommandError::DeployRejected( | ||
| conflict.outstanding.to_string(), | ||
| )) | ||
| } | ||
| _ => Err(CommandError::WrongResponseStatus(status.as_u16())), | ||
| } | ||
| } | ||
|
|
||
| fn post_deploy( | ||
| &self, | ||
| app_id: &str, | ||
| endpoint: &str, | ||
| payload: &DeployPayload, | ||
| ) -> Result<(StatusCode, Value), CommandError> { | ||
| let url = format!( | ||
| "{}/v3/edge-apps/{app_id}/{endpoint}", | ||
| &self.authentication.config.url | ||
|
Check warning on line 143 in src/api/edge_app/deploy.rs
|
||
| ); | ||
| debug!("POST {url}"); | ||
|
|
||
| let response = self | ||
| .authentication | ||
| .build_client()? | ||
| .post(&url) | ||
| .timeout(Duration::from_secs(DEPLOY_TIMEOUT_SECONDS)) | ||
| .json(payload) | ||
| .send()?; | ||
|
|
||
| let status = response.status(); | ||
| debug!("POST {url} -> {status}"); | ||
|
|
||
| match status { | ||
| StatusCode::OK | StatusCode::CONFLICT => { | ||
| Ok((status, serde_json::from_str(&response.text()?)?)) | ||
| } | ||
| StatusCode::NOT_FOUND => Err(CommandError::AppNotFound(format!( | ||
| "Edge App with ID '{app_id}' not found." | ||
| ))), | ||
| _ => { | ||
| debug!("Response: {:?}", &response.text()?); | ||
|
Check warning on line 166 in src/api/edge_app/deploy.rs
|
||
| Err(CommandError::WrongResponseStatus(status.as_u16())) | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| pub mod app; | ||
| pub mod channel; | ||
| pub mod deploy; | ||
| pub mod installation; | ||
| pub mod setting; | ||
| pub mod version; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-blocking, but worth catching before a large app hits it: this URL now scales with the number of files uploaded.
Each ULID is ~27 bytes with its separator, so ~300 uploaded files puts the request line past the usual 8 KB header limit and the poll starts 414ing — mid-deploy, after the upload has already succeeded. The first deploy of a large app is exactly the case where every file is missing and every id lands in this list, so it's reachable in one shot rather than needing an unlucky sequence.
Chunking the ids inside the poll loop covers it — the statuses from each batch just concatenate, and the
failed/pending_countlogic above doesn't care that they arrived in pieces.