GeezerVison is showing github.com — feat: add mirrors select on confirming installation · EM-GeekLab/LLMOne@a8aea4b
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard +20Lines changed: 20 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +/** | | 2 | + * Copyright (c) 2025 EM-GeekLab | | 3 | + * LLMOne is licensed under Mulan PSL v2. | | 4 | + * You can use this software according to the terms and conditions of the Mulan PSL v2. | | 5 | + * You may obtain a copy of Mulan PSL v2 at: | | 6 | + * http://license.coscl.org.cn/MulanPSL2 | | 7 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, | | 8 | + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, | | 9 | + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. | | 10 | + * See the Mulan PSL v2 for more details. | | 11 | + */ | | 12 | + | | 13 | +import { enableMapSet } from 'immer' | | 14 | +import { atom } from 'jotai' | | 15 | + | | 16 | +import type { InstallOptions } from '@/lib/ssh/ssh-deployer' | | 17 | + | | 18 | +enableMapSet() | | 19 | + | | 20 | +export const installConfigAtom = atom<Map<string, InstallOptions>>(new Map()) |
Collapse file Copy file name to clipboardExpand all lines: app/install-env/ssh/hooks.tsx +13-3Lines changed: 13 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 10 | 10 | * See the Mulan PSL v2 for more details. | 11 | 11 | */ | 12 | 12 |
| | 13 | +import { useCallback } from 'react' | 13 | 14 | import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query' | | 15 | +import { useAtomValue } from 'jotai/react' | 14 | 16 |
| | 17 | +import { installConfigAtom } from '@/app/install-env/ssh/atoms' | 15 | 18 | import { useGlobalStoreApi } from '@/stores' | 16 | 19 | import { useTRPC, useTRPCClient } from '@/trpc/client' | 17 | 20 |
| @@ -20,13 +23,14 @@ export function useInstallStartTrigger(): { start: () => void } { | 20 | 23 | const trpcClient = useTRPCClient() | 21 | 24 | const trpc = useTRPC() | 22 | 25 | const queryClient = useQueryClient() | | 26 | + const installConfigs = useAtomValue(installConfigAtom) | 23 | 27 |
| 24 | 28 | const { mutate: start } = useMutation({ | 25 | 29 | mutationFn: async () => { | 26 | 30 | const { finalSshHosts } = storeApi.getState() | 27 | 31 | await Promise.all( | 28 | 32 | finalSshHosts.map(async ({ ip: host }) => { | 29 | | - await trpcClient.sshDeploy.install.triggerOnce.mutate(host) | | 33 | + await trpcClient.sshDeploy.install.triggerOnce.mutate({ host, options: installConfigs.get(host) }) | 30 | 34 | }), | 31 | 35 | ) | 32 | 36 | }, | @@ -47,10 +51,11 @@ export function useInstallStartTrigger(): { start: () => void } { | 47 | 51 | export function useInstallRetryTrigger(): { retry: (host: string) => void } { | 48 | 52 | const trpc = useTRPC() | 49 | 53 | const queryClient = useQueryClient() | | 54 | + const installConfigs = useAtomValue(installConfigAtom) | 50 | 55 |
| 51 | | - const { mutate: retry } = useMutation( | | 56 | + const { mutate } = useMutation( | 52 | 57 | trpc.sshDeploy.install.triggerOnce.mutationOptions({ | 53 | | - onSuccess: (_, host) => { | | 58 | + onSuccess: (_, { host }) => { | 54 | 59 | return Promise.all([ | 55 | 60 | queryClient.resetQueries({ queryKey: trpc.sshDeploy.install.status.queryKey(host) }), | 56 | 61 | queryClient.resetQueries({ queryKey: trpc.sshDeploy.install.statusAll.queryKey() }), | @@ -59,6 +64,11 @@ export function useInstallRetryTrigger(): { retry: (host: string) => void } { | 59 | 64 | }), | 60 | 65 | ) | 61 | 66 |
| | 67 | + const retry = useCallback( | | 68 | + (host: string) => mutate({ host, options: installConfigs.get(host) }), | | 69 | + [installConfigs, mutate], | | 70 | + ) | | 71 | + | 62 | 72 | return { retry } | 63 | 73 | } | 64 | 74 |
| |
Collapse file Copy file name to clipboard +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +'use client' | | 2 | + | | 3 | +import { Provider } from 'jotai/react' | | 4 | + | | 5 | +export function JotaiProvider({ children }: { children: React.ReactNode }) { | | 6 | + return <Provider>{children}</Provider> | | 7 | +} |
Collapse file Copy file name to clipboardExpand all lines: app/install-env/ssh/ssh-hosts-confirm.tsx +73-4Lines changed: 73 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 13 | 13 | 'use client' | 14 | 14 |
| 15 | 15 | import * as React from 'react' | 16 | | -import { ReactNode } from 'react' | | 16 | +import { ComponentProps, ReactNode, useId } from 'react' | 17 | 17 | import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query' | | 18 | +import { useAtom } from 'jotai/react' | 18 | 19 | import { AlertTriangleIcon, ArrowRightIcon, CheckIcon } from 'lucide-react' | 19 | 20 | import { match } from 'ts-pattern' | 20 | 21 |
| 21 | | -import type { InstallFlag, SshDeployerInfo } from '@/lib/ssh/ssh-deployer' | | 22 | +import type { InstallFlag, InstallOptions, SshDeployerInfo } from '@/lib/ssh/ssh-deployer' | | 23 | +import { cn } from '@/lib/utils' | 22 | 24 | import { AppCardContent, AppCardFooter, AppCardSection } from '@/components/app/app-card' | 23 | 25 | import { Callout } from '@/components/base/callout' | 24 | 26 | import { NavButton } from '@/components/base/nav-button' | 25 | 27 | import { Badge } from '@/components/ui/badge' | 26 | 28 | import { Button } from '@/components/ui/button' | | 29 | +import { installConfigAtom } from '@/app/install-env/ssh/atoms' | 27 | 30 | import { useGlobalStore } from '@/stores' | 28 | 31 | import { useTRPC, useTRPCClient } from '@/trpc/client' | 29 | 32 |
| @@ -112,13 +115,17 @@ function HostConfirmList({ host }: { host: SshDeployerInfo }) { | 112 | 115 | flag={flags.updateSources} | 113 | 116 | plannedMessage="即将更新软件源镜像" | 114 | 117 | completedMessage="已更新软件源镜像" | 115 | | - /> | | 118 | + > | | 119 | + <PackageMirrorSelect host={host.host} /> | | 120 | + </HostConfirmItem> | 116 | 121 | <HostConfirmItem | 117 | 122 | flag={flags.installDependencies} | 118 | 123 | plannedMessage="即将安装基础依赖" | 119 | 124 | completedMessage="已安装基础依赖" | 120 | 125 | /> | 121 | | - <HostConfirmItem flag={flags.installDocker} plannedMessage="即将安装 Docker" completedMessage="已安装 Docker" /> | | 126 | + <HostConfirmItem flag={flags.installDocker} plannedMessage="即将安装 Docker" completedMessage="已安装 Docker"> | | 127 | + <DockerPackageMirrorSelect host={host.host} /> | | 128 | + </HostConfirmItem> | 122 | 129 | {flags.installNvidiaGpu && ( | 123 | 130 | <HostConfirmItem | 124 | 131 | flag={flags.installNvidiaGpu} | @@ -145,6 +152,68 @@ function HostConfirmList({ host }: { host: SshDeployerInfo }) { | 145 | 152 | ) | 146 | 153 | } | 147 | 154 |
| | 155 | +function PackageMirrorSelect({ host }: { host: string }) { | | 156 | + const id = useId() | | 157 | + const [options, setOptions] = useAtom(installConfigAtom) | | 158 | + const value = options.get(host)?.packageMirror || 'none' | | 159 | + const setValue = (e: React.ChangeEvent<HTMLSelectElement>) => { | | 160 | + const newMirror = e.target.value as InstallOptions['packageMirror'] | | 161 | + setOptions((prev) => { | | 162 | + const newOptions = new Map(prev) | | 163 | + const currentConfig = newOptions.get(host) || {} | | 164 | + newOptions.set(host, { ...currentConfig, packageMirror: newMirror }) | | 165 | + return newOptions | | 166 | + }) | | 167 | + } | | 168 | + | | 169 | + return ( | | 170 | + <NativeSelect id={id} name="package-mirror" value={value} onChange={setValue}> | | 171 | + <option value="none">不修改源</option> | | 172 | + <option value="mirrors.aliyun.com">阿里源</option> | | 173 | + <option value="mirrors.tencent.com">腾讯源</option> | | 174 | + <option value="mirrors.tuna.tsinghua.edu.cn">清华源</option> | | 175 | + <option value="mirrors.ustc.edu.cn">中科大源</option> | | 176 | + </NativeSelect> | | 177 | + ) | | 178 | +} | | 179 | + | | 180 | +function DockerPackageMirrorSelect({ host }: { host: string }) { | | 181 | + const id = useId() | | 182 | + const [options, setOptions] = useAtom(installConfigAtom) | | 183 | + const value = options.get(host)?.dockerPackageMirror || 'mirrors.aliyun.com/docker-ce' | | 184 | + const setValue = (e: React.ChangeEvent<HTMLSelectElement>) => { | | 185 | + const newMirror = e.target.value as InstallOptions['dockerPackageMirror'] | | 186 | + setOptions((prev) => { | | 187 | + const newOptions = new Map(prev) | | 188 | + const currentConfig = newOptions.get(host) || {} | | 189 | + newOptions.set(host, { ...currentConfig, dockerPackageMirror: newMirror }) | | 190 | + return newOptions | | 191 | + }) | | 192 | + } | | 193 | + | | 194 | + return ( | | 195 | + <NativeSelect id={id} name="docker-package-mirror" value={value} onChange={setValue}> | | 196 | + <option value="mirrors.aliyun.com/docker-ce">阿里源</option> | | 197 | + <option value="mirrors.tencent.com/docker-ce">腾讯源</option> | | 198 | + <option value="mirrors.tuna.tsinghua.edu.cn/docker-ce">清华源</option> | | 199 | + <option value="mirrors.ustc.edu.cn/docker-ce">中科大源</option> | | 200 | + <option value="download.docker.com">官方源</option> | | 201 | + </NativeSelect> | | 202 | + ) | | 203 | +} | | 204 | + | | 205 | +function NativeSelect({ className, ...props }: ComponentProps<'select'>) { | | 206 | + return ( | | 207 | + <select | | 208 | + className={cn( | | 209 | + 'shrink-0 rounded-sm border bg-background py-px text-xs shadow-xs outline-none group-data-completed:hidden hover:border-accent-foreground/25 hover:bg-accent hover:text-accent-foreground focus-visible:border-ring focus-visible:ring-[2px] focus-visible:ring-ring/50 disabled:hover:border-border disabled:hover:bg-background disabled:hover:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50 dark:disabled:hover:bg-input/30', | | 210 | + className, | | 211 | + )} | | 212 | + {...props} | | 213 | + /> | | 214 | + ) | | 215 | +} | | 216 | + | 148 | 217 | function HostConfirmItem({ | 149 | 218 | children, | 150 | 219 | customIcon, | |
Collapse file Copy file name to clipboardExpand all lines: app/install-env/ssh/ssh-page.tsx +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 14 | 14 |
| 15 | 15 | import * as React from 'react' | 16 | 16 |
| | 17 | +import { JotaiProvider } from './jotai-provider' | 17 | 18 | import { SshHostsConfirm } from './ssh-hosts-confirm' | 18 | 19 | import { SshInstallPage } from './ssh-install-page' | 19 | 20 |
| 20 | 21 | export function SshPage() { | 21 | 22 | return ( | 22 | | - <> | | 23 | + <JotaiProvider> | 23 | 24 | <SshHostsConfirm /> | 24 | 25 | <SshInstallPage /> | 25 | | - </> | | 26 | + </JotaiProvider> | 26 | 27 | ) | 27 | 28 | } |
Collapse file Copy file name to clipboardExpand all lines: lib/ssh/ssh-deployer.ts +28-23Lines changed: 28 additions & 23 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -22,7 +22,7 @@ import { logger } from '@/lib/logger' | 22 | 22 | import { messageError, wrapError } from '@/lib/utils/error' | 23 | 23 | import { SshFinalConnectionInfo } from '@/app/connect-info/schemas' | 24 | 24 |
| 25 | | -import { PackageManager } from './pm' | | 25 | +import { DockerPackageMirrors, PackageManager, PackageMirrors } from './pm' | 26 | 26 | import { MxaCtl, SystemInfo } from './ssh-controller' | 27 | 27 |
| 28 | 28 | const log = logger.child({ module: 'ssh.deployer' }) | @@ -53,6 +53,11 @@ export type InstallStepFlags = { | 53 | 53 | installNvidiaCtk?: InstallFlag | 54 | 54 | } | 55 | 55 |
| | 56 | +export type InstallOptions = { | | 57 | + packageMirror?: PackageMirrors | 'none' | | 58 | + dockerPackageMirror?: DockerPackageMirrors | | 59 | +} | | 60 | + | 56 | 61 | export type SshDeployerStatus = 'idle' | 'failed' | 'installing' | 'completed' | 57 | 62 |
| 58 | 63 | export type SshDeployerInfo = { | @@ -242,14 +247,14 @@ echo "{\ | 242 | 247 | this.ee.on('install:completed', listener) | 243 | 248 | } | 244 | 249 |
| 245 | | - async install({ onProgress }: { onProgress?: LogListener } = {}) { | | 250 | + async install({ onProgress, ...options }: { onProgress?: LogListener } & InstallOptions = {}) { | 246 | 251 | if (onProgress) { | 247 | 252 | this.onLog(onProgress) | 248 | 253 | } | 249 | 254 | this.beforeInstall() | 250 | | - await this.updateSources() | | 255 | + await this.updateSources(options.packageMirror) | 251 | 256 | await this.installDependencies() | 252 | | - await this.installDocker() | | 257 | + await this.installDocker(options.dockerPackageMirror) | 253 | 258 | if (this.installFlags.installNvidiaGpu) { | 254 | 259 | await this.installNvidiaGpu() | 255 | 260 | } | @@ -313,20 +318,20 @@ echo "{\ | 313 | 318 | } | 314 | 319 | } | 315 | 320 |
| 316 | | - private async updatePmIndex() { | 317 | | - await this.execInstallScript({ | 318 | | - script: this.pm.updateIndex(), | 319 | | - flag: this.installFlags.updateSources, | 320 | | - initLog: '更新软件包索引', | 321 | | - successLog: '软件包索引更新完成', | 322 | | - errorLog: '软件包索引更新失败', | 323 | | - errorMessage: '软件包索引更新失败,请检查网络连接或手动更新软件包索引', | 324 | | - }) | 325 | | - } | 326 | | - | 327 | | - private async updateSources() { | | 321 | + private async updateSources(mirror?: InstallOptions['packageMirror']) { | | 322 | + if (mirror === 'none') { | | 323 | + await this.execInstallScript({ | | 324 | + script: this.pm.updateIndex(), | | 325 | + flag: this.installFlags.updateSources, | | 326 | + initLog: '更新软件包索引', | | 327 | + successLog: '软件包索引更新完成', | | 328 | + errorLog: '软件包索引更新失败', | | 329 | + errorMessage: '软件包索引更新失败,请检查网络连接或手动更新软件包索引', | | 330 | + }) | | 331 | + return | | 332 | + } | 328 | 333 | await this.execInstallScript({ | 329 | | - script: this.pm.updateSources(), | | 334 | + script: this.pm.updateSources(mirror), | 330 | 335 | flag: this.installFlags.updateSources, | 331 | 336 | initLog: '更新软件源', | 332 | 337 | successLog: '软件源更新完成', | @@ -353,9 +358,9 @@ echo "{\ | 353 | 358 | }) | 354 | 359 | } | 355 | 360 |
| 356 | | - private async installDocker() { | | 361 | + private async installDocker(mirror?: InstallOptions['dockerPackageMirror']) { | 357 | 362 | await this.execInstallScript({ | 358 | | - script: this.pm.installDocker(), | | 363 | + script: this.pm.installDocker(mirror), | 359 | 364 | flag: this.installFlags.installDocker, | 360 | 365 | initLog: '安装 Docker', | 361 | 366 | successLog: 'Docker 安装完成', | @@ -508,17 +513,17 @@ export class SshDeployerManager { | 508 | 513 | return deployer | 509 | 514 | } | 510 | 515 |
| 511 | | - async installTrigger(host: string) { | | 516 | + async installTrigger(host: string, options: InstallOptions = {}) { | 512 | 517 | const deployer = this.getDeployer(host) | 513 | | - await deployer.install() | | 518 | + await deployer.install(options) | 514 | 519 | } | 515 | 520 |
| 516 | | - installStream(host: string): EventIterator<string> { | | 521 | + installStream(host: string, options: InstallOptions = {}): EventIterator<string> { | 517 | 522 | const deployer = this.getDeployer(host) | 518 | 523 | return new EventIterator<string>(({ push, stop, fail }) => { | 519 | 524 | deployer.getLogs().forEach((log) => push(log)) | 520 | 525 | deployer | 521 | | - .install({ onProgress: (data) => push(data) }) | | 526 | + .install({ onProgress: (data) => push(data), ...options }) | 522 | 527 | .then(() => stop()) | 523 | 528 | .catch((err) => fail(err)) | 524 | 529 | }) | |
Collapse file Copy file name to clipboardExpand all lines: trpc/router/ssh-deploy.ts +34-4Lines changed: 34 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 13 | 13 | import { TRPCError } from '@trpc/server' | 14 | 14 |
| 15 | 15 | import { SshDeployerManager } from '@/lib/ssh/ssh-deployer' | | 16 | +import { z } from '@/lib/zod' | 16 | 17 | import { sshHostsListSchema } from '@/app/connect-info/schemas' | 17 | 18 | import { baseProcedure, createRouter } from '@/trpc/init' | 18 | 19 |
| @@ -29,6 +30,35 @@ function getSshDeployerManager() { | 29 | 30 |
| 30 | 31 | const installStatusCache = new Map<string, Promise<void>>() | 31 | 32 |
| | 33 | +const triggerInputSchema = z.object({ | | 34 | + host: z.string(), | | 35 | + options: z | | 36 | + .object({ | | 37 | + packageMirror: z | | 38 | + .enum([ | | 39 | + 'none', | | 40 | + 'mirrors.aliyun.com', | | 41 | + 'mirrors.tencent.com', | | 42 | + 'mirrors.tuna.tsinghua.edu.cn', | | 43 | + 'mirrors.ustc.edu.cn', | | 44 | + ]) | | 45 | + .optional(), | | 46 | + dockerPackageMirror: z | | 47 | + .enum([ | | 48 | + 'mirrors.aliyun.com/docker-ce', | | 49 | + 'mirrors.tencent.com/docker-ce', | | 50 | + 'mirrors.tuna.tsinghua.edu.cn/docker-ce', | | 51 | + 'mirrors.ustc.edu.cn/docker-ce', | | 52 | + 'download.docker.com', | | 53 | + ]) | | 54 | + .optional(), | | 55 | + }) | | 56 | + .default({ | | 57 | + packageMirror: 'none', | | 58 | + dockerPackageMirror: 'mirrors.aliyun.com/docker-ce', | | 59 | + }), | | 60 | +}) | | 61 | + | 32 | 62 | export const sshDeployRouter = createRouter({ | 33 | 63 | deployer: { | 34 | 64 | init: baseProcedure.input(sshHostsListSchema).mutation(async ({ input }) => { | @@ -53,13 +83,13 @@ export const sshDeployRouter = createRouter({ | 53 | 83 | }), | 54 | 84 | }, | 55 | 85 | install: { | 56 | | - trigger: baseProcedure.input(inputType<string>).mutation(async ({ input: host }) => { | 57 | | - const promise = getSshDeployerManager().installTrigger(host) | | 86 | + trigger: baseProcedure.input(triggerInputSchema).mutation(async ({ input: { host, options } }) => { | | 87 | + const promise = getSshDeployerManager().installTrigger(host, options) | 58 | 88 | installStatusCache.set(host, promise) | 59 | 89 | return await promise | 60 | 90 | }), | 61 | | - triggerOnce: baseProcedure.input(inputType<string>).mutation(async ({ input: host }) => { | 62 | | - const promise = getSshDeployerManager().installTrigger(host) | | 91 | + triggerOnce: baseProcedure.input(triggerInputSchema).mutation(async ({ input: { host, options } }) => { | | 92 | + const promise = getSshDeployerManager().installTrigger(host, options) | 63 | 93 | installStatusCache.set(host, promise) | 64 | 94 | }), | 65 | 95 | status: baseProcedure.input(inputType<string>).query(async ({ input: host }) => { | |
|