mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-19 08:19:15 +08:00
fix(container-command): Fix the issue of container command parsing failure. (#7200)
This commit is contained in:
parent
519c6bca66
commit
53e91a87b0
@ -678,8 +678,8 @@ const message = {
|
|||||||
containerExample: '80 or 80-88',
|
containerExample: '80 or 80-88',
|
||||||
exposePort: 'Expose port',
|
exposePort: 'Expose port',
|
||||||
exposeAll: 'Expose all',
|
exposeAll: 'Expose all',
|
||||||
cmdHelper: "e.g. 'nginx' '-g' 'daemon off;' OR nginx -g daemon off;",
|
cmdHelper: 'e.g. nginx -g "daemon off;"',
|
||||||
entrypointHelper: 'e.g. /bin/sh -c',
|
entrypointHelper: 'e.g. docker-entrypoint.sh',
|
||||||
autoRemove: 'Auto remove',
|
autoRemove: 'Auto remove',
|
||||||
cpuQuota: 'NacosCPU',
|
cpuQuota: 'NacosCPU',
|
||||||
memoryLimit: 'Memory',
|
memoryLimit: 'Memory',
|
||||||
|
@ -652,8 +652,8 @@ const message = {
|
|||||||
containerExample: '80 或者 80-88',
|
containerExample: '80 或者 80-88',
|
||||||
exposePort: '暴露端口',
|
exposePort: '暴露端口',
|
||||||
exposeAll: '暴露所有',
|
exposeAll: '暴露所有',
|
||||||
cmdHelper: "例: 'nginx' '-g' 'daemon off;' 或 nginx -g daemon off;",
|
cmdHelper: '例: nginx -g "daemon off;"',
|
||||||
entrypointHelper: '例: /bin/sh -c',
|
entrypointHelper: '例: docker-entrypoint.sh',
|
||||||
autoRemove: '容器退出後自動刪除容器',
|
autoRemove: '容器退出後自動刪除容器',
|
||||||
cpuQuota: 'CPU 限製',
|
cpuQuota: 'CPU 限製',
|
||||||
memoryLimit: '內存限製',
|
memoryLimit: '內存限製',
|
||||||
|
@ -654,8 +654,8 @@ const message = {
|
|||||||
containerExample: '80 或者 80-88',
|
containerExample: '80 或者 80-88',
|
||||||
exposePort: '暴露端口',
|
exposePort: '暴露端口',
|
||||||
exposeAll: '暴露所有',
|
exposeAll: '暴露所有',
|
||||||
cmdHelper: "例: 'nginx' '-g' 'daemon off;' 或者 nginx -g daemon off;",
|
cmdHelper: '例: nginx -g "daemon off;"',
|
||||||
entrypointHelper: '例: /bin/sh -c',
|
entrypointHelper: '例: docker-entrypoint.sh',
|
||||||
autoRemove: '容器退出后自动删除容器',
|
autoRemove: '容器退出后自动删除容器',
|
||||||
cpuQuota: 'CPU 限制',
|
cpuQuota: 'CPU 限制',
|
||||||
memoryLimit: '内存限制',
|
memoryLimit: '内存限制',
|
||||||
|
@ -357,23 +357,26 @@ const acceptParams = (params: DialogProps): void => {
|
|||||||
title.value = i18n.global.t('container.' + dialogData.value.title);
|
title.value = i18n.global.t('container.' + dialogData.value.title);
|
||||||
if (params.title === 'edit') {
|
if (params.title === 'edit') {
|
||||||
dialogData.value.rowData.memory = Number(dialogData.value.rowData.memory.toFixed(2));
|
dialogData.value.rowData.memory = Number(dialogData.value.rowData.memory.toFixed(2));
|
||||||
dialogData.value.rowData.cmd = dialogData.value.rowData.cmd || [];
|
|
||||||
let itemCmd = '';
|
let itemCmd = '';
|
||||||
for (const item of dialogData.value.rowData.cmd) {
|
for (const item of dialogData.value.rowData.cmd) {
|
||||||
itemCmd += `'${item}' `;
|
if (item.indexOf(' ') !== -1) {
|
||||||
|
itemCmd += `"${item.replaceAll('"', '\\"')}" `;
|
||||||
|
} else {
|
||||||
|
itemCmd += item + ' ';
|
||||||
}
|
}
|
||||||
dialogData.value.rowData.cmdStr = itemCmd ? itemCmd.substring(0, itemCmd.length - 1) : '';
|
}
|
||||||
|
dialogData.value.rowData.cmdStr = itemCmd.trimEnd();
|
||||||
let itemEntrypoint = '';
|
let itemEntrypoint = '';
|
||||||
if (dialogData.value.rowData?.entrypoint) {
|
|
||||||
for (const item of dialogData.value.rowData.entrypoint) {
|
for (const item of dialogData.value.rowData.entrypoint) {
|
||||||
itemEntrypoint += `'${item}' `;
|
if (item.indexOf(' ') !== -1) {
|
||||||
|
itemEntrypoint += `"${item.replaceAll('"', '\\"')}" `;
|
||||||
|
} else {
|
||||||
|
itemEntrypoint += item + ' ';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
dialogData.value.rowData.entrypointStr = itemEntrypoint.trimEnd();
|
||||||
|
|
||||||
dialogData.value.rowData.entrypointStr = itemEntrypoint
|
|
||||||
? itemEntrypoint.substring(0, itemEntrypoint.length - 1)
|
|
||||||
: '';
|
|
||||||
dialogData.value.rowData.labels = dialogData.value.rowData.labels || [];
|
dialogData.value.rowData.labels = dialogData.value.rowData.labels || [];
|
||||||
dialogData.value.rowData.env = dialogData.value.rowData.env || [];
|
dialogData.value.rowData.env = dialogData.value.rowData.env || [];
|
||||||
dialogData.value.rowData.labelsStr = dialogData.value.rowData.labels.join('\n');
|
dialogData.value.rowData.labelsStr = dialogData.value.rowData.labels.join('\n');
|
||||||
@ -501,34 +504,16 @@ const submit = async () => {
|
|||||||
}
|
}
|
||||||
dialogData.value.rowData!.cmd = [];
|
dialogData.value.rowData!.cmd = [];
|
||||||
if (dialogData.value.rowData?.cmdStr) {
|
if (dialogData.value.rowData?.cmdStr) {
|
||||||
if (dialogData.value.rowData?.cmdStr.indexOf(`'`) !== -1) {
|
let itemCmd = splitWithQuotes(dialogData.value.rowData?.cmdStr);
|
||||||
let itemCmd = dialogData.value.rowData!.cmdStr.split(`'`);
|
for (const item of itemCmd) {
|
||||||
for (const cmd of itemCmd) {
|
dialogData.value.rowData!.cmd.push(item.replace(/(?<!\\)"/g, '').replaceAll('\\"', '"'));
|
||||||
if (cmd && cmd !== ' ') {
|
|
||||||
dialogData.value.rowData!.cmd.push(cmd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let itemCmd = dialogData.value.rowData!.cmdStr.split(` `);
|
|
||||||
for (const cmd of itemCmd) {
|
|
||||||
dialogData.value.rowData!.cmd.push(cmd);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dialogData.value.rowData!.entrypoint = [];
|
dialogData.value.rowData!.entrypoint = [];
|
||||||
if (dialogData.value.rowData?.entrypointStr) {
|
if (dialogData.value.rowData?.entrypointStr) {
|
||||||
if (dialogData.value.rowData?.entrypointStr.indexOf(`'`) !== -1) {
|
let itemEntrypoint = splitWithQuotes(dialogData.value.rowData?.entrypointStr);
|
||||||
let itemEntrypoint = dialogData.value.rowData!.entrypointStr.split(`'`);
|
for (const item of itemEntrypoint) {
|
||||||
for (const entry of itemEntrypoint) {
|
dialogData.value.rowData!.entrypoint.push(item.replace(/(?<!\\)"/g, '').replaceAll('\\"', '"'));
|
||||||
if (entry && entry !== ' ') {
|
|
||||||
dialogData.value.rowData!.entrypoint.push(entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let itemEntrypoint = dialogData.value.rowData!.entrypointStr.split(` `);
|
|
||||||
for (const entry of itemEntrypoint) {
|
|
||||||
dialogData.value.rowData!.entrypoint.push(entry);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (dialogData.value.rowData!.publishAllPorts) {
|
if (dialogData.value.rowData!.publishAllPorts) {
|
||||||
@ -644,6 +629,17 @@ const isFromApp = (rowData: Container.ContainerHelper) => {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const splitWithQuotes = (str) => {
|
||||||
|
str = str.replace(/\\"/g, '<quota>');
|
||||||
|
const regex = /(?=(?:[^'"]|['"][^'"]*['"])*$)\s+/g;
|
||||||
|
let parts = str.split(regex).filter(Boolean);
|
||||||
|
let returnList = [];
|
||||||
|
for (const item of parts) {
|
||||||
|
returnList.push(item.replaceAll('<quota>', '\\"'));
|
||||||
|
}
|
||||||
|
return returnList;
|
||||||
|
};
|
||||||
defineExpose({
|
defineExpose({
|
||||||
acceptParams,
|
acceptParams,
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user