mirror of
https://github.com/portainer/portainer.git
synced 2025-08-04 21:35:23 +02:00
refactor(containers): migrate create view to react [EE-2307] (#9175)
This commit is contained in:
parent
bc0050a7b4
commit
d970f0e2bc
71 changed files with 2612 additions and 1399 deletions
|
@ -1,6 +1,23 @@
|
|||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
import { buildUrl as buildDockerUrl } from '@/react/docker/queries/utils/build-url';
|
||||
import { buildUrl as buildDockerProxyUrl } from '@/react/docker/proxy/queries/build-url';
|
||||
|
||||
export function buildUrl(environmentId: EnvironmentId) {
|
||||
return buildDockerUrl(environmentId, 'images');
|
||||
}
|
||||
|
||||
export function buildProxyUrl(
|
||||
environmentId: EnvironmentId,
|
||||
{ id, action }: { id?: string; action?: string } = {}
|
||||
) {
|
||||
let dockerAction = '';
|
||||
if (id) {
|
||||
dockerAction += `${id}`;
|
||||
}
|
||||
|
||||
if (action) {
|
||||
dockerAction = dockerAction ? `${dockerAction}/${action}` : action;
|
||||
}
|
||||
|
||||
return buildDockerProxyUrl(environmentId, 'images', dockerAction);
|
||||
}
|
||||
|
|
56
app/react/docker/images/queries/usePullImageMutation.ts
Normal file
56
app/react/docker/images/queries/usePullImageMutation.ts
Normal file
|
@ -0,0 +1,56 @@
|
|||
import { AxiosRequestHeaders } from 'axios';
|
||||
|
||||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
import { Registry } from '@/react/portainer/registries/types/registry';
|
||||
|
||||
import { buildImageFullURI } from '../utils';
|
||||
|
||||
import { encodeRegistryCredentials } from './encodeRegistryCredentials';
|
||||
import { buildProxyUrl } from './build-url';
|
||||
|
||||
interface PullImageOptions {
|
||||
environmentId: EnvironmentId;
|
||||
image: string;
|
||||
nodeName?: string;
|
||||
registry?: Registry;
|
||||
ignoreErrors: boolean;
|
||||
}
|
||||
|
||||
export async function pullImage({
|
||||
environmentId,
|
||||
ignoreErrors,
|
||||
image,
|
||||
nodeName,
|
||||
registry,
|
||||
}: PullImageOptions) {
|
||||
const authenticationDetails =
|
||||
registry && registry.Authentication
|
||||
? encodeRegistryCredentials(registry.Id)
|
||||
: '';
|
||||
|
||||
const imageURI = buildImageFullURI(image, registry);
|
||||
|
||||
const headers: AxiosRequestHeaders = {
|
||||
'X-Registry-Auth': authenticationDetails,
|
||||
};
|
||||
|
||||
if (nodeName) {
|
||||
headers['X-PortainerAgent-Target'] = nodeName;
|
||||
}
|
||||
|
||||
try {
|
||||
await axios.post(buildProxyUrl(environmentId, { action: 'create' }), null, {
|
||||
params: {
|
||||
fromImage: imageURI,
|
||||
},
|
||||
headers,
|
||||
});
|
||||
} catch (err) {
|
||||
if (ignoreErrors) {
|
||||
return;
|
||||
}
|
||||
|
||||
throw parseAxiosError(err as Error, 'Unable to pull image');
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue