mirror of
https://github.com/portainer/portainer.git
synced 2025-07-25 00:09:40 +02:00
feat(app): limit the docker API version supported by the frontend (#11855)
Some checks are pending
ci / build_images (map[arch:amd64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
ci / build_images (map[arch:arm platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:arm64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:ppc64le platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:s390x platform:linux version:]) (push) Waiting to run
ci / build_manifests (push) Blocked by required conditions
/ triage (push) Waiting to run
Lint / Run linters (push) Waiting to run
Test / test-client (push) Waiting to run
Test / test-server (map[arch:amd64 platform:linux]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
Test / test-server (map[arch:arm64 platform:linux]) (push) Waiting to run
Some checks are pending
ci / build_images (map[arch:amd64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
ci / build_images (map[arch:arm platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:arm64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:ppc64le platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:s390x platform:linux version:]) (push) Waiting to run
ci / build_manifests (push) Blocked by required conditions
/ triage (push) Waiting to run
Lint / Run linters (push) Waiting to run
Test / test-client (push) Waiting to run
Test / test-server (map[arch:amd64 platform:linux]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
Test / test-server (map[arch:arm64 platform:linux]) (push) Waiting to run
This commit is contained in:
parent
4ba16f1b04
commit
6a8e6734f3
212 changed files with 4439 additions and 3281 deletions
|
@ -7,22 +7,22 @@ import {
|
|||
MountPoint,
|
||||
NetworkSettings,
|
||||
} from 'docker-types/generated/1.41';
|
||||
import { RawAxiosRequestHeaders } from 'axios';
|
||||
|
||||
import { PortainerResponse } from '@/react/docker/types';
|
||||
import axios, {
|
||||
agentTargetHeader,
|
||||
parseAxiosError,
|
||||
} from '@/portainer/services/axios';
|
||||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
import { ContainerId } from '@/react/docker/containers/types';
|
||||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
import { queryClient } from '@/react-tools/react-query';
|
||||
|
||||
import { urlBuilder } from '../containers.service';
|
||||
import { buildDockerProxyUrl } from '../../proxy/queries/buildDockerProxyUrl';
|
||||
import { withAgentTargetHeader } from '../../proxy/queries/utils';
|
||||
|
||||
import { queryKeys } from './query-keys';
|
||||
|
||||
export interface ContainerJSON {
|
||||
/**
|
||||
* Raw Docker Container Details response
|
||||
*/
|
||||
export interface ContainerDetailsJSON {
|
||||
/**
|
||||
* The ID of the container
|
||||
*/
|
||||
|
@ -86,7 +86,7 @@ export function useContainer(
|
|||
containerId ? queryKeys.container(environmentId, containerId) : [],
|
||||
() =>
|
||||
containerId
|
||||
? getContainer(environmentId, containerId, nodeName)
|
||||
? getContainer(environmentId, containerId, { nodeName })
|
||||
: undefined,
|
||||
{
|
||||
meta: {
|
||||
|
@ -107,23 +107,28 @@ export function invalidateContainer(
|
|||
);
|
||||
}
|
||||
|
||||
export type ContainerResponse = PortainerResponse<ContainerJSON>;
|
||||
export type ContainerDetailsResponse = PortainerResponse<ContainerDetailsJSON>;
|
||||
|
||||
async function getContainer(
|
||||
/**
|
||||
* Raw docker API proxy
|
||||
* @param environmentId
|
||||
* @param id
|
||||
* @param param2
|
||||
* @returns
|
||||
*/
|
||||
export async function getContainer(
|
||||
environmentId: EnvironmentId,
|
||||
containerId: ContainerId,
|
||||
nodeName?: string
|
||||
id: ContainerId,
|
||||
{ nodeName }: { nodeName?: string } = {}
|
||||
) {
|
||||
try {
|
||||
const headers: RawAxiosRequestHeaders = {};
|
||||
|
||||
if (nodeName) {
|
||||
headers[agentTargetHeader] = nodeName;
|
||||
}
|
||||
|
||||
const { data } = await axios.get<ContainerResponse>(
|
||||
urlBuilder(environmentId, containerId, 'json'),
|
||||
{ headers }
|
||||
const { data } = await axios.get<ContainerDetailsResponse>(
|
||||
buildDockerProxyUrl(environmentId, 'containers', id, 'json'),
|
||||
{
|
||||
headers: {
|
||||
...withAgentTargetHeader(nodeName),
|
||||
},
|
||||
}
|
||||
);
|
||||
return data;
|
||||
} catch (error) {
|
|
@ -2,14 +2,13 @@ import { useQuery } from '@tanstack/react-query';
|
|||
|
||||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
import { genericHandler } from '@/docker/rest/response/handlers';
|
||||
|
||||
import { ContainerId } from '../types';
|
||||
import { urlBuilder } from '../containers.service';
|
||||
import { addNodeHeader } from '../../proxy/addNodeHeader';
|
||||
import { withAgentTargetHeader } from '../../proxy/queries/utils';
|
||||
import { buildDockerProxyUrl } from '../../proxy/queries/buildDockerProxyUrl';
|
||||
|
||||
import { queryKeys } from './query-keys';
|
||||
import { ContainerJSON } from './container';
|
||||
import { ContainerDetailsJSON } from './useContainer';
|
||||
|
||||
export function useContainerInspect(
|
||||
environmentId: EnvironmentId,
|
||||
|
@ -28,12 +27,12 @@ export async function inspectContainer(
|
|||
{ nodeName }: { nodeName?: string } = {}
|
||||
) {
|
||||
try {
|
||||
const { data } = await axios.get<ContainerJSON>(
|
||||
urlBuilder(environmentId, id, 'json'),
|
||||
{ transformResponse: genericHandler, headers: addNodeHeader(nodeName) }
|
||||
const { data } = await axios.get<ContainerDetailsJSON>(
|
||||
buildDockerProxyUrl(environmentId, 'containers', id, 'json'),
|
||||
{ headers: { ...withAgentTargetHeader(nodeName) } }
|
||||
);
|
||||
return data;
|
||||
} catch (e) {
|
||||
throw parseAxiosError(e, 'Failed starting container');
|
||||
throw parseAxiosError(e, 'Failed inspecting container');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
|
||||
import { buildDockerProxyUrl } from '../../proxy/queries/buildDockerProxyUrl';
|
||||
|
||||
/**
|
||||
* Raw docker API proxy
|
||||
* @param environmentId
|
||||
* @param id exec instance id
|
||||
*/
|
||||
export async function resizeTTY(
|
||||
environmentId: EnvironmentId,
|
||||
id: string,
|
||||
{ width, height }: { width: number; height: number }
|
||||
) {
|
||||
try {
|
||||
await axios.post(
|
||||
buildDockerProxyUrl(environmentId, 'containers', id, 'resize'),
|
||||
{},
|
||||
{
|
||||
params: { h: height, w: width },
|
||||
}
|
||||
);
|
||||
} catch (err) {
|
||||
throw parseAxiosError(err, 'Unable to resize tty of container');
|
||||
}
|
||||
}
|
136
app/react/docker/containers/queries/useContainerStats.ts
Normal file
136
app/react/docker/containers/queries/useContainerStats.ts
Normal file
|
@ -0,0 +1,136 @@
|
|||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
|
||||
import { buildDockerProxyUrl } from '../../proxy/queries/buildDockerProxyUrl';
|
||||
import { ContainerId } from '../types';
|
||||
|
||||
/**
|
||||
* This type is arbitrary and only defined based on what we use / observed from the API responses.
|
||||
*/
|
||||
export type ContainerStats = {
|
||||
name?: string;
|
||||
id?: string;
|
||||
read?: string;
|
||||
preread?: string;
|
||||
pids_stats?: {
|
||||
current?: number;
|
||||
limit?: number;
|
||||
};
|
||||
memory_stats?: MemoryStats;
|
||||
num_procs?: number;
|
||||
precpu_stats?: CpuStats;
|
||||
cpu_stats?: CpuStats;
|
||||
networks?: Record<string, NetworkStats>;
|
||||
blkio_stats?: BlkioStats;
|
||||
storage_stats?: unknown;
|
||||
};
|
||||
|
||||
/**
|
||||
* Raw docker API proxy
|
||||
* @param environmentId
|
||||
* @param id
|
||||
* @returns
|
||||
*/
|
||||
export async function containerStats(
|
||||
environmentId: EnvironmentId,
|
||||
id: ContainerId
|
||||
) {
|
||||
try {
|
||||
const { data } = await axios.get(
|
||||
buildDockerProxyUrl(environmentId, 'containers', id, 'stats'),
|
||||
{ params: { stream: false } }
|
||||
);
|
||||
return data;
|
||||
} catch (err) {
|
||||
throw parseAxiosError(err, 'Unable to retrieve container stats');
|
||||
}
|
||||
}
|
||||
|
||||
type BlkioStats = {
|
||||
io_service_bytes_recursive?: {
|
||||
major: number;
|
||||
minor: number;
|
||||
op: string;
|
||||
value: number;
|
||||
}[];
|
||||
io_serviced_recursive?: null;
|
||||
io_queue_recursive?: null;
|
||||
io_service_time_recursive?: null;
|
||||
io_wait_time_recursive?: null;
|
||||
io_merged_recursive?: null;
|
||||
io_time_recursive?: null;
|
||||
sectors_recursive?: null;
|
||||
};
|
||||
|
||||
type NetworkStats = {
|
||||
rx_bytes?: number;
|
||||
rx_packets?: number;
|
||||
rx_errors?: number;
|
||||
rx_dropped?: number;
|
||||
tx_bytes?: number;
|
||||
tx_packets?: number;
|
||||
tx_errors?: number;
|
||||
tx_dropped?: number;
|
||||
};
|
||||
|
||||
type MemoryStats = {
|
||||
privateworkingset?: number;
|
||||
usage?: number;
|
||||
stats?: MemoryStatsStats;
|
||||
limit?: number;
|
||||
};
|
||||
|
||||
type MemoryStatsStats = {
|
||||
active_anon?: number;
|
||||
active_file?: number;
|
||||
anon?: number;
|
||||
anon_thp?: number;
|
||||
cache?: number;
|
||||
file?: number;
|
||||
file_dirty?: number;
|
||||
file_mapped?: number;
|
||||
file_writeback?: number;
|
||||
inactive_anon?: number;
|
||||
inactive_file?: number;
|
||||
kernel_stack?: number;
|
||||
pgactivate?: number;
|
||||
pgdeactivate?: number;
|
||||
pgfault?: number;
|
||||
pglazyfree?: number;
|
||||
pglazyfreed?: number;
|
||||
pgmajfault?: number;
|
||||
pgrefill?: number;
|
||||
pgscan?: number;
|
||||
pgsteal?: number;
|
||||
shmem?: number;
|
||||
slab?: number;
|
||||
slab_reclaimable?: number;
|
||||
slab_unreclaimable?: number;
|
||||
sock?: number;
|
||||
thp_collapse_alloc?: number;
|
||||
thp_fault_alloc?: number;
|
||||
unevictable?: number;
|
||||
workingset_activate?: number;
|
||||
workingset_nodereclaim?: number;
|
||||
workingset_refault?: number;
|
||||
};
|
||||
|
||||
type CpuUsage = {
|
||||
total_usage?: number;
|
||||
usage_in_kernelmode?: number;
|
||||
usage_in_usermode?: number;
|
||||
percpu_usage?: number[];
|
||||
};
|
||||
|
||||
type ThrottlingData = {
|
||||
periods?: number;
|
||||
throttled_periods?: number;
|
||||
throttled_time?: number;
|
||||
};
|
||||
|
||||
type CpuStats = {
|
||||
cpu_usage?: CpuUsage;
|
||||
system_cpu_usage?: number;
|
||||
online_cpus?: number;
|
||||
throttling_data?: ThrottlingData;
|
||||
};
|
25
app/react/docker/containers/queries/useContainerTop.ts
Normal file
25
app/react/docker/containers/queries/useContainerTop.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
|
||||
import { ContainerId } from '../types';
|
||||
import { buildDockerProxyUrl } from '../../proxy/queries/buildDockerProxyUrl';
|
||||
|
||||
/**
|
||||
* Raw docker API proxy
|
||||
* @param environmentId
|
||||
* @param id
|
||||
* @returns
|
||||
*/
|
||||
export async function containerTop(
|
||||
environmentId: EnvironmentId,
|
||||
id: ContainerId
|
||||
) {
|
||||
try {
|
||||
const { data } = await axios.get(
|
||||
buildDockerProxyUrl(environmentId, 'containers', id, 'top')
|
||||
);
|
||||
return data;
|
||||
} catch (err) {
|
||||
throw parseAxiosError(err, 'Unable to retrieve container top');
|
||||
}
|
||||
}
|
|
@ -4,11 +4,14 @@ import { EnvironmentId } from '@/react/portainer/environments/types';
|
|||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
import { withGlobalError } from '@/react-tools/react-query';
|
||||
|
||||
import { urlBuilder } from '../containers.service';
|
||||
import { DockerContainerResponse } from '../types/response';
|
||||
import { toListViewModel } from '../utils';
|
||||
import { DockerContainer } from '../types';
|
||||
import { addNodeHeader } from '../../proxy/addNodeHeader';
|
||||
import { ContainerListViewModel } from '../types';
|
||||
import { buildDockerProxyUrl } from '../../proxy/queries/buildDockerProxyUrl';
|
||||
import {
|
||||
withFiltersQueryParam,
|
||||
withAgentTargetHeader,
|
||||
} from '../../proxy/queries/utils';
|
||||
|
||||
import { Filters } from './types';
|
||||
import { queryKeys } from './query-keys';
|
||||
|
@ -19,7 +22,7 @@ interface UseContainers {
|
|||
nodeName?: string;
|
||||
}
|
||||
|
||||
export function useContainers<T = DockerContainer[]>(
|
||||
export function useContainers<T = ContainerListViewModel[]>(
|
||||
environmentId: EnvironmentId,
|
||||
{
|
||||
autoRefreshRate,
|
||||
|
@ -28,7 +31,7 @@ export function useContainers<T = DockerContainer[]>(
|
|||
...params
|
||||
}: UseContainers & {
|
||||
autoRefreshRate?: number;
|
||||
select?: (data: DockerContainer[]) => T;
|
||||
select?: (data: ContainerListViewModel[]) => T;
|
||||
enabled?: boolean;
|
||||
} = {}
|
||||
) {
|
||||
|
@ -37,26 +40,29 @@ export function useContainers<T = DockerContainer[]>(
|
|||
() => getContainers(environmentId, params),
|
||||
{
|
||||
...withGlobalError('Unable to retrieve containers'),
|
||||
refetchInterval() {
|
||||
return autoRefreshRate ?? false;
|
||||
},
|
||||
refetchInterval: autoRefreshRate ?? false,
|
||||
select,
|
||||
enabled,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch containers and transform to ContainerListViewModel
|
||||
* @param environmentId
|
||||
* @param param1
|
||||
* @returns ContainerListViewModel[]
|
||||
*/
|
||||
export async function getContainers(
|
||||
environmentId: EnvironmentId,
|
||||
{ all = true, filters, nodeName }: UseContainers = {}
|
||||
) {
|
||||
const headers = addNodeHeader(nodeName);
|
||||
try {
|
||||
const { data } = await axios.get<DockerContainerResponse[]>(
|
||||
urlBuilder(environmentId, undefined, 'json'),
|
||||
buildDockerProxyUrl(environmentId, 'containers', 'json'),
|
||||
{
|
||||
params: { all, filters: filters && JSON.stringify(filters) },
|
||||
headers,
|
||||
params: { all, ...withFiltersQueryParam(filters) },
|
||||
headers: { ...withAgentTargetHeader(nodeName) },
|
||||
}
|
||||
);
|
||||
return data.map((c) => toListViewModel(c));
|
33
app/react/docker/containers/queries/useCreateExecMutation.ts
Normal file
33
app/react/docker/containers/queries/useCreateExecMutation.ts
Normal file
|
@ -0,0 +1,33 @@
|
|||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
|
||||
import { buildDockerProxyUrl } from '../../proxy/queries/buildDockerProxyUrl';
|
||||
import { ContainerId } from '../types';
|
||||
|
||||
type ExecConfig = {
|
||||
AttachStdin: boolean; // Attach to stdin of the exec command.
|
||||
AttachStdout: boolean; // Attach to stdout of the exec command.
|
||||
AttachStderr: boolean; // Attach to stderr of the exec command.
|
||||
DetachKeys: string; // Override the key sequence for detaching a container. Format is a single character [a-Z] or ctrl-<value> where <value> is one of: a-z, @, ^, [, , or _.
|
||||
Tty: boolean; // Allocate a pseudo-TTY.
|
||||
Env: string[]; // A list of environment variables in the form ["VAR=value", ...].
|
||||
Cmd: string[]; // Command to run, as a string or array of strings.
|
||||
Privileged: boolean; // Default: false - Runs the exec process with extended privileges.
|
||||
User: string; // The user, and optionally, group to run the exec process inside the container. Format is one of: user, user:group, uid, or uid:gid.
|
||||
WorkingDir: string; // The working directory for the exec process inside the container.
|
||||
};
|
||||
export async function createExec(
|
||||
environmentId: EnvironmentId,
|
||||
id: ContainerId,
|
||||
config: ExecConfig
|
||||
) {
|
||||
try {
|
||||
const { data } = await axios.post<{ Id: string }>(
|
||||
buildDockerProxyUrl(environmentId, 'containers', id, 'exec'),
|
||||
config
|
||||
);
|
||||
return data;
|
||||
} catch (err) {
|
||||
throw parseAxiosError(err, 'Unable to create exec');
|
||||
}
|
||||
}
|
|
@ -3,8 +3,8 @@ import { Resources, RestartPolicy } from 'docker-types/generated/1.41';
|
|||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
|
||||
import { urlBuilder } from '../containers.service';
|
||||
import { addNodeHeader } from '../../proxy/addNodeHeader';
|
||||
import { withAgentTargetHeader } from '../../proxy/queries/utils';
|
||||
import { buildDockerProxyUrl } from '../../proxy/queries/buildDockerProxyUrl';
|
||||
|
||||
/**
|
||||
* UpdateConfig holds the mutable attributes of a Container.
|
||||
|
@ -12,23 +12,23 @@ import { addNodeHeader } from '../../proxy/addNodeHeader';
|
|||
*/
|
||||
interface UpdateConfig extends Resources {
|
||||
// Contains container's resources (cgroups, ulimits)
|
||||
|
||||
RestartPolicy?: RestartPolicy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Raw docker API proxy
|
||||
*/
|
||||
export async function updateContainer(
|
||||
environmentId: EnvironmentId,
|
||||
containerId: string,
|
||||
config: UpdateConfig,
|
||||
{ nodeName }: { nodeName?: string } = {}
|
||||
) {
|
||||
const headers = addNodeHeader(nodeName);
|
||||
|
||||
try {
|
||||
await axios.post<{ Warnings: string[] }>(
|
||||
urlBuilder(environmentId, containerId, 'update'),
|
||||
buildDockerProxyUrl(environmentId, 'containers', containerId, 'update'),
|
||||
config,
|
||||
{ headers }
|
||||
{ headers: { ...withAgentTargetHeader(nodeName) } }
|
||||
);
|
||||
} catch (err) {
|
||||
throw parseAxiosError(err, 'failed updating container');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue