Skip to content

Commit

Permalink
optimize(docker): get plantBreedGame in its own layer
Browse files Browse the repository at this point in the history
  • Loading branch information
juliendiot42 committed Dec 6, 2024
1 parent fbfbc19 commit ae4373b
Showing 1 changed file with 45 additions and 31 deletions.
76 changes: 45 additions & 31 deletions nix_package/image.nix
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
};
};
Expand Down

0 comments on commit ae4373b

Please sign in to comment.