Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/compute/onprem-config.tsx
Views: 687
import type {1ComputeServerTemplate,2OnPremCloudConfiguration,3State,4} from "@cocalc/util/db-schema/compute-servers";5import { ON_PREM_DEFAULTS } from "@cocalc/util/db-schema/compute-servers";6import { Checkbox, Divider, Select, Spin } from "antd";7import { setServerConfiguration } from "./api";8import { useEffect, useState } from "react";9import SelectImage, { ImageDescription, ImageLinks } from "./select-image";10import ExcludeFromSync from "./exclude-from-sync";11import ShowError from "@cocalc/frontend/components/error";12import Ephemeral from "./ephemeral";13import { SELECTOR_WIDTH } from "./google-cloud-config";14import Proxy from "./proxy";15import { useImages } from "./images-hook";16import DNS from "@cocalc/frontend/compute/cloud/common/dns";17import { A, Icon } from "@cocalc/frontend/components";18import Template from "@cocalc/frontend/compute/cloud/common/template";19import { useTypedRedux } from "@cocalc/frontend/app-framework";2021interface Props {22configuration: OnPremCloudConfiguration;23editable?: boolean;24// if id not set, then doesn't try to save anything to the backend25id?: number;26project_id: string;27// called whenever changes are made.28onChange?: (configuration: OnPremCloudConfiguration) => void;29disabled?: boolean;30state?: State;31data?;32template?: ComputeServerTemplate;33}3435export default function OnPremCloudConfiguration({36configuration: configuration0,37editable,38id,39project_id,40onChange,41disabled,42state,43data,44template,45}: Props) {46const [IMAGES, ImagesError] = useImages();47const [loading, setLoading] = useState<boolean>(false);48const [error, setError] = useState<string>("");49const [configuration, setLocalConfiguration] =50useState<OnPremCloudConfiguration>(configuration0);5152useEffect(() => {53if (!editable) {54setLocalConfiguration(configuration0);55}56}, [configuration0]);5758const setConfig = async (changes) => {59try {60const newConfiguration = { ...configuration, ...changes };61setLoading(true);62if (onChange != null) {63onChange(newConfiguration);64}65setLocalConfiguration(newConfiguration);66if (id != null) {67await setServerConfiguration({ id, configuration: changes });68}69} catch (err) {70setError(`${err}`);71} finally {72setLoading(false);73}74};7576if (!editable || !project_id) {77return (78<div>79Self Hosted {configuration.arch == "arm64" ? "ARM64" : "x86_64"} Linux80VM81{configuration.gpu ? " that has an NVIDIA GPU" : ""}.82</div>83);84}8586if (ImagesError != null) {87return ImagesError;88}8990return (91<div style={{ marginBottom: "30px" }}>92<div style={{ color: "#666", marginBottom: "15px" }}>93<div style={{ color: "#666", marginBottom: "5px" }}>94<b>Self Hosted Compute Server</b>95</div>96You can connect your own <b>Ubuntu 22.04 Virtual Machine</b> to this97CoCalc project and seamlessly run Jupyter notebooks and terminals on it.98<ul>99<li>100Watch the{" "}101<A href="https://youtu.be/NkNx6tx3nu0">102<Icon name="youtube" style={{ color: "red" }} /> compute server103tutorial104</A>105.106</li>107<li>Self hosted compute servers are currently free.</li>108<li>109<A href="https://onprem.cocalc.com/overview.html">CoCalc OnPrem</A>{" "}110is a related product for running a self-contained CoCalc cluster.111</li>112</ul>113</div>114<div style={{ color: "#666", marginBottom: "5px" }}>115<b>Architecture</b>116</div>117<Select118disabled={loading || disabled}119style={{ width: SELECTOR_WIDTH }}120options={[121{ label: "x86_64 (e.g., Linux VM on Intel or AMD)", value: "x86_64" },122{123label: "ARM 64 (e.g., Linux VM on an M1 Mac)",124value: "arm64",125disabled: configuration.gpu,126},127]}128value={configuration.arch ?? "x86_64"}129onChange={(arch) => {130setConfig({ arch });131}}132/>133<div style={{ margin: "15px 0" }}>134<Checkbox135disabled={136loading ||137disabled ||138configuration.arch ==139"arm64" /* we only have x86_64 docker images */140}141style={{ width: SELECTOR_WIDTH }}142checked={configuration.gpu}143onChange={() => {144setConfig({145gpu: !configuration.gpu,146image:147ON_PREM_DEFAULTS[!configuration.gpu ? "gpu" : "cpu"]?.image,148});149}}150>151NVIDIA GPU with CUDA 12.x installed152</Checkbox>153</div>154<Image155state={state}156disabled={loading || disabled}157setConfig={setConfig}158configuration={configuration}159/>160<ShowError error={error} setError={setError} />161<Divider />162<Proxy163id={id}164project_id={project_id}165setConfig={setConfig}166configuration={configuration}167data={data}168state={state}169IMAGES={IMAGES}170/>171{data?.externalIp && (172<>173<Divider />174<DNS175setConfig={setConfig}176configuration={configuration}177loading={loading}178/>179</>180)}181{loading && <Spin style={{ marginLeft: "15px" }} />}182<Admin id={id} template={template} />183</div>184);185}186187function Admin({ id, template }) {188const isAdmin = useTypedRedux("account", "is_admin");189if (!isAdmin) {190return null;191}192return <Template id={id} template={template} />;193}194195function Image(props) {196const { state = "deprovisioned" } = props;197return (198<div>199<div style={{ color: "#666", marginBottom: "5px" }}>200<b>Image</b>201</div>202{(state == "deprovisioned" || state == "off") && (203<div style={{ color: "#666", marginBottom: "5px" }}>204Select compute server image. You will be able to use sudo with no205password and can easily install anything into the Ubuntu Linux image.206</div>207)}208<SelectImage209{...props}210gpu={!!props.configuration.gpu}211arch={props.configuration.arch}212warnBigGb={4}213/>214<div style={{ color: "#666", marginTop: "5px" }}>215<ImageDescription configuration={props.configuration} />216<ImageLinks217image={props.configuration.image}218style={{ flexDirection: "row" }}219/>220{!(state == "deprovisioned" || state == "off") && (221<div style={{ color: "#666", marginTop: "5px" }}>222You can only edit the image when server is deprovisioned or off.223</div>224)}225</div>226<ExcludeFromSync {...props} />227<Divider />228<Ephemeral style={{ marginTop: "30px" }} {...props} />229</div>230);231}232233234