-
-
Save NeQuissimus/a902ce4192f24877b8c78b1bdde7e7c2 to your computer and use it in GitHub Desktop.
VM test for reproducing https://github.com/NixOS/nixpkgs/issues/30289
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let | |
dockerConfig = { pkgs, ... }: { | |
virtualisation.docker.enable = true; | |
virtualisation.docker.package = pkgs.docker; | |
virtualisation.docker.liveRestore = false; | |
}; | |
dockerImage = { | |
name = "rabbitmq:3.6.12-management"; | |
hash = "bcdfca2f591e9d8e88d4002305b480b036e4b9a1ab26b517e853446f2d20b815"; | |
}; | |
imageSpec = with dockerImage; "${name}@sha256:${hash}"; in import <nixpkgs/nixos/tests/make-test.nix> { | |
name = "docker-swarm"; | |
machine = { config, lib, pkgs, ... }: let | |
saved-image = (import <nixpkgs/nixos/lib/testing.nix> { | |
inherit (config.nixpkgs) system; | |
}).runInMachine { | |
drv = pkgs.runCommand "docker-image" { | |
outputHashAlgo = "sha256"; | |
outputHash = "1jy0pb38d4fbbr3sh9y74x4gqrvbd3kppwhwyg8w3xxyfzdfb27z"; | |
outputHashMode = "recursive"; | |
nativeBuildInputs = [ pkgs.docker ]; | |
} '' | |
docker pull ${imageSpec} | |
docker save ${imageSpec} > "$out/image.tar" | |
''; | |
machine = dockerConfig; | |
}; | |
in { | |
system.build.saved-image = saved-image; | |
imports = [ dockerConfig ]; | |
}; | |
testScript = { nodes, ... }: let | |
inherit (nodes.machine.config.networking) primaryIPAddress; | |
inherit (nodes.machine.config.system.build) saved-image; | |
in '' | |
$machine->waitForUnit('multi-user.target'); | |
$machine->succeed( | |
'docker swarm init --advertise-addr=${primaryIPAddress}', | |
'docker network create ci -d overlay', | |
'docker load -i ${saved-image}/image.tar', | |
'docker tag "$(docker images --format "{{.ID}}")" rabbit:test', | |
); | |
$machine->succeed('docker service create --name rabbit --detach=false '. | |
'--no-resolve-image '. | |
'-p 15672:15672 "rabbit:test"'); | |
$machine->waitUntilSucceeds('curl http://127.0.0.1:15672/ >&2'); | |
''; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
docker service does not like image IDs, so we need to tag it first.
Also, the resolution towards the Docker Registry was annoying, so I turned that off.
Finally, it is actually important to pull a x.y.z-management tag because only those start the web interface on 15672