Test and fix that we only load images when needed
This commit is contained in:
parent
9dd1ab0568
commit
dcc5b1e3ce
2 changed files with 43 additions and 1 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue