-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
262 additions
and
88 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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,15 @@ | ||
#!/bin/sh | ||
|
||
tdxctl notify-host -e "boot.progress" -d "pulling images" || true | ||
if ! docker compose pull; then | ||
tdxctl notify-host -e "boot.error" -d "failed to pull images" | ||
exit 1 | ||
fi | ||
|
||
tdxctl notify-host -e "boot.progress" -d "starting containers" || true | ||
if ! docker compose up -d; then | ||
tdxctl notify-host -e "boot.error" -d "failed to start containers" | ||
exit 1 | ||
fi | ||
|
||
tdxctl notify-host -e "boot.progress" -d "containers started" || true |
This file contains 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 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 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 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,52 @@ | ||
use crate::utils::{deserialize_json_file, LocalConfig}; | ||
use anyhow::Result; | ||
use host_api::{ | ||
client::{new_client, DefaultClient}, | ||
Notification, | ||
}; | ||
use tracing::warn; | ||
|
||
pub(crate) struct NotifyClient { | ||
client: DefaultClient, | ||
} | ||
|
||
impl Default for NotifyClient { | ||
fn default() -> Self { | ||
Self::new("".into()) | ||
} | ||
} | ||
|
||
impl NotifyClient { | ||
pub fn new(base_url: String) -> Self { | ||
Self { | ||
client: new_client(base_url), | ||
} | ||
} | ||
|
||
pub fn load_or_default(url: Option<String>) -> Result<Self> { | ||
let url = match url { | ||
Some(url) => url, | ||
None => { | ||
let local_config: LocalConfig = deserialize_json_file("/tapp/config.json")?; | ||
local_config.host_api_url.clone() | ||
} | ||
}; | ||
Ok(Self::new(url)) | ||
} | ||
|
||
pub async fn notify(&self, event: &str, payload: &str) -> Result<()> { | ||
self.client | ||
.notify(Notification { | ||
event: event.to_string(), | ||
payload: payload.to_string(), | ||
}) | ||
.await?; | ||
Ok(()) | ||
} | ||
|
||
pub async fn notify_q(&self, event: &str, payload: &str) { | ||
if let Err(err) = self.notify(event, payload).await { | ||
warn!("Failed to notify event {event} to host: {:?}", err); | ||
} | ||
} | ||
} |
Oops, something went wrong.