aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2024-03-06 12:53:26 -0500
committerJoseph Hunkeler <jhunkeler@gmail.com>2024-03-06 12:53:37 -0500
commite678623a8b01c0a24c601c1fb7fa588f14e2dc0e (patch)
tree90845cb361dc8a7c4d586f75987a287cb37b0234 /src
parent9bb22e9fc9be18ee4829a2e672ea05889dcbb224 (diff)
downloadstasis-e678623a8b01c0a24c601c1fb7fa588f14e2dc0e.tar.gz
docker_save function will pipe output of "docker save" to a compression program if requested
Diffstat (limited to 'src')
-rw-r--r--src/docker.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/docker.c b/src/docker.c
index 32c7b60..955428b 100644
--- a/src/docker.c
+++ b/src/docker.c
@@ -68,10 +68,30 @@ int docker_build(const char *dirpath, const char *args, int engine) {
return docker_exec(cmd, 0);
}
-int docker_save(const char *image, const char *destdir) {
+int docker_save(const char *image, const char *destdir, const char *compression_program) {
char cmd[PATH_MAX];
+
memset(cmd, 0, sizeof(cmd));
- sprintf(cmd, "save %s -o \"%s/%s.tar\"", image, destdir, image);
+
+ if (compression_program && strlen(compression_program)) {
+ char ext[255];
+ memset(ext, 0, sizeof(ext));
+ if (startswith(compression_program, "zstd")) {
+ strcpy(ext, "zst");
+ } else if (startswith(compression_program, "xz")) {
+ strcpy(ext, "xz");
+ } else if (startswith(compression_program, "gzip")) {
+ strcpy(ext, "gz");
+ } else if (startswith(compression_program, "bzip2")) {
+ strcpy(ext, "bz2");
+ } else {
+ strncpy(ext, compression_program, sizeof(ext) - 1);
+ }
+ sprintf(cmd, "save \"%s\" | %s > \"%s/%s.tar.%s\"", image, compression_program, destdir, image, ext);
+ } else {
+ sprintf(cmd, "save \"%s\" -o \"%s/%s.tar\"", image, destdir, image);
+
+ }
return docker_exec(cmd, 0);
}