1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-24 15:59:41 +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

This commit is contained in:
LP B 2024-06-10 20:54:31 +02:00 committed by GitHub
parent 4ba16f1b04
commit 6a8e6734f3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
212 changed files with 4439 additions and 3281 deletions

View file

@ -1,23 +1,27 @@
import _ from 'lodash';
import { EnvironmentId } from '@/react/portainer/environments/types';
import PortainerError from '@/portainer/error';
import axios, { parseAxiosError } from '@/portainer/services/axios';
import { genericHandler } from '@/docker/rest/response/handlers';
import { addNodeHeader } from '../proxy/addNodeHeader';
import { withAgentTargetHeader } from '../proxy/queries/utils';
import { buildDockerProxyUrl } from '../proxy/queries/buildDockerProxyUrl';
import { buildDockerUrl } from '../queries/utils/buildDockerUrl';
import { ContainerId } from './types';
import { ContainerId, ContainerLogsParams } from './types';
export async function startContainer(
environmentId: EnvironmentId,
id: ContainerId,
{ nodeName }: { nodeName?: string } = {}
) {
const headers = addNodeHeader(nodeName);
try {
await axios.post<void>(
urlBuilder(environmentId, id, 'start'),
buildDockerProxyUrl(environmentId, 'containers', id, 'start'),
{},
{ transformResponse: genericHandler, headers }
{
headers: { ...withAgentTargetHeader(nodeName) },
}
);
} catch (e) {
throw parseAxiosError(e, 'Failed starting container');
@ -29,9 +33,12 @@ export async function stopContainer(
id: ContainerId,
{ nodeName }: { nodeName?: string } = {}
) {
const headers = addNodeHeader(nodeName);
try {
await axios.post<void>(urlBuilder(endpointId, id, 'stop'), {}, { headers });
await axios.post<void>(
buildDockerProxyUrl(endpointId, 'containers', id, 'stop'),
{},
{ headers: { ...withAgentTargetHeader(nodeName) } }
);
} catch (e) {
throw parseAxiosError(e, 'Failed stopping container');
}
@ -43,14 +50,13 @@ export async function recreateContainer(
pullImage: boolean,
{ nodeName }: { nodeName?: string } = {}
) {
const headers = addNodeHeader(nodeName);
try {
await axios.post<void>(
`/docker/${endpointId}/containers/${id}/recreate`,
buildDockerUrl(endpointId, 'containers', id, 'recreate'),
{
PullImage: pullImage,
},
{ headers }
{ headers: { ...withAgentTargetHeader(nodeName) } }
);
} catch (e) {
throw parseAxiosError(e, 'Failed recreating container');
@ -62,12 +68,11 @@ export async function restartContainer(
id: ContainerId,
{ nodeName }: { nodeName?: string } = {}
) {
const headers = addNodeHeader(nodeName);
try {
await axios.post<void>(
urlBuilder(endpointId, id, 'restart'),
buildDockerProxyUrl(endpointId, 'containers', id, 'restart'),
{},
{ headers }
{ headers: { ...withAgentTargetHeader(nodeName) } }
);
} catch (e) {
throw parseAxiosError(e, 'Failed restarting container');
@ -79,9 +84,12 @@ export async function killContainer(
id: ContainerId,
{ nodeName }: { nodeName?: string } = {}
) {
const headers = addNodeHeader(nodeName);
try {
await axios.post<void>(urlBuilder(endpointId, id, 'kill'), {}, { headers });
await axios.post<void>(
buildDockerProxyUrl(endpointId, 'containers', id, 'kill'),
{},
{ headers: { ...withAgentTargetHeader(nodeName) } }
);
} catch (e) {
throw parseAxiosError(e, 'Failed killing container');
}
@ -92,12 +100,11 @@ export async function pauseContainer(
id: ContainerId,
{ nodeName }: { nodeName?: string } = {}
) {
const headers = addNodeHeader(nodeName);
try {
await axios.post<void>(
urlBuilder(endpointId, id, 'pause'),
buildDockerProxyUrl(endpointId, 'containers', id, 'pause'),
{},
{ headers }
{ headers: { ...withAgentTargetHeader(nodeName) } }
);
} catch (e) {
throw parseAxiosError(e, 'Failed pausing container');
@ -109,12 +116,11 @@ export async function resumeContainer(
id: ContainerId,
{ nodeName }: { nodeName?: string } = {}
) {
const headers = addNodeHeader(nodeName);
try {
await axios.post<void>(
urlBuilder(endpointId, id, 'unpause'),
buildDockerProxyUrl(endpointId, 'containers', id, 'unpause'),
{},
{ headers }
{ headers: { ...withAgentTargetHeader(nodeName) } }
);
} catch (e) {
throw parseAxiosError(e, 'Failed resuming container');
@ -127,15 +133,13 @@ export async function renameContainer(
name: string,
{ nodeName }: { nodeName?: string } = {}
) {
const headers = addNodeHeader(nodeName);
try {
await axios.post<void>(
urlBuilder(endpointId, id, 'rename'),
buildDockerProxyUrl(endpointId, 'containers', id, 'rename'),
{},
{
params: { name },
transformResponse: genericHandler,
headers,
headers: { ...withAgentTargetHeader(nodeName) },
}
);
} catch (e) {
@ -151,14 +155,12 @@ export async function removeContainer(
removeVolumes,
}: { removeVolumes?: boolean; nodeName?: string } = {}
) {
const headers = addNodeHeader(nodeName);
try {
const { data } = await axios.delete<null | { message: string }>(
urlBuilder(endpointId, containerId),
buildDockerProxyUrl(endpointId, 'containers', containerId),
{
params: { v: removeVolumes ? 1 : 0, force: true },
transformResponse: genericHandler,
headers,
headers: { ...withAgentTargetHeader(nodeName) },
}
);
@ -166,24 +168,25 @@ export async function removeContainer(
throw new PortainerError(data.message);
}
} catch (e) {
throw parseAxiosError(e, 'Failed removing container');
throw parseAxiosError(e, 'Unable to remove container');
}
}
export function urlBuilder(
endpointId: EnvironmentId,
id?: ContainerId,
action?: string
) {
let url = `/endpoints/${endpointId}/docker/containers`;
export async function getContainerLogs(
environmentId: EnvironmentId,
containerId: ContainerId,
params?: ContainerLogsParams
): Promise<string> {
try {
const { data } = await axios.get<string>(
buildDockerProxyUrl(environmentId, 'containers', containerId, 'logs'),
{
params: _.pickBy(params),
}
);
if (id) {
url += `/${id}`;
return data;
} catch (e) {
throw parseAxiosError(e, 'Unable to get container logs');
}
if (action) {
url += `/${action}`;
}
return url;
}