feat: changeWorkdir option for docker

This commit is contained in:
YuMao 2024-11-27 14:35:48 +08:00
parent 0bd617d5ed
commit 137808048d
8 changed files with 76 additions and 37 deletions

1
common/global.d.ts vendored
View File

@ -74,6 +74,7 @@ export interface IGlobalInstanceDockerConfig {
cpuUsage?: number;
workingDir?: string;
env?: string[];
changeWorkdir?: boolean;
}
export interface IPanelResponseProtocol {

View File

@ -66,7 +66,8 @@ export default class InstanceConfig implements IGlobalInstanceConfig {
io: 0,
network: 0,
workingDir: "/workspace/",
env: []
env: [],
changeWorkdir: false
};
public pingConfig = {

View File

@ -209,6 +209,7 @@ export default class Instance extends EventEmitter {
configureEntityParams(this.config.docker, cfg.docker, "cpuUsage", Number);
configureEntityParams(this.config.docker, cfg.docker, "env");
configureEntityParams(this.config.docker, cfg.docker, "workingDir", String);
configureEntityParams(this.config.docker, cfg.docker, "changeWorkdir", Boolean);
}
if (cfg.pingConfig) {
configureEntityParams(this.config.pingConfig, cfg.pingConfig, "ip", String);

View File

@ -175,7 +175,7 @@ export class SetupDockerContainer extends AsyncTask {
AttachStdout: true,
AttachStderr: true,
Tty: isTty,
WorkingDir: workingDir,
WorkingDir: instance.config.docker.changeWorkdir ? workingDir : undefined,
Cmd: commandList.length > 0 ? commandList : undefined,
OpenStdin: true,
StdinOnce: false,

View File

@ -16,6 +16,7 @@ interface Props extends MountComponent {
data: any[];
subTitle?: string;
columns?: AntColumnsType[];
textarea?: boolean;
}
const props = defineProps<Props>();
@ -92,7 +93,7 @@ const operation = (type: "add" | "del", index = 0) => {
<a-modal
v-model:open="open"
centered
width="600px"
width="1300px"
:mask-closable="false"
:title="props.title"
:ok-text="t('TXT_CODE_d507abff')"
@ -135,7 +136,15 @@ const operation = (type: "add" | "del", index = 0) => {
}
]"
>
<a-textarea
v-if="props.textarea"
v-model:value="record[String(column.dataIndex)]"
:placeholder="(column as any).placeholder"
:rows="3"
:auto-size="false"
/>
<a-input
v-else
v-model:value="record[String(column.dataIndex)]"
:placeholder="(column as any).placeholder"
/>

View File

@ -80,7 +80,8 @@ export async function usePortEditDialog(data: PortConfigItem[] = []) {
title: t("TXT_CODE_ad1c674c"),
placeholder: "tcp/udp"
}
] as AntColumnsType[]
] as AntColumnsType[],
textarea: false
}).mount<PortConfigItem[]>(KvOptionsDialogVue)) || []
);
}
@ -102,7 +103,8 @@ export async function useVolumeEditDialog(data: DockerConfigItem[] = []) {
dataIndex: "container",
title: t("TXT_CODE_30258325")
}
] as AntColumnsType[]
] as AntColumnsType[],
textarea: true
}).mount<DockerConfigItem[]>(KvOptionsDialogVue)) || []
);
}
@ -123,7 +125,8 @@ export async function useDockerEnvEditDialog(data: DockerEnvItem[] = []) {
dataIndex: "value",
title: t("TXT_CODE_115e8a25")
}
] as AntColumnsType[]
] as AntColumnsType[],
textarea: true
}).mount<DockerEnvItem[]>(KvOptionsDialogVue)) || []
);
}

View File

@ -134,7 +134,7 @@ defineExpose({
:cancel-text="t('TXT_CODE_3b1cc020')"
:ok-text="t('TXT_CODE_abfe9512')"
:mask-closable="false"
:width="fullScreen ? '100%' : '1300px'"
:width="fullScreen ? '100%' : '1600px'"
:confirm-loading="isLoading"
@ok="submit"
@cancel="cancel"

View File

@ -227,10 +227,6 @@ const encodeFormData = () => {
throw new Error("Ref Options is null");
};
const openCmdAssistDialog = async () => {
const cmd = await useCmdAssistantDialog();
if (options.value && cmd) options.value.config.startCommand = cmd;
};
const handleEditDockerConfig = async (type: "port" | "volume" | "env") => {
if (type === "port" && options.value?.config) {
// "25565:25565/tcp 8080:8080/tcp" -> Array
@ -277,7 +273,7 @@ defineExpose({
v-model:open="open"
centered
:mask-closable="false"
:width="isPhone ? '100%' : 'calc(100% - 30vw)'"
:width="isPhone ? '100%' : '1600px'"
:title="t('TXT_CODE_aac98b2a')"
:confirm-loading="isLoading"
:ok-text="t('TXT_CODE_abfe9512')"
@ -381,10 +377,12 @@ defineExpose({
v-model:value="options.config.startCommand"
:rows="5"
style="min-height: 40px"
:placeholder="
options.config.docker.image
? t('留空将使用 Docker 镜像自带命令启动')
: t('请填写启动命令')
"
/>
<a-button type="default" style="height: auto" @click="openCmdAssistDialog">
{{ t("TXT_CODE_2728d0d4") }}
</a-button>
</a-input-group>
</a-form-item>
</a-col>
@ -466,7 +464,7 @@ defineExpose({
</div>
</a-form-item>
</a-col>
<a-col v-if="options.imageSelectMethod === 'SELECT'" :xs="24" :lg="8" :offset="0">
<a-col v-if="options.imageSelectMethod === 'SELECT'" :xs="24" :lg="16" :offset="0">
<a-form-item :name="['docker', 'image']">
<a-typography-title :level="5" :class="{ 'require-field': isDocker }">
{{ t("TXT_CODE_6904cb3") }}
@ -508,30 +506,16 @@ defineExpose({
</a-form-item>
</a-col>
<a-col :xs="24" :lg="8" :offset="0">
<a-form-item>
<a-typography-title :level="5">{{ t("TXT_CODE_c3a3b6b1") }}</a-typography-title>
<a-typography-paragraph>
<a-typography-text type="secondary" :class="!isPhone && 'two-line-height'">
{{ t("TXT_CODE_d1c78fbf") }}
</a-typography-text>
</a-typography-paragraph>
<a-tooltip placement="bottom">
<template #title>{{ t("TXT_CODE_8d4882b0") }}</template>
<a-input
v-model:value="options.config.docker.containerName"
:placeholder="t('TXT_CODE_f6047384')"
/>
</a-tooltip>
</a-form-item>
</a-col>
<a-col :xs="24" :lg="16" :offset="0">
<a-form-item>
<a-typography-title :level="5">{{ t("TXT_CODE_9c247f6") }}</a-typography-title>
<a-typography-title :level="5">{{ t("挂载文件管理中的文件") }}</a-typography-title>
<a-typography-paragraph>
<a-typography-text type="secondary">
{{ t("TXT_CODE_df3fdec") }}
<a-typography-text type="secondary" :class="!isPhone && 'two-line-height'">
{{
t(
"填写一个容器内的文件路径,设置后,文件管理中的所有文件将挂载到填写的路径中。"
)
}}
</a-typography-text>
</a-typography-paragraph>
<a-input
@ -541,6 +525,28 @@ defineExpose({
</a-form-item>
</a-col>
<a-col :xs="24" :lg="8" :offset="0">
<a-form-item name="changeWorkdir">
<a-typography-title :level="5" :class="{ 'require-field': isDocker }">
{{ t("自动切换工作路径") }}
</a-typography-title>
<a-typography-paragraph>
<a-typography-text type="secondary" :class="!isPhone && 'two-line-height'">
{{ t("启动容器时,自动将当前目录切换到工作目录,某些情况下可能需要这类功能") }}
</a-typography-text>
</a-typography-paragraph>
<a-switch
v-model:checked="options.config.docker.changeWorkdir"
:disabled="isGlobalTerminal"
checked-value="docker"
un-checked-value="general"
>
<template #checkedChildren><check-outlined /></template>
<template #unCheckedChildren><close-outlined /></template>
</a-switch>
</a-form-item>
</a-col>
<a-col :xs="24" :lg="8" :offset="0">
<a-form-item :name="['docker', 'networkMode']">
<a-typography-title :level="5" :class="{ 'require-field': isDocker }">
@ -681,6 +687,24 @@ defineExpose({
/>
</a-form-item>
</a-col>
<a-col :xs="24" :lg="8" :offset="0">
<a-form-item>
<a-typography-title :level="5">{{ t("TXT_CODE_c3a3b6b1") }}</a-typography-title>
<a-typography-paragraph>
<a-typography-text type="secondary">
{{ t("TXT_CODE_d1c78fbf") }}
</a-typography-text>
</a-typography-paragraph>
<a-tooltip placement="bottom">
<template #title>{{ t("TXT_CODE_8d4882b0") }}</template>
<a-input
v-model:value="options.config.docker.containerName"
:placeholder="t('TXT_CODE_f6047384')"
/>
</a-tooltip>
</a-form-item>
</a-col>
</a-row>
</a-form>
</div>