Skip to content

Commit

Permalink
Merge pull request #3712 from terascope/caching-storage-limit-fix
Browse files Browse the repository at this point in the history
remove docker images after saving zip file
  • Loading branch information
jsnoble authored Aug 6, 2024
2 parents 42787d1 + 406ed74 commit 9f9d820
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/scripts/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@terascope/scripts",
"displayName": "Scripts",
"version": "0.83.2",
"version": "0.83.3",
"description": "A collection of terascope monorepo scripts",
"homepage": "https://github.com/terascope/teraslice/tree/master/packages/scripts#readme",
"bugs": {
Expand Down
15 changes: 14 additions & 1 deletion packages/scripts/src/helpers/scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,17 @@ export async function dockerPush(image: string): Promise<void> {
}
}

async function dockerImageRm(image: string): Promise<void> {
const subprocess = await execa.command(
`docker image rm ${image}`,
{ reject: false }
);

if (subprocess.exitCode !== 0) {
throw new Error(`Unable to remove docker image ${image}, ${subprocess.stderr}`);
}
}

/**
* Unzips and loads a Docker image from a Docker cache
* If successful the image will be deleted from the cache
Expand Down Expand Up @@ -486,7 +497,8 @@ export async function pgrep(name: string): Promise<string> {
}

/**
* Save a docker image as a tar.gz to a local directory
* Save a docker image as a tar.gz to a local directory.
* Then remove the image from docker
* @param {string} imageName Name of image to pull and save
* @param {string} imageSavePath Location where image will be saved and compressed.
* @returns void
Expand All @@ -497,6 +509,7 @@ export async function saveAndZip(imageName:string, imageSavePath: string) {
const filePath = path.join(imageSavePath, `${fileName}.tar`);
const command = `docker save ${imageName} | gzip > ${filePath}.gz`;
await execa.command(command, { shell: true });
await dockerImageRm(imageName);
}

export async function getCommitHash(): Promise<string> {
Expand Down

0 comments on commit 9f9d820

Please sign in to comment.