Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function pullImageIfNecessary(
docker: BuidlerDocker,
image: Image,
cachePath: string
) {
if (!(await docker.hasPulledImage(image))) {
console.log(
`Pulling Docker image ${BuidlerDocker.imageToRepoTag(image)}...`
);
await docker.pullImage(image);
console.log(`Image pulled`);
} else {
await checkForImageUpdates(docker, image, cachePath);
}
}
async function checkForImageUpdates(
docker: BuidlerDocker,
image: Image,
cachePath: string
) {
if (!(await shouldCheckForUpdates(image, cachePath))) {
return;
}
if (!(await docker.isImageUpToDate(image))) {
console.log(
`Updating Docker image ${BuidlerDocker.imageToRepoTag(image)}...`
);
await docker.pullImage(image);
console.log(`Image updated`);
}
await saveLastUpdateCheckDate(image, cachePath);
}
async function getLastUpdateCheckDate(
image: Image,
cachePath: string
): Promise {
const file = path.join(cachePath, VYPER_DOCKER_IMAGES_LAST_UPDATE_CHECK_FILE);
if (!(await fsExtra.pathExists(file))) {
return undefined;
}
const updates = await fsExtra.readJSON(file);
return updates[BuidlerDocker.imageToRepoTag(image)];
}
if (error instanceof DockerHubConnectionError) {
throw new BuidlerPluginError(
`Error connecting to Docker Hub.
Please check your internet connection.`,
error
);
}
if (error instanceof DockerServerError) {
throw new BuidlerPluginError("Docker error", error);
}
if (error instanceof ImageDoesntExistError) {
throw new BuidlerPluginError(
`Docker image ${BuidlerDocker.imageToRepoTag(
error.image
)} doesn't exist.
Make sure you chose a valid Vyper version.`
);
}
throw error;
}
}
async function saveLastUpdateCheckDate(image: Image, cachePath: string) {
let updates: { [repoTag: string]: number };
const file = path.join(cachePath, VYPER_DOCKER_IMAGES_LAST_UPDATE_CHECK_FILE);
if (!(await fsExtra.pathExists(file))) {
updates = {};
} else {
updates = await fsExtra.readJSON(file);
}
updates[BuidlerDocker.imageToRepoTag(image)] = +new Date();
await fsExtra.ensureDir(path.dirname(file));
await fsExtra.writeJSON(file, updates);
}