Skip to content

Commit

Permalink
Make creation modal button text configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
lyang2821 committed Aug 22, 2024
1 parent f627b9a commit 1f83081
Show file tree
Hide file tree
Showing 16 changed files with 142 additions and 66 deletions.
7 changes: 7 additions & 0 deletions lapdev-api/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use axum::{
};
use axum_client_ip::SecureClientIpSource;
use axum_extra::{headers, TypedHeader};
use hyper::StatusCode;
use lapdev_db::entities;
use lapdev_proxy_http::forward::ProxyForward;
use lapdev_rpc::error::ApiError;
Expand Down Expand Up @@ -35,8 +36,14 @@ fn private_routes() -> Router<CoreState> {
)
}

async fn not_found() -> impl IntoResponse {
StatusCode::NOT_FOUND
}

fn v1_api_routes(additional_router: Option<Router<CoreState>>) -> Router<CoreState> {
let router = Router::new()
.route("/", any(not_found))
.route("/*0", any(not_found))
.route("/cluster_info", get(admin::get_cluster_info))
.route("/auth_providers", get(admin::get_auth_providers))
.route("/hostnames", get(admin::get_hostnames))
Expand Down
27 changes: 21 additions & 6 deletions lapdev-api/src/server.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::{path::PathBuf, sync::Arc};
use std::{
path::{Path, PathBuf},
sync::Arc,
};

use anyhow::{anyhow, Context, Result};
use axum::{extract::Request, Router};
Expand Down Expand Up @@ -38,22 +41,33 @@ struct Cli {
/// The folder for putting logs
#[clap(short, long, action, value_hint = clap::ValueHint::AnyPath)]
logs_folder: Option<PathBuf>,
/// The folder for putting data
#[clap(short, long, action, value_hint = clap::ValueHint::AnyPath)]
data_folder: Option<PathBuf>,
/// Don't run db migration on startup
#[clap(short, long, action)]
no_migration: bool,
}

pub async fn start(additional_router: Option<Router<CoreState>>) {
let cli = Cli::parse();
let data_folder = cli
.data_folder
.clone()
.unwrap_or_else(|| PathBuf::from("/var/lib/lapdev"));

let _result = setup_log(&cli).await;
let _result = setup_log(&cli, &data_folder).await;

if let Err(e) = run(&cli, additional_router).await {
if let Err(e) = run(&cli, additional_router, data_folder).await {
tracing::error!("lapdev api start server error: {e:#}");
}
}

async fn run(cli: &Cli, additional_router: Option<Router<CoreState>>) -> Result<()> {
async fn run(
cli: &Cli,
additional_router: Option<Router<CoreState>>,
data_folder: PathBuf,
) -> Result<()> {
let config_file = cli
.config_file
.clone()
Expand All @@ -68,7 +82,7 @@ async fn run(cli: &Cli, additional_router: Option<Router<CoreState>>) -> Result<
.ok_or_else(|| anyhow!("can't find database url in your config file"))?;

let db = DbApi::new(&db_url, cli.no_migration).await?;
let conductor = Conductor::new(LAPDEV_VERSION, db.clone()).await?;
let conductor = Conductor::new(LAPDEV_VERSION, db.clone(), data_folder).await?;

let ssh_proxy_port = config.ssh_proxy_port.unwrap_or(2222);
{
Expand Down Expand Up @@ -164,11 +178,12 @@ async fn run(cli: &Cli, additional_router: Option<Router<CoreState>>) -> Result<

async fn setup_log(
cli: &Cli,
data_folder: &Path,
) -> Result<tracing_appender::non_blocking::WorkerGuard, anyhow::Error> {
let folder = cli
.logs_folder
.clone()
.unwrap_or_else(|| PathBuf::from("/var/lib/lapdev/logs"));
.unwrap_or_else(|| data_folder.join("logs"));
tokio::fs::create_dir_all(&folder).await?;
let file_appender = tracing_appender::rolling::Builder::new()
.max_log_files(30)
Expand Down
23 changes: 15 additions & 8 deletions lapdev-conductor/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ pub struct Conductor {
rpcs: Arc<Mutex<HashMap<Uuid, WorkspaceServiceClient>>>,
ws_hosts: Arc<Mutex<HashMap<Uuid, WorkspaceHostInfo>>>,
region: Arc<RwLock<String>>,
data_folder: PathBuf,
pub hostnames: Arc<RwLock<HashMap<String, String>>>,
pub cpu_overcommit: Arc<RwLock<usize>>,
// updates for a single prebuild, including the image building outputs
Expand All @@ -129,10 +130,10 @@ pub struct Conductor {
}

impl Conductor {
pub async fn new(version: &str, db: DbApi) -> Result<Self> {
tokio::fs::create_dir_all("/var/lib/lapdev/projects/")
pub async fn new(version: &str, db: DbApi, data_folder: PathBuf) -> Result<Self> {
tokio::fs::create_dir_all(data_folder.join("projects"))
.await
.with_context(|| "trying to create /var/lib/lapdev/projects/")?;
.with_context(|| format!("trying to create {:?}", data_folder.join("projects")))?;
let cpu_overcommit = db
.get_config(LAPDEV_CPU_OVERCOMMIT)
.await
Expand All @@ -144,6 +145,7 @@ impl Conductor {
let enterprise = Arc::new(Enterprise::new(db.clone()).await?);
let hostnames = enterprise.get_hostnames().await.unwrap_or_default();
let conductor = Self {
data_folder,
version: version.to_string(),
rpcs: Default::default(),
rpc_aborts: Default::default(),
Expand Down Expand Up @@ -548,8 +550,9 @@ impl Conductor {
let local_repo_url = repo_url.to_string();
let repo_url = repo_url.to_string();
let auth = auth.clone();
let data_folder = self.data_folder.clone();
tokio::task::spawn_blocking(move || {
let repo = git2::Repository::init("/var/lib/lapdev")?;
let repo = git2::Repository::init(data_folder)?;
let mut remote = repo.remote_anonymous(&repo_url)?;

let mut cbs = RemoteCallbacks::new();
Expand Down Expand Up @@ -680,7 +683,7 @@ impl Conductor {
.await?;
txn.commit().await?;

let path = PathBuf::from(format!("/var/lib/lapdev/projects/{id}"));
let path = self.data_folder.join(format!("projects/{id}"));
let url = repo.url.clone();
tokio::fs::create_dir_all(&path).await?;
clone_repo(url, path, repo.auth.clone()).await?;
Expand All @@ -700,9 +703,10 @@ impl Conductor {
user_agent: Option<String>,
) -> Result<Vec<GitBranch>, ApiError> {
let project_id = project.id;
let data_folder = self.data_folder.clone();
let (previous_branches, branches) = tokio::task::spawn_blocking(
move || -> Result<(Vec<GitBranch>, Vec<GitBranch>), ApiError> {
let path = PathBuf::from(format!("/var/lib/lapdev/projects/{project_id}"));
let path = data_folder.join(format!("projects/{project_id}"));
let repo = git2::Repository::open(path)?;

let previous_branches = repo_branches(&repo)?;
Expand Down Expand Up @@ -1236,7 +1240,10 @@ impl Conductor {

async fn prepare_repo(&self, repo: &RepoDetails, temp_repo_dir: &Path) -> Result<(), ApiError> {
if let Some(project) = repo.project.as_ref() {
let src_repo_dir = format!("/var/lib/lapdev/projects/{}/.", project.id);
let src_repo_dir = self.data_folder.join(format!("projects/{}/.", project.id));
let src_repo_dir = src_repo_dir
.to_str()
.ok_or_else(|| anyhow!("can't get repo dir"))?;
let temp_repo_dir = temp_repo_dir
.to_str()
.ok_or_else(|| anyhow!("can't get repo dir"))?;
Expand Down Expand Up @@ -2836,7 +2843,7 @@ impl Conductor {
}
}

let path = PathBuf::from(format!("/var/lib/lapdev/projects/{}", project.id));
let path = self.data_folder.join(format!("projects/{}", project.id));
tokio::fs::remove_dir_all(path).await?;

Ok(())
Expand Down
56 changes: 30 additions & 26 deletions lapdev-dashboard/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub fn Login() -> impl IntoView {

view! {
<section class="bg-gray-50 dark:bg-gray-900">
<div class="flex flex-col items-center justify-center px-6 py-8 mx-auto md:h-screen lg:py-0">
<div class="flex flex-col items-center justify-center px-6 py-8 mx-auto h-screen lg:py-0">
<a href="#" class="flex items-center mb-6 text-2xl font-semibold text-gray-900 dark:text-white">
<svg class="w-10 h-10 mr-4" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 1024 1024">
<path d="M512 0C390.759 0 279.426 42.2227 191.719 112.656L191.719 612L351.719 612L351.719 332L422 332L431.719 332L431.719 332.344C488.169 334.127 541.249 351.138 581.875 380.625C627.591 413.806 654.875 460.633 654.875 512C654.875 563.367 627.591 610.194 581.875 643.375C541.249 672.862 488.169 689.873 431.719 691.656L431.719 1017.69C457.88 1021.81 484.68 1024 512 1024C794.77 1024 1024 794.77 1024 512C1024 229.23 794.77 0 512 0ZM111.719 192.906C41.8539 280.432 0 391.303 0 512C0 738.766 147.487 930.96 351.719 998.25L351.719 692L151.719 692L151.719 691.844L111.719 691.844L111.719 192.906ZM738.219 372C741.597 372.107 745.042 373.02 748.312 374.812L946.281 483.312C952.311 486.616 956.692 492.393 959.188 499.156C959.821 500.874 960.317 502.641 960.688 504.469C960.764 504.834 960.841 505.196 960.906 505.562C961.12 506.807 961.225 508.071 961.312 509.344C961.378 510.235 961.498 511.112 961.5 512C961.498 512.888 961.378 513.765 961.312 514.656C961.226 515.929 961.12 517.193 960.906 518.438C960.841 518.804 960.764 519.166 960.688 519.531C960.317 521.359 959.821 523.126 959.188 524.844C956.692 531.608 952.311 537.384 946.281 540.688L748.312 649.188C735.232 656.355 719.818 649.367 713.875 633.594C707.932 617.82 713.7 599.23 726.781 592.062L872.875 512L726.781 431.938C713.7 424.771 707.932 406.18 713.875 390.406C718.332 378.576 728.085 371.678 738.219 372ZM431.719 412.344L431.719 611.656C513.56 608.208 574.875 561.985 574.875 512C574.875 462.015 513.56 415.792 431.719 412.344Z" />
Expand Down Expand Up @@ -88,32 +88,36 @@ pub fn LoginWithView(auth_providers: Vec<AuthProvider>) -> impl IntoView {
let login = use_context::<Resource<i32, Option<MeUser>>>().unwrap();
view! {
<div
class="w-full bg-white rounded-lg shadow dark:border md:mt-0 sm:max-w-md xl:p-0 dark:bg-gray-800 dark:border-gray-700"
class:hidden=move || login.with(|l| l.is_none())
class="max-w-96 w-full"
class:hidden=move || login.with(|l| l.is_none())
>
<div class="p-6">
<h1 class="mb-4 text-xl font-bold leading-tight tracking-tight text-gray-900 md:text-2xl dark:text-white">
Sign in to your account
</h1>
<button type="button"
class="mb-2 w-full text-gray-900 bg-white hover:bg-gray-100 border border-gray-200 focus:ring-4 focus:outline-none focus:ring-gray-100 font-medium rounded-lg text-sm px-5 py-2.5 text-center inline-flex items-center dark:focus:ring-gray-600 dark:bg-gray-800 dark:border-gray-700 dark:text-white dark:hover:bg-gray-700"
class:hidden={ let auth_providers = auth_providers.clone(); move || !auth_providers.contains(&AuthProvider::Github) }
on:click=move |_| { create_action(move |_| {now_login(AuthProvider::Github)}).dispatch(()) }
>
<svg class="w-4 h-4 me-2" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
<path fill-rule="evenodd" d="M10 .333A9.911 9.911 0 0 0 6.866 19.65c.5.092.678-.215.678-.477 0-.237-.01-1.017-.014-1.845-2.757.6-3.338-1.169-3.338-1.169a2.627 2.627 0 0 0-1.1-1.451c-.9-.615.07-.6.07-.6a2.084 2.084 0 0 1 1.518 1.021 2.11 2.11 0 0 0 2.884.823c.044-.503.268-.973.63-1.325-2.2-.25-4.516-1.1-4.516-4.9A3.832 3.832 0 0 1 4.7 7.068a3.56 3.56 0 0 1 .095-2.623s.832-.266 2.726 1.016a9.409 9.409 0 0 1 4.962 0c1.89-1.282 2.717-1.016 2.717-1.016.366.83.402 1.768.1 2.623a3.827 3.827 0 0 1 1.02 2.659c0 3.807-2.319 4.644-4.525 4.889a2.366 2.366 0 0 1 .673 1.834c0 1.326-.012 2.394-.012 2.72 0 .263.18.572.681.475A9.911 9.911 0 0 0 10 .333Z" clip-rule="evenodd"/>
</svg>
Sign in with GitHub
</button>

<button type="button"
class="mb-2 w-full text-gray-900 bg-white hover:bg-gray-100 border border-gray-200 focus:ring-4 focus:outline-none focus:ring-gray-100 font-medium rounded-lg text-sm px-5 py-2.5 text-center inline-flex items-center dark:focus:ring-gray-600 dark:bg-gray-800 dark:border-gray-700 dark:text-white dark:hover:bg-gray-700"
class:hidden=move || !auth_providers.contains(&AuthProvider::Gitlab)
on:click=move |_| { create_action(move |_| {now_login(AuthProvider::Gitlab)}).dispatch(()) }
>
<svg class="w-4 h-4 me-2" viewBox="0 0 25 24" xmlns="http://www.w3.org/2000/svg"><path d="M24.507 9.5l-.034-.09L21.082.562a.896.896 0 00-1.694.091l-2.29 7.01H7.825L5.535.653a.898.898 0 00-1.694-.09L.451 9.411.416 9.5a6.297 6.297 0 002.09 7.278l.012.01.03.022 5.16 3.867 2.56 1.935 1.554 1.176a1.051 1.051 0 001.268 0l1.555-1.176 2.56-1.935 5.197-3.89.014-.01A6.297 6.297 0 0024.507 9.5z" fill="#E24329"/><path d="M24.507 9.5l-.034-.09a11.44 11.44 0 00-4.56 2.051l-7.447 5.632 4.742 3.584 5.197-3.89.014-.01A6.297 6.297 0 0024.507 9.5z" fill="#FC6D26"/><path d="M7.707 20.677l2.56 1.935 1.555 1.176a1.051 1.051 0 001.268 0l1.555-1.176 2.56-1.935-4.743-3.584-4.755 3.584z" fill="#FCA326"/><path d="M5.01 11.461a11.43 11.43 0 00-4.56-2.05L.416 9.5a6.297 6.297 0 002.09 7.278l.012.01.03.022 5.16 3.867 4.745-3.584-7.444-5.632z" fill="#FC6D26"/></svg>
Sign in with GitLab
</button>
<h1 class="mb-4 text-center text-2xl font-bold leading-tight tracking-tight text-gray-900 dark:text-white">
Sign in to your account
</h1>
<div
class="w-full bg-white rounded-lg shadow dark:border md:mt-0 sm:max-w-md xl:p-0 dark:bg-gray-800 dark:border-gray-700"
>
<div class="p-6 flex flex-col space-y-3">
<button type="button"
class="w-full text-gray-900 bg-white hover:bg-gray-100 border border-gray-200 focus:ring-4 focus:outline-none focus:ring-gray-100 font-medium rounded-lg text-sm px-5 py-2.5 text-center inline-flex items-center dark:focus:ring-gray-600 dark:bg-gray-800 dark:border-gray-700 dark:text-white dark:hover:bg-gray-700"
class:hidden={ let auth_providers = auth_providers.clone(); move || !auth_providers.contains(&AuthProvider::Github) }
on:click=move |_| { create_action(move |_| {now_login(AuthProvider::Github)}).dispatch(()) }
>
<svg class="w-4 h-4 me-2" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
<path fill-rule="evenodd" d="M10 .333A9.911 9.911 0 0 0 6.866 19.65c.5.092.678-.215.678-.477 0-.237-.01-1.017-.014-1.845-2.757.6-3.338-1.169-3.338-1.169a2.627 2.627 0 0 0-1.1-1.451c-.9-.615.07-.6.07-.6a2.084 2.084 0 0 1 1.518 1.021 2.11 2.11 0 0 0 2.884.823c.044-.503.268-.973.63-1.325-2.2-.25-4.516-1.1-4.516-4.9A3.832 3.832 0 0 1 4.7 7.068a3.56 3.56 0 0 1 .095-2.623s.832-.266 2.726 1.016a9.409 9.409 0 0 1 4.962 0c1.89-1.282 2.717-1.016 2.717-1.016.366.83.402 1.768.1 2.623a3.827 3.827 0 0 1 1.02 2.659c0 3.807-2.319 4.644-4.525 4.889a2.366 2.366 0 0 1 .673 1.834c0 1.326-.012 2.394-.012 2.72 0 .263.18.572.681.475A9.911 9.911 0 0 0 10 .333Z" clip-rule="evenodd"/>
</svg>
Sign in with GitHub
</button>

<button type="button"
class="w-full text-gray-900 bg-white hover:bg-gray-100 border border-gray-200 focus:ring-4 focus:outline-none focus:ring-gray-100 font-medium rounded-lg text-sm px-5 py-2.5 text-center inline-flex items-center dark:focus:ring-gray-600 dark:bg-gray-800 dark:border-gray-700 dark:text-white dark:hover:bg-gray-700"
class:hidden=move || !auth_providers.contains(&AuthProvider::Gitlab)
on:click=move |_| { create_action(move |_| {now_login(AuthProvider::Gitlab)}).dispatch(()) }
>
<svg class="w-4 h-4 me-2" viewBox="0 0 25 24" xmlns="http://www.w3.org/2000/svg"><path d="M24.507 9.5l-.034-.09L21.082.562a.896.896 0 00-1.694.091l-2.29 7.01H7.825L5.535.653a.898.898 0 00-1.694-.09L.451 9.411.416 9.5a6.297 6.297 0 002.09 7.278l.012.01.03.022 5.16 3.867 2.56 1.935 1.554 1.176a1.051 1.051 0 001.268 0l1.555-1.176 2.56-1.935 5.197-3.89.014-.01A6.297 6.297 0 0024.507 9.5z" fill="#E24329"/><path d="M24.507 9.5l-.034-.09a11.44 11.44 0 00-4.56 2.051l-7.447 5.632 4.742 3.584 5.197-3.89.014-.01A6.297 6.297 0 0024.507 9.5z" fill="#FC6D26"/><path d="M7.707 20.677l2.56 1.935 1.555 1.176a1.051 1.051 0 001.268 0l1.555-1.176 2.56-1.935-4.743-3.584-4.755 3.584z" fill="#FCA326"/><path d="M5.01 11.461a11.43 11.43 0 00-4.56-2.05L.416 9.5a6.297 6.297 0 002.09 7.278l.012.01.03.022 5.16 3.867 4.745-3.584-7.444-5.632z" fill="#FC6D26"/></svg>
Sign in with GitLab
</button>
</div>
</div>
</div>
}
Expand Down
9 changes: 9 additions & 0 deletions lapdev-dashboard/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ use crate::{
workspace::{WorkspaceDetails, Workspaces},
};

#[derive(Clone)]
pub struct AppConfig {
pub show_lapdev_website: bool,
}

#[component]
fn Root() -> impl IntoView {
view! {
Expand Down Expand Up @@ -61,6 +66,10 @@ pub fn set_context() {
account: create_rw_signal(pathname.starts_with("/account")),
};
provide_context(nav_expanded);

provide_context(create_rw_signal(AppConfig {
show_lapdev_website: false,
}));
}

#[component]
Expand Down
10 changes: 5 additions & 5 deletions lapdev-dashboard/src/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ pub fn NewWorkspaceHostView(
<CreationInput label="Disk (GB)".to_string() value=disk placeholder="disk in GB".to_string() />
};
view! {
<CreationModal title="Create New Workspace Host".to_string() modal_hidden=new_workspace_host_modal_hidden action body is_update=false create_button_hidden=false />
<CreationModal title="Create New Workspace Host".to_string() modal_hidden=new_workspace_host_modal_hidden action body update_text=Some("Create".to_string()) updating_text=Some("Creating".to_string()) create_button_hidden=false />
}
}

Expand Down Expand Up @@ -184,7 +184,7 @@ pub fn UpdateWorkspaceHostModal(
<CreationInput label="Disk (GB)".to_string() value=disk placeholder="disk in GB".to_string() />
};
view! {
<CreationModal title="Update Workspace Host".to_string() modal_hidden=update_workspace_host_modal_hidden action body is_update=true create_button_hidden=false />
<CreationModal title="Update Workspace Host".to_string() modal_hidden=update_workspace_host_modal_hidden action body update_text=None updating_text=None create_button_hidden=false />
}
}

Expand Down Expand Up @@ -1096,7 +1096,7 @@ pub fn NewMachineTypeView(
</div>
};
view! {
<CreationModal title="Create New Machine Type".to_string() modal_hidden=new_machine_type_modal_hidden action body is_update=false create_button_hidden=false />
<CreationModal title="Create New Machine Type".to_string() modal_hidden=new_machine_type_modal_hidden action body update_text=Some("Create".to_string()) updating_text=Some("Creating".to_string()) create_button_hidden=false />
}
}

Expand Down Expand Up @@ -1127,7 +1127,7 @@ pub fn UpdateMachineTypeModal(
</div>
};
view! {
<CreationModal title="Update Workspace Host".to_string() modal_hidden=update_machine_type_modal_hidden action body is_update=true create_button_hidden=false />
<CreationModal title="Update Workspace Host".to_string() modal_hidden=update_machine_type_modal_hidden action body update_text=None updating_text=None create_button_hidden=false />
}
}

Expand Down Expand Up @@ -1668,6 +1668,6 @@ fn ClusterUserItemView(
</button>
</div>
</div>
<CreationModal title=format!("Update Cluster User") modal_hidden=update_modal_hidden action=update_action body=update_modal_body is_update=true create_button_hidden=false />
<CreationModal title=format!("Update Cluster User") modal_hidden=update_modal_hidden action=update_action body=update_modal_body update_text=None updating_text=None create_button_hidden=false />
}
}
Loading

0 comments on commit 1f83081

Please sign in to comment.