Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove docker images after saving zip file #3712

Merged
merged 5 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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