Skip to content

Commit

Permalink
build(nix): add network image
Browse files Browse the repository at this point in the history
  • Loading branch information
nialov committed Feb 5, 2025
1 parent f0c07ea commit 8a97d11
Showing 1 changed file with 68 additions and 22 deletions.
90 changes: 68 additions & 22 deletions nix/per-system.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@
(final: prev:

let
imageConfig = {
name = "fractopo-validation";
mkImageConfig = { name, entrypoint }: {
inherit name;
config = {
Entrypoint = [
"${final.fractopo-validation-run}/bin/fractopo-validation-run"
];
Entrypoint = [ entrypoint ];
Cmd = [
"--host"
"0.0.0.0"
Expand All @@ -28,6 +26,25 @@
];
};
};
validationImageConfig = mkImageConfig {
name = "fractopo-validation";
entrypoint =
"${final.fractopo-validation-run}/bin/fractopo-validation-run";
};
networkImageConfig = mkImageConfig {
name = "fractopo-network";
entrypoint =
"${final.fractopo-network-run}/bin/fractopo-network-run";
};
mkMarimoRun = { name, scriptPath }:
prev.writeShellApplication {
inherit name;
runtimeInputs = [ final.fractopoEnv ];
text = ''
marimo run ${scriptPath} "$@"
'';

};

in {
pythonPackagesExtensions = prev.pythonPackagesExtensions ++ [
Expand All @@ -51,40 +68,68 @@
# TODO: Should check.
[ p.fractopo.passthru.no-check ]
++ p.fractopo.passthru.optional-dependencies.dev);
fractopo-validation-run = prev.writeShellApplication {
fractopo-validation-run = mkMarimoRun {
name = "fractopo-validation-run";
runtimeInputs = [ final.fractopoEnv ];
text = ''
marimo run ${./../marimos/validation.py} "$@"
'';
scriptPath = ./../marimos/validation.py;
};

fractopo-network-run = mkMarimoRun {
name = "fractopo-network-run";
scriptPath = ./../marimos/network.py;

};

fractopo-validation-image =
pkgs.dockerTools.buildLayeredImage imageConfig;
pkgs.dockerTools.buildLayeredImage validationImageConfig;
fractopo-validation-image-stream =
pkgs.dockerTools.streamLayeredImage imageConfig;
push-fractopo-validation-image = prev.writeShellApplication {
name = "push-fractopo-validation-image";
pkgs.dockerTools.streamLayeredImage validationImageConfig;

fractopo-network-image =
pkgs.dockerTools.buildLayeredImage networkImageConfig;
fractopo-network-image-stream =
pkgs.dockerTools.streamLayeredImage networkImageConfig;
push-fractopo-fractopo-images = prev.writeShellApplication {
name = "push-fractopo-images";
text = let

inherit (final.fractopo-validation-image-stream)
imageName imageTag;
streams = [
final.fractopo-validation-image-stream
final.fractopo-network-image-stream
];

mkLoadCmd = stream: "${stream} | docker load";
loadCmds = builtins.map mkLoadCmd streams;

mkTagCmd = { imageName, imageTag }:
''
docker tag ${imageName}:${imageTag} "$1"/"$2"/${imageName}:latest'';

tagCmds = builtins.map (stream:
mkTagCmd { inherit (stream) imageName imageTag; })
streams;

mkPushCmd = imageName:
''docker push "$1"/"$2"/${imageName}:latest'';

pushCmds =
builtins.map (stream: mkPushCmd stream.imageName)
streams;

in ''
echo "Logging in to $1"
docker login -p "$3" -u unused "$1"
echo "Loading new version of fractopo validation image into docker"
${final.fractopo-validation-image-stream} | docker load
echo "Loading new version of fractopo images into docker"
${lib.concatStringsSep "\n" loadCmds}
echo "Listing images"
docker image list
echo "Tagging new image version to project $2 in $1"
docker tag ${imageName}:${imageTag} "$1"/"$2"/${imageName}:latest
echo "Tagging new image versions to project $2 in $1"
${lib.concatStringsSep "\n" tagCmds}
echo "Pushing new image version to project $2 in $1"
docker push "$1"/"$2"/${imageName}:latest
echo "Pushing new image versions to project $2 in $1"
${lib.concatStringsSep "\n" pushCmds}
'';
};
cut-release-changelog = prev.writeShellApplication {
Expand All @@ -109,6 +154,7 @@
packages = devShellPackages;
shellHook = config.pre-commit.installationScript + ''
export PROJECT_DIR="$PWD"
export PYTHONPATH="$PWD":"$PYTHONPATH"
'';
};

Expand Down

0 comments on commit 8a97d11

Please sign in to comment.