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 (#12295)
Some checks failed
ci / build_images (map[arch:amd64 platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Has been cancelled
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Has been cancelled
ci / build_images (map[arch:arm platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:arm64 platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:ppc64le platform:linux version:]) (push) Has been cancelled
/ triage (push) Has been cancelled
Lint / Run linters (push) Has been cancelled
Test / test-client (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:linux]) (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Has been cancelled
Test / test-server (map[arch:arm64 platform:linux]) (push) Has been cancelled
ci / build_manifests (push) Has been cancelled
Some checks failed
ci / build_images (map[arch:amd64 platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Has been cancelled
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Has been cancelled
ci / build_images (map[arch:arm platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:arm64 platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:ppc64le platform:linux version:]) (push) Has been cancelled
/ triage (push) Has been cancelled
Lint / Run linters (push) Has been cancelled
Test / test-client (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:linux]) (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Has been cancelled
Test / test-server (map[arch:arm64 platform:linux]) (push) Has been cancelled
ci / build_manifests (push) Has been cancelled
This commit is contained in:
parent
8cbd23c059
commit
ac5491e864
227 changed files with 4702 additions and 3411 deletions
|
@ -9,196 +9,122 @@ import {
|
|||
startContainer,
|
||||
stopContainer,
|
||||
recreateContainer,
|
||||
getContainerLogs,
|
||||
} from '@/react/docker/containers/containers.service';
|
||||
import { ContainerDetailsViewModel, ContainerStatsViewModel, ContainerViewModel } from '../models/container';
|
||||
import { getContainers } from '@/react/docker/containers/queries/useContainers';
|
||||
import { getContainer } from '@/react/docker/containers/queries/useContainer';
|
||||
import { resizeTTY } from '@/react/docker/containers/queries/useContainerResizeTTYMutation';
|
||||
import { updateContainer } from '@/react/docker/containers/queries/useUpdateContainer';
|
||||
import { createExec } from '@/react/docker/containers/queries/useCreateExecMutation';
|
||||
import { containerStats } from '@/react/docker/containers/queries/useContainerStats';
|
||||
import { containerTop } from '@/react/docker/containers/queries/useContainerTop';
|
||||
import { createOrReplace } from '@/react/docker/containers/CreateView/useCreateMutation';
|
||||
|
||||
import { ContainerDetailsViewModel } from '../models/containerDetails';
|
||||
import { ContainerStatsViewModel } from '../models/containerStats';
|
||||
import { formatLogs } from '../helpers/logHelper';
|
||||
|
||||
angular.module('portainer.docker').factory('ContainerService', ContainerServiceFactory);
|
||||
|
||||
/* @ngInject */
|
||||
function ContainerServiceFactory($q, Container, $timeout) {
|
||||
const service = {
|
||||
killContainer,
|
||||
pauseContainer,
|
||||
renameContainer,
|
||||
restartContainer,
|
||||
resumeContainer,
|
||||
startContainer,
|
||||
stopContainer,
|
||||
recreateContainer,
|
||||
remove: removeContainer,
|
||||
updateRestartPolicy,
|
||||
updateLimits,
|
||||
function ContainerServiceFactory(AngularToReact) {
|
||||
const { useAxios } = AngularToReact;
|
||||
|
||||
return {
|
||||
killContainer: useAxios(killContainer), // container edit
|
||||
pauseContainer: useAxios(pauseContainer), // container edit
|
||||
renameContainer: useAxios(renameContainer), // container edit
|
||||
restartContainer: useAxios(restartContainer), // container edit
|
||||
resumeContainer: useAxios(resumeContainer), // container edit
|
||||
startContainer: useAxios(startContainer), // container edit
|
||||
stopContainer: useAxios(stopContainer), // container edit
|
||||
recreateContainer: useAxios(recreateContainer), // container edit
|
||||
remove: useAxios(removeContainer), // container edit
|
||||
container: useAxios(getContainerAngularJS), // container console + container edit + container stats
|
||||
containers: useAxios(getContainers), // dashboard + services list + service edit + voluem edit + stackservice + stack create + stack edit
|
||||
resizeTTY: useAxios(resizeTTYAngularJS), // container console
|
||||
updateRestartPolicy: useAxios(updateRestartPolicyAngularJS), // container edit
|
||||
createExec: useAxios(createExec), // container console
|
||||
containerStats: useAxios(containerStatsAngularJS), // container stats
|
||||
containerTop: useAxios(containerTop), // container stats
|
||||
inspect: useAxios(getContainer), // container inspect
|
||||
createAndStartContainer: useAxios(createAndStartContainer), // templates
|
||||
logs: useAxios(containerLogsAngularJS), // container logs
|
||||
};
|
||||
|
||||
service.container = function (environmentId, id) {
|
||||
var deferred = $q.defer();
|
||||
|
||||
Container.get({ environmentId, id })
|
||||
.$promise.then(function success(data) {
|
||||
var container = new ContainerDetailsViewModel(data);
|
||||
deferred.resolve(container);
|
||||
})
|
||||
.catch(function error(err) {
|
||||
deferred.reject({ msg: 'Unable to retrieve container information', err: err });
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
service.containers = function (environmentId, all, filters) {
|
||||
var deferred = $q.defer();
|
||||
Container.query({ environmentId, all, filters })
|
||||
.$promise.then(function success(data) {
|
||||
var containers = data.map(function (item) {
|
||||
return new ContainerViewModel(item);
|
||||
});
|
||||
deferred.resolve(containers);
|
||||
})
|
||||
.catch(function error(err) {
|
||||
deferred.reject({ msg: 'Unable to retrieve containers', err: err });
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
service.resizeTTY = function (environmentId, id, width, height, timeout) {
|
||||
var deferred = $q.defer();
|
||||
|
||||
$timeout(function () {
|
||||
Container.resize({}, { environmentId, id, width, height })
|
||||
.$promise.then(function success(data) {
|
||||
if (data.message) {
|
||||
deferred.reject({ msg: 'Unable to resize tty of container ' + id, err: data.message });
|
||||
} else {
|
||||
deferred.resolve(data);
|
||||
}
|
||||
})
|
||||
.catch(function error(err) {
|
||||
deferred.reject({ msg: 'Unable to resize tty of container ' + id, err: err });
|
||||
});
|
||||
}, timeout);
|
||||
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
function updateRestartPolicy(environmentId, id, restartPolicy, maximumRetryCounts) {
|
||||
return Container.update({ environmentId, id }, { RestartPolicy: { Name: restartPolicy, MaximumRetryCount: maximumRetryCounts } }).$promise;
|
||||
/**
|
||||
* @param {EnvironmentId} environmentId
|
||||
* @param {ContainerId} id
|
||||
* @param {*} param2
|
||||
*/
|
||||
async function getContainerAngularJS(environmentId, id, { nodeName } = {}) {
|
||||
const data = await getContainer(environmentId, id, { nodeName });
|
||||
return new ContainerDetailsViewModel(data);
|
||||
}
|
||||
|
||||
function updateLimits(environmentId, id, config) {
|
||||
return Container.update(
|
||||
{ environmentId, id },
|
||||
{
|
||||
// MemorySwap: must be set
|
||||
// -1: non limits, 0: treated as unset(cause update error).
|
||||
MemoryReservation: config.HostConfig.MemoryReservation,
|
||||
Memory: config.HostConfig.Memory,
|
||||
MemorySwap: -1,
|
||||
NanoCpus: config.HostConfig.NanoCpus,
|
||||
}
|
||||
).$promise;
|
||||
/**
|
||||
* @param {EnvironmentId} environmentId
|
||||
* @param {string} containerId
|
||||
* @param {number} width
|
||||
* @param {number} height
|
||||
* @param timeout DEPRECATED: Previously used in pure AJS implementation
|
||||
*/
|
||||
async function resizeTTYAngularJS(environmentId, containerId, width, height) {
|
||||
return resizeTTY(environmentId, containerId, { width, height });
|
||||
}
|
||||
|
||||
service.createContainer = function (environmentId, configuration) {
|
||||
var deferred = $q.defer();
|
||||
Container.create({ environmentId }, configuration)
|
||||
.$promise.then(function success(data) {
|
||||
deferred.resolve(data);
|
||||
})
|
||||
.catch(function error(err) {
|
||||
deferred.reject({ msg: 'Unable to create container', err: err });
|
||||
});
|
||||
return deferred.promise;
|
||||
};
|
||||
/**
|
||||
* @param {EnvironmentId} environmentId
|
||||
* @param {ContainerId} id
|
||||
* @param {RestartPolicy['Name']} restartPolicy
|
||||
* @param {RestartPolicy['MaximumRetryCount']} maximumRetryCounts
|
||||
*/
|
||||
async function updateRestartPolicyAngularJS(environmentId, id, restartPolicy, maximumRetryCounts) {
|
||||
return updateContainer(environmentId, id, {
|
||||
RestartPolicy: {
|
||||
Name: restartPolicy,
|
||||
MaximumRetryCount: maximumRetryCounts,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
service.createAndStartContainer = function (environmentId, configuration) {
|
||||
var deferred = $q.defer();
|
||||
var container;
|
||||
service
|
||||
.createContainer(environmentId, configuration)
|
||||
.then(function success(data) {
|
||||
container = data;
|
||||
return service.startContainer(environmentId, container.Id);
|
||||
})
|
||||
.then(function success() {
|
||||
deferred.resolve(container);
|
||||
})
|
||||
.catch(function error(err) {
|
||||
deferred.reject(err);
|
||||
});
|
||||
return deferred.promise;
|
||||
};
|
||||
/**
|
||||
* @param {Environment} environment
|
||||
* @param {*} configuration
|
||||
*/
|
||||
async function createAndStartContainer(environment, configuration) {
|
||||
return createOrReplace({
|
||||
config: configuration,
|
||||
environment,
|
||||
});
|
||||
}
|
||||
|
||||
service.createExec = function (environmentId, execConfig) {
|
||||
var deferred = $q.defer();
|
||||
|
||||
Container.exec({ environmentId }, execConfig)
|
||||
.$promise.then(function success(data) {
|
||||
if (data.message) {
|
||||
deferred.reject({ msg: data.message, err: data.message });
|
||||
} else {
|
||||
deferred.resolve(data);
|
||||
}
|
||||
})
|
||||
.catch(function error(err) {
|
||||
deferred.reject(err);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
service.logs = function (environmentId, id, stdout, stderr, timestamps, since, tail, stripHeaders) {
|
||||
var deferred = $q.defer();
|
||||
|
||||
var parameters = {
|
||||
id: id,
|
||||
stdout: stdout || 0,
|
||||
stderr: stderr || 0,
|
||||
timestamps: timestamps || 0,
|
||||
since: since || 0,
|
||||
tail: tail || 'all',
|
||||
environmentId,
|
||||
};
|
||||
|
||||
Container.logs(parameters)
|
||||
.$promise.then(function success(data) {
|
||||
var logs = formatLogs(data.logs, { stripHeaders, withTimestamps: !!timestamps });
|
||||
deferred.resolve(logs);
|
||||
})
|
||||
.catch(function error(err) {
|
||||
deferred.reject(err);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
service.containerStats = function (environmentId, id) {
|
||||
var deferred = $q.defer();
|
||||
|
||||
Container.stats({ environmentId, id })
|
||||
.$promise.then(function success(data) {
|
||||
var containerStats = new ContainerStatsViewModel(data);
|
||||
deferred.resolve(containerStats);
|
||||
})
|
||||
.catch(function error(err) {
|
||||
deferred.reject(err);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
service.containerTop = function (environmentId, id) {
|
||||
return Container.top({ environmentId, id }).$promise;
|
||||
};
|
||||
|
||||
service.inspect = function (environmentId, id) {
|
||||
return Container.inspect({ environmentId, id }).$promise;
|
||||
};
|
||||
|
||||
service.prune = function (environmentId, filters) {
|
||||
return Container.prune({ environmentId, filters }).$promise;
|
||||
};
|
||||
|
||||
return service;
|
||||
/**
|
||||
* @param {EnvironmentId} environmentId
|
||||
* @param {ContainerId} id
|
||||
*/
|
||||
async function containerStatsAngularJS(environmentId, id) {
|
||||
const data = await containerStats(environmentId, id);
|
||||
return new ContainerStatsViewModel(data);
|
||||
}
|
||||
/**
|
||||
* @param {EnvironmentId} environmentId
|
||||
* @param {Containerid} id
|
||||
* @param {boolean?} stdout
|
||||
* @param {boolean?} stderr
|
||||
* @param {boolean?} timestamps
|
||||
* @param {number?} since
|
||||
* @param {number?} tail
|
||||
* @param {boolean?} stripHeaders
|
||||
*/
|
||||
async function containerLogsAngularJS(environmentId, id, stdout = false, stderr = false, timestamps = false, since = 0, tail = 'all', stripHeaders) {
|
||||
const data = await getContainerLogs(environmentId, id, {
|
||||
since,
|
||||
stderr,
|
||||
stdout,
|
||||
tail,
|
||||
timestamps,
|
||||
});
|
||||
return formatLogs(data, { stripHeaders, withTimestamps: !!timestamps });
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue