mirror of
https://github.com/portainer/portainer.git
synced 2025-07-23 07:19:41 +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
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