Stream to make the builder image smaller

This avoids storing a Docker image tarball in the image. Instead,
stream the layers while doing `docker run`.
This commit is contained in:
Daniël de Kok 2024-09-29 12:35:56 +02:00
parent 755361b932
commit b806a856c7
3 changed files with 33 additions and 15 deletions

View File

@ -1,8 +1,7 @@
# Build the image and get out the docker file:
#
# docker build -t tgi-nix -f Dockerfile.nix
# docker run --rm --volume $PWD/data:/data tgi-nix cp -H result /data/tgi-docker.tar.gz
# docker load < tgi-docker.tar.gz
# docker build -t tgi-nix-builder -f Dockerfile.nix
# docker run tgi-nix-builder | docker load
FROM nixos/nix:2.18.8
RUN echo "experimental-features = nix-command flakes" >> /etc/nix/nix.conf
@ -10,4 +9,5 @@ RUN nix profile install nixpkgs#cachix
RUN cachix use text-generation-inference
WORKDIR /root
ADD . .
RUN nix build .#dockerImage
RUN nix build .#dockerImageStreamed
ENTRYPOINT ./result

View File

@ -153,18 +153,13 @@
'';
};
dockerImage = pkgs.dockerTools.buildLayeredImage {
name = "tgi-docker";
tag = "latest";
config = {
EntryPoint = [ "${default}/bin/text-generation-inference" ];
Env = [
"HF_HOME=/data"
"PORT=80"
];
dockerImage = pkgs.callPackage nix/docker.nix {
text-generation-inference = default;
};
contents = [ pkgs.cacert ];
dockerImageStreamed = pkgs.callPackage nix/docker.nix {
text-generation-inference = default;
stream = true;
};
};
}

23
nix/docker.nix Normal file
View File

@ -0,0 +1,23 @@
{
dockerTools,
cacert,
text-generation-inference,
stream ? false,
}:
let
build = if stream then dockerTools.streamLayeredImage else dockerTools.buildLayeredImage;
in
build {
name = "tgi-docker";
tag = "latest";
config = {
EntryPoint = [ "${text-generation-inference}/bin/text-generation-inference" ];
Env = [
"HF_HOME=/data"
"PORT=80"
];
};
contents = [ cacert ];
}