1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-22 23:09:41 +02:00

refactor(docker/containers): migrate commands tab to react [EE-5208] (#10085)

This commit is contained in:
Chaim Lev-Ari 2023-09-04 19:07:29 +01:00 committed by GitHub
parent 46e73ee524
commit f7366d9788
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
42 changed files with 1783 additions and 951 deletions

View file

@ -0,0 +1,60 @@
import { commandStringToArray } from '@/docker/helpers/containers';
import { CreateContainerRequest } from '../types';
import { Values } from './types';
import { LogConfig } from './LoggerConfig';
import { ConsoleConfig, ConsoleSetting } from './ConsoleSettings';
export function toRequest(
oldConfig: CreateContainerRequest,
values: Values
): CreateContainerRequest {
const config = {
...oldConfig,
HostConfig: {
...oldConfig.HostConfig,
LogConfig: getLogConfig(values.logConfig),
},
User: values.user,
WorkingDir: values.workingDir,
...getConsoleConfig(values.console),
};
if (values.cmd) {
config.Cmd = commandStringToArray(values.cmd);
}
if (values.entrypoint) {
config.Entrypoint = commandStringToArray(values.entrypoint);
}
return config;
function getLogConfig(
value: LogConfig
): CreateContainerRequest['HostConfig']['LogConfig'] {
return {
Type: value.type,
Config: Object.fromEntries(
value.options.map(({ option, value }) => [option, value])
),
// docker types - requires union while it should allow also custom string for custom plugins
} as CreateContainerRequest['HostConfig']['LogConfig'];
}
function getConsoleConfig(value: ConsoleSetting): ConsoleConfig {
switch (value) {
case 'both':
return { OpenStdin: true, Tty: true };
case 'interactive':
return { OpenStdin: true, Tty: false };
case 'tty':
return { OpenStdin: false, Tty: true };
case 'none':
default:
return { OpenStdin: false, Tty: false };
}
}
}