Skip to content

Commit

Permalink
build(container/images): reduce container image size
Browse files Browse the repository at this point in the history
Fixup the spdk rpath in the pre-fixup allowing for the default
fixup phase to shrink.
Split io-engine derivation into 2 outputs, to avoid pulling in all binaries.

Signed-off-by: Tiago Castro <[email protected]>
  • Loading branch information
tiagolobocastro committed Oct 5, 2023
1 parent 3fd7d55 commit fd764e6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
19 changes: 9 additions & 10 deletions nix/pkgs/images/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ let
tag = version;
created = "now";
config = { };
contents = [ busybox ];
copyToRoot = [ busybox ];
extraCommands = ''
mkdir tmp
mkdir -p var/tmp
Expand All @@ -71,12 +71,12 @@ let
'';
casperf = runCommand "casperf" { } ''
mkdir -p $out/bin
cp ${io-engine}/bin/casperf $out/bin/casperf
cp ${io-engine.out}/bin/casperf $out/bin/casperf
'';
io-engine-bins = runCommand "io-engine" { } ''
mkdir -p $out/bin
cp ${io-engine}/bin/io-engine $out/bin/io-engine
cp ${io-engine}/bin/io-engine-client $out/bin/io-engine-client
cp ${io-engine.out}/bin/io-engine $out/bin/io-engine
cp ${io-engine.out}/bin/io-engine-client $out/bin/io-engine-client
'';

mctl = writeScriptBin "mctl" ''
Expand All @@ -86,28 +86,27 @@ in
{
mayastor-io-engine = dockerTools.buildImage (ioEngineImageProps // {
name = "openebs/mayastor-io-engine";
contents = [ busybox io-engine-bins mctl ];
copyToRoot = [ busybox io-engine-bins mctl ];
});

mayastor-io-engine-dev = dockerTools.buildImage (ioEngineImageProps // {
name = "openebs/mayastor-io-engine-dev";
contents = [ busybox io-engine-dev ];
copyToRoot = [ busybox io-engine-dev ];
});

mayastor-io-engine-client = dockerTools.buildImage (ioEngineImageProps // {
name = "openebs/mayastor-io-engine-client";
contents = [ busybox io-engine ];
copyToRoot = [ busybox io-engine ];
config = { Entrypoint = [ "/bin/io-engine-client" ]; };
});

mayastor-fio-spdk = dockerTools.buildImage (clientImageProps // {
name = "openebs/mayastor-fio-spdk";
contents = clientImageProps.contents ++ [ tini fio_wrapper ];
copyToRoot = clientImageProps.copyToRoot ++ [ tini fio_wrapper ];
});

mayastor-casperf = dockerTools.buildImage (clientImageProps // {
name = "openebs/mayastor-casperf";
contents = clientImageProps.contents ++ [ tini casperf ];
config = { Entrypoint = [ "/bin/casperf" ]; };
copyToRoot = clientImageProps.copyToRoot ++ [ tini casperf ];
});
}
28 changes: 17 additions & 11 deletions nix/pkgs/io-engine/cargo-package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
, buildPackages
, targetPlatform
, versions
, systemdMinimal
, cargoBuildFlags ? [ ]
}:
let
Expand Down Expand Up @@ -73,29 +74,34 @@ let
libbsd
libnvme
libpcap
udev
systemdMinimal.dev
liburing
numactl
openssl
utillinux
openssl.dev
utillinux.dev
libunwind
];
cargoLock = {
lockFile = ../../../Cargo.lock;
};
doCheck = false;
meta = { platforms = lib.platforms.linux; };
fixupPhase = ''
preFixup = ''
mkdir $lib
mv $out/lib/* $lib/
local ms_lib_path
local new_rpath
echo "fixing rpaths in io-engine binaries to point to $out/lib"
ms_lib_path=$(echo "$out/lib" | sed 's/\//\\\//g')
new_rpath=$(patchelf --print-rpath "$out/bin/io-engine" | sed -r 's/\/build\/io-engine(\/[^:]*)+/'"$ms_lib_path"'/')
patchelf \
--set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
--set-rpath "$new_rpath" \
"$out/bin/io-engine"
echo "fixing rpaths in io-engine binaries to point to $lib"
ms_lib_path=$(echo "$lib" | sed 's/\//\\\//g')
for bin in "$out/bin/"*; do
new_rpath=$(patchelf --print-rpath "$bin" | sed -r 's/\/build\/io-engine(\/[^:]*)+/'"$ms_lib_path"'/')
patchelf \
--set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
--set-rpath "$new_rpath" \
"$bin"
done
'';
outputs = [ "out" "lib" ];
};
in
{
Expand Down

0 comments on commit fd764e6

Please sign in to comment.