mirror of
https://github.com/moghtech/komodo.git
synced 2026-05-02 18:17:28 -05:00
* add some network stuff to container summary * improve settings tables UI * periphery build supports additional tags * fix variable container sizing * alert types newline wrap * plumbing for Stack resource * plumbing for Stack resource * mount stack api * stack resource sync * get remote compose file * support image_name and image_tag * add server config placeholders. default server config address * configure image name and image tag * deployment work with build image_name and image_tag * stack UI * fe builds * configure registry provider and account * implement periphery stack api * stack poll interval * add UI provider management * deploy stacks * build push commit hash tag. * Destroy stack * update default core port to 9120 * remove git_account alias * finish stack (and container) api * frontend builds * cant cancel server based builds * fix * use git pull -f * 9120 * start UI updates (#15) * fix From<Stack> for CloneArgs * remove unused imports * UI Updates (#16) * cleanup dashboard charts for resources * bring back solid scrollbars * enable sidebar scrolling * remove alerts from all resources * pass jwt secret * stacks dont delete the target * parse services from yaml * stacks deploy * close * looking good * closer * destroy stack when file missing. onboard stacks * figure out stack container name matching * get stack state correct * work with service views * UI Updates - Sidebar, Topbar Alerts, and All Resources page (#17) * move sidebar to use fixed positioning instead of sticky * add alert details dialog to topbar alerts * cleanup all resources page layout * ensure resource links don't propagate clicks * periphery support passing env with --env-file * StackServicePage * default run_directory to ./ for clarify * add stack webhook listeners * add default compose name of stack name * stacks controlled with project name * migrate to dotenvy * add stack to dashboard * remove deploying / destroying stack services * update config files * fix getting service logs * git / docker provider management api * implement passing git / registry token from db * rename system user Github to Git Webhook * seperate deployed and latest services on stack info * add stack service level operations * UI Updates - Update Shadcn/UI components, prevent navbar menu layout shift (#20) * add dashboard pie for resource syncs * dashboard items same height * update shadcn components * ensure centered following sheet update * cleanup layout, prevent navbar menu layout shifts * add manual filter, fix toast call * guard webhooks * remove deployed_message, latest_message from StackListItemInfo * stop all containers on server correctly * support multiple compose files * cache all containers networks images projects * remove project missing from db cache * work on sync deploy stuff * rework deployment sync deploy to support stacks. they can depend on each other. * UI Updates - Remove topbar transparency, pretty status badges, tidy resource page layout with a 'back' button (#21) * remove topbar transparency * cleanup unused * responsive dashboard * better mobile header * dont need to calc 64px less since header is using position fixed * add status badge component * update status badges * further simplify layout * allow undefined status as prop * use new status badges for alerts * update status badges for all resources * undo layout change * tidy up resource page layout, add back button * no need for button wrapper * remove unused * build cancel log * update ts types * fix fe type changes * fe tweaks * remove on build logs * core refresh cache immediately on startup * jwt_ttl * canonicalize run directory on host * update canonicalize error message * core use docker-compose * fix incorrect project missing, add status string to stack info * remove entries in "after" that aren't deploying * fix dockerfiel * build custom tag postfix * sync fixes * ensure UpdateGitProviderAccount doesn't change id * ensure UpdateDockerRegistryAccount doesn't change id * configure providers in the UI * add // comment support to env, conversions * add updates for provider deletes * improve sync pending deploy log * add more deployment actions * add backward compat with v1.12 for clone repo * stack deploy format * fe * alert menus clone when click resource link * rename stacks * don't close on click * snake case stack state, in line with deployment state * sync redeploy stack if newer hash (optional behind resource field 'latest_hash') * remove nav to tree * RefreshStack/Sync debug instruments * improve inline UI docs * implement resource base_permission backend * plumbing for Repo build * build repos * write env file repos * add latest hash / message to build info * add optional hash to update * keep built_hash updated * add backend for build / repo latest hash management * remove unused resources * clean up repo dirs after cache update * fix repo info deser error * add build / repo git status * fix page layouts * improve layout responsive * most config incline docs * add descriptions for all resource types * default local auth false * fix omnibar arrow keys issue * add compose file to example config * image registry * dashboard display no resources messge * update deps. * show when no config * resource sync use config git_provider * fix networks * fix deploy error due to after * update lots of docs * fix server stat charts not working * update screenshots * update changelog * add a disclaimer * remove file paths docs stuff * build repo * v1.13 - Komodo * update docs for cli * fill out the compose example more --------- Co-authored-by: Karamvir Singh <67458484+karamvirsingh98@users.noreply.github.com>
172 lines
4.1 KiB
Rust
172 lines
4.1 KiB
Rust
use std::time::Instant;
|
|
|
|
use anyhow::{anyhow, Context};
|
|
use axum::{middleware, routing::post, Extension, Router};
|
|
use formatting::format_serror;
|
|
use monitor_client::{
|
|
api::execute::*,
|
|
entities::{
|
|
update::{Log, Update},
|
|
user::User,
|
|
},
|
|
};
|
|
use mungos::by_id::find_one_by_id;
|
|
use resolver_api::{derive::Resolver, Resolver};
|
|
use serde::{Deserialize, Serialize};
|
|
use serror::Json;
|
|
use typeshare::typeshare;
|
|
use uuid::Uuid;
|
|
|
|
use crate::{
|
|
auth::auth_request,
|
|
helpers::update::{init_execution_update, update_update},
|
|
state::{db_client, State},
|
|
};
|
|
|
|
mod build;
|
|
mod deployment;
|
|
mod procedure;
|
|
mod repo;
|
|
mod server;
|
|
mod server_template;
|
|
mod stack;
|
|
mod sync;
|
|
|
|
#[typeshare]
|
|
#[derive(Serialize, Deserialize, Debug, Clone, Resolver)]
|
|
#[resolver_target(State)]
|
|
#[resolver_args((User, Update))]
|
|
#[serde(tag = "type", content = "params")]
|
|
pub enum ExecuteRequest {
|
|
// ==== SERVER ====
|
|
StopAllContainers(StopAllContainers),
|
|
PruneContainers(PruneContainers),
|
|
PruneImages(PruneImages),
|
|
PruneNetworks(PruneNetworks),
|
|
|
|
// ==== DEPLOYMENT ====
|
|
Deploy(Deploy),
|
|
StartContainer(StartContainer),
|
|
RestartContainer(RestartContainer),
|
|
PauseContainer(PauseContainer),
|
|
UnpauseContainer(UnpauseContainer),
|
|
StopContainer(StopContainer),
|
|
RemoveContainer(RemoveContainer),
|
|
|
|
// ==== STACK ====
|
|
DeployStack(DeployStack),
|
|
StartStack(StartStack),
|
|
RestartStack(RestartStack),
|
|
StopStack(StopStack),
|
|
PauseStack(PauseStack),
|
|
UnpauseStack(UnpauseStack),
|
|
DestroyStack(DestroyStack),
|
|
|
|
// ==== BUILD ====
|
|
RunBuild(RunBuild),
|
|
CancelBuild(CancelBuild),
|
|
|
|
// ==== REPO ====
|
|
CloneRepo(CloneRepo),
|
|
PullRepo(PullRepo),
|
|
BuildRepo(BuildRepo),
|
|
CancelRepoBuild(CancelRepoBuild),
|
|
|
|
// ==== PROCEDURE ====
|
|
RunProcedure(RunProcedure),
|
|
|
|
// ==== SERVER TEMPLATE ====
|
|
LaunchServer(LaunchServer),
|
|
|
|
// ==== SYNC ====
|
|
RunSync(RunSync),
|
|
}
|
|
|
|
pub fn router() -> Router {
|
|
Router::new()
|
|
.route("/", post(handler))
|
|
.layer(middleware::from_fn(auth_request))
|
|
}
|
|
|
|
async fn handler(
|
|
Extension(user): Extension<User>,
|
|
Json(request): Json<ExecuteRequest>,
|
|
) -> serror::Result<Json<Update>> {
|
|
let req_id = Uuid::new_v4();
|
|
|
|
// need to validate no cancel is active before any update is created.
|
|
build::validate_cancel_build(&request).await?;
|
|
|
|
let update = init_execution_update(&request, &user).await?;
|
|
|
|
let handle =
|
|
tokio::spawn(task(req_id, request, user, update.clone()));
|
|
|
|
tokio::spawn({
|
|
let update_id = update.id.clone();
|
|
async move {
|
|
let log = match handle.await {
|
|
Ok(Err(e)) => {
|
|
warn!("/execute request {req_id} task error: {e:#}",);
|
|
Log::error("task error", format_serror(&e.into()))
|
|
}
|
|
Err(e) => {
|
|
warn!("/execute request {req_id} spawn error: {e:?}",);
|
|
Log::error("spawn error", format!("{e:#?}"))
|
|
}
|
|
_ => return,
|
|
};
|
|
let res = async {
|
|
let mut update =
|
|
find_one_by_id(&db_client().await.updates, &update_id)
|
|
.await
|
|
.context("failed to query to db")?
|
|
.context("no update exists with given id")?;
|
|
update.logs.push(log);
|
|
update.finalize();
|
|
update_update(update).await
|
|
}
|
|
.await;
|
|
|
|
if let Err(e) = res {
|
|
warn!("failed to update update with task error log | {e:#}");
|
|
}
|
|
}
|
|
});
|
|
|
|
Ok(Json(update))
|
|
}
|
|
|
|
#[instrument(name = "ExecuteRequest", skip(user, update), fields(user_id = user.id, update_id = update.id))]
|
|
async fn task(
|
|
req_id: Uuid,
|
|
request: ExecuteRequest,
|
|
user: User,
|
|
update: Update,
|
|
) -> anyhow::Result<String> {
|
|
info!(
|
|
"/execute request {req_id} | user: {} ({})",
|
|
user.username, user.id
|
|
);
|
|
let timer = Instant::now();
|
|
|
|
let res = State
|
|
.resolve_request(request, (user, update))
|
|
.await
|
|
.map_err(|e| match e {
|
|
resolver_api::Error::Serialization(e) => {
|
|
anyhow!("{e:?}").context("response serialization error")
|
|
}
|
|
resolver_api::Error::Inner(e) => e,
|
|
});
|
|
|
|
if let Err(e) = &res {
|
|
warn!("/execute request {req_id} error: {e:#}");
|
|
}
|
|
|
|
let elapsed = timer.elapsed();
|
|
debug!("/execute request {req_id} | resolve time: {elapsed:?}");
|
|
|
|
res
|
|
}
|