This commit is contained in:
Girish Ramakrishnan
2024-12-14 14:05:53 +01:00
parent 5145344987
commit 0bd1aac0ef

View File

@@ -110,14 +110,16 @@ async function getAuthConfig(image) {
return autoConfig;
}
async function pullImage(manifest) {
const authConfig = await getAuthConfig(manifest.dockerImage);
async function pullImage(dockerImage) {
assert.strictEqual(typeof dockerImage, 'string');
debug(`pullImage: will pull ${manifest.dockerImage}. auth: ${authConfig ? 'yes' : 'no'}`);
const authConfig = await getAuthConfig(dockerImage);
const [error, stream] = await safe(gConnection.pull(manifest.dockerImage, { authconfig: authConfig }));
if (error && error.statusCode === 404) throw new BoxError(BoxError.NOT_FOUND, `Unable to pull image ${manifest.dockerImage}. message: ${error.message} statusCode: ${error.statusCode}`);
if (error) throw new BoxError(BoxError.DOCKER_ERROR, `Unable to pull image ${manifest.dockerImage}. Please check the network or if the image needs authentication. statusCode: ${error.statusCode}`);
debug(`pullImage: will pull ${dockerImage}. auth: ${authConfig ? 'yes' : 'no'}`);
const [error, stream] = await safe(gConnection.pull(dockerImage, { authconfig: authConfig }));
if (error && error.statusCode === 404) throw new BoxError(BoxError.NOT_FOUND, `Unable to pull image ${dockerImage}. message: ${error.message} statusCode: ${error.statusCode}`);
if (error) throw new BoxError(BoxError.DOCKER_ERROR, `Unable to pull image ${dockerImage}. Please check the network or if the image needs authentication. statusCode: ${error.statusCode}`);
return new Promise((resolve, reject) => {
// https://github.com/dotcloud/docker/issues/1074 says each status message is emitted as a chunk
@@ -128,13 +130,13 @@ async function pullImage(manifest) {
// The data.status here is useless because this is per layer as opposed to per image
if (!data.status && data.error) { // data is { errorDetail: { message: xx } , error: xx }
debug(`pullImage error ${manifest.dockerImage}: ${data.errorDetail.message}`);
debug(`pullImage error ${dockerImage}: ${data.errorDetail.message}`);
layerError = data.errorDetail;
}
});
stream.on('end', function () {
debug(`downloaded image ${manifest.dockerImage} . error: ${!!layerError}`);
debug(`downloaded image ${dockerImage} . error: ${!!layerError}`);
if (!layerError) return resolve();
@@ -142,7 +144,7 @@ async function pullImage(manifest) {
});
stream.on('error', function (error) { // this is only hit for stream error and not for some download error
debug('error pulling image %s: %o', manifest.dockerImage, error);
debug(`error pulling image ${dockerImage}: %o`, error);
reject(new BoxError(BoxError.DOCKER_ERROR, error.message));
});
});
@@ -159,7 +161,7 @@ async function downloadImage(manifest) {
if (!error && result) return; // image is already present locally
await promiseRetry({ times: 10, interval: 5000, debug, retry: (pullError) => pullError.reason !== BoxError.NOT_FOUND && pullError.reason !== BoxError.FS_ERROR }, async () => {
await pullImage(manifest);
await pullImage(manifest.dockerImage);
});
}