From dcc5b1e3ceb120c1f75da1d4fec0a6c842bab2fd Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Mon, 31 May 2021 15:14:24 +0200 Subject: [PATCH] Test and fix that we only load images when needed --- src/haskell/lib/Arion/Images.hs | 6 +++++- tests/arion-test/default.nix | 38 +++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/haskell/lib/Arion/Images.hs b/src/haskell/lib/Arion/Images.hs index 350ac93..e2899f4 100644 --- a/src/haskell/lib/Arion/Images.hs +++ b/src/haskell/lib/Arion/Images.hs @@ -22,7 +22,11 @@ loadImages requestedImages = do loaded <- getDockerImages let - isNew i = (imageName i <> ":" <> imageTag i) `notElem` loaded + isNew i = + -- On docker, the image name is unmodified + (imageName i <> ":" <> imageTag i) `notElem` loaded + -- -- On podman, you automatically get a localhost prefix + && ("localhost/" <> imageName i <> ":" <> imageTag i) `notElem` loaded traverse_ loadImage . filter isNew $ requestedImages diff --git a/tests/arion-test/default.nix b/tests/arion-test/default.nix index e34ff93..3d05648 100644 --- a/tests/arion-test/default.nix +++ b/tests/arion-test/default.nix @@ -70,6 +70,44 @@ in ) machine.wait_until_fails("curl --fail localhost:8000") + # Tests + # - running same image again doesn't require a `docker load` + with subtest("docker load only once"): + # We assume image loading relies on the `docker images` and `docker load` commands, so this should fail + machine.fail( + "export REAL_DOCKER=$(which docker); rm -rf work && cp -frT ${../../examples/minimal} work && cd work && NIX_PATH=nixpkgs='${pkgs.path}' PATH=\"${pkgs.writeScriptBin "docker" '' + #!${pkgs.runtimeShell} -eu + echo 1>&2 "This failure is expected. Args were" "$@" + echo "$@" >/tmp/docker-args + exit 1 + ''}/bin:$PATH\" arion up -d" + ) + machine.succeed( + "export REAL_DOCKER=$(which docker); rm -rf work && cp -frT ${../../examples/minimal} work && cd work && NIX_PATH=nixpkgs='${pkgs.path}' PATH=\"${pkgs.writeScriptBin "docker" '' + #!${pkgs.runtimeShell} -eu + case $1 in + load) + echo 1>&2 "arion must not docker load when upping the same deployment for the second time" + exit 1 + ;; + images) + echo 1>&2 "execing docker to list images" + exec $REAL_DOCKER "$@" + ;; + *) + echo 1>&2 "Unknown docker invocation. This may be a shortcoming of this docker mock." + echo 1>&2 "Invocation: docker" "$@" + ;; + esac + ''}/bin:$PATH\" arion up -d" + ) + machine.wait_until_succeeds("curl --fail localhost:8000") + machine.succeed( + "cd work && NIX_PATH=nixpkgs='${pkgs.path}' arion down" + ) + machine.wait_until_fails("curl --fail localhost:8000") + + # Tests # - examples/flake # This _test_ doesn't work because flake-compat fetches the github