From ae4373b6c8ab51bec6a3cd380566fd8cc7d0efe9 Mon Sep 17 00:00:00 2001 From: Julien DIOT Date: Fri, 6 Dec 2024 10:59:03 +0900 Subject: [PATCH] optimize(docker): get plantBreedGame in its own layer --- nix_package/image.nix | 76 +++++++++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 31 deletions(-) diff --git a/nix_package/image.nix b/nix_package/image.nix index 959efd0..8aed953 100644 --- a/nix_package/image.nix +++ b/nix_package/image.nix @@ -1,17 +1,17 @@ +{ nix2containerPkgs, pkgs }: { - nix2containerPkgs, - pkgs, -}: { - builder = { - imageName ? null, - plantBreedGame ? null, - tag ? "latest", - }: let - setTimezone = pkgs.runCommand "setTimezone" {} '' - mkdir -p $out/etc - ln -s ${pkgs.tzdata}/share/zoneinfo/Asia/Tokyo $out/etc/localtime - ''; - in + builder = + { + imageName ? null, + plantBreedGame ? null, + tag ? "latest", + }: + let + setTimezone = pkgs.runCommand "setTimezone" { } '' + mkdir -p $out/etc + ln -s ${pkgs.tzdata}/share/zoneinfo/Asia/Tokyo $out/etc/localtime + ''; + in nix2containerPkgs.nix2container.buildImage { name = imageName; tag = tag; @@ -24,38 +24,52 @@ deps = plantBreedGame.buildInput; maxLayers = 90; }) - # plantBreedGame layer - (nix2containerPkgs.nix2container.buildLayer { - deps = plantBreedGame.buildInput; - }) ]; copyToRoot = [ (pkgs.buildEnv { name = "root"; - paths = with pkgs; - with pkgs.dockerTools; [ - plantBreedGame - setTimezone + paths = + with pkgs; + with pkgs.dockerTools; + [ + plantBreedGame + setTimezone - fakeNss - tzdata + fakeNss + tzdata - bashInteractive - coreutils - usrBinEnv - binSh - ]; + bashInteractive + coreutils + usrBinEnv + binSh + ]; ignoreCollisions = false; - pathsToLink = ["/bin" "/var" "/run" "/tmp" "/etc" "/share"]; + pathsToLink = [ + "/bin" + "/var" + "/run" + "/tmp" + "/etc" + "/share" + ]; }) ]; config = { WorkingDir = "/"; - Run = ["touch" "/toto.txt"]; + Run = [ + "touch" + "/toto.txt" + ]; Volume = "/var/lib/plantBreedGame"; - Cmd = ["${plantBreedGame}/bin/plantBreedGame" "--host" "0.0.0.0" "--port" "3838"]; + Cmd = [ + "${plantBreedGame}/bin/plantBreedGame" + "--host" + "0.0.0.0" + "--port" + "3838" + ]; Expose = 3838; }; };