You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
portainer/app/react/docker/images/queries/usePullImageMutation.ts

57 lines
1.3 KiB

import { RawAxiosRequestHeaders } 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: RawAxiosRequestHeaders = {
'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');
}
}