-
-
Notifications
You must be signed in to change notification settings - Fork 164
/
pull-image.ts
30 lines (26 loc) · 1.06 KB
/
pull-image.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { DockerImageName } from "../../../docker-image-name";
import { log } from "../../../logger";
import { PullStreamParser } from "../../pull-stream-parser";
import { dockerClient } from "../../docker-client";
import { AuthConfig } from "../../types";
import { imageExists } from "./image-exists";
import Dockerode from "dockerode";
export type PullImageOptions = {
imageName: DockerImageName;
force: boolean;
authConfig?: AuthConfig;
};
export const pullImage = async (dockerode: Dockerode, options: PullImageOptions): Promise<void> => {
try {
if ((await imageExists(dockerode, options.imageName)) && !options.force) {
log.debug(`Not pulling image as it already exists: ${options.imageName}`);
return;
}
log.info(`Pulling image: ${options.imageName}`);
const stream = await dockerode.pull(options.imageName.toString(), { authconfig: options.authConfig });
await new PullStreamParser(options.imageName, log).consume(stream);
} catch (err) {
log.error(`Failed to pull image "${options.imageName}": ${err}`);
throw err;
}
};