simple test for docker network using reverse proxy

This commit is contained in:
Maximilian Güntner
2020-06-19 19:20:07 +02:00
parent 5ba744be76
commit 0699a82ccb
4 changed files with 51 additions and 8 deletions

1
index.alpha.html Normal file
View File

@@ -0,0 +1 @@
alpha

1
index.bravo.html Normal file
View File

@@ -0,0 +1 @@
bravo

23
nginx.conf Normal file
View File

@@ -0,0 +1,23 @@
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm;
server_name _;
location /alpha {
proxy_pass http://nginx_alpha/index.html;
}
location /bravo {
proxy_pass http://nginx_bravo/index.html;
}
location / {
try_files $uri $uri/ =404;
}
}

View File

@@ -6,6 +6,7 @@ with import <nixpkgs/nixos/lib/testing-python.nix> { inherit system pkgs; };
let
registry = import ./static_registry/default.nix;
nginx_image = registry.nginx.nginx_7d0cdcc60a96;
in
{
mytest = makeTest {
@@ -15,23 +16,40 @@ in
virtualisation.cores = 4;
virtualisation.memorySize = 1024;
foo.bar.enable = true;
docker-containers.nginx = let
image = registry.nginx.nginx_7d0cdcc60a96;
in
docker-networks.web = {
usedBy = [ "nginx_alpha" "nginx_bravo" ];
};
docker-containers.nginx_alpha =
{
image = image.tag;
imageFile = image.image;
image = nginx_image.tag;
imageFile = nginx_image.image;
extraDockerOptions = [ "--network=web" ];
ports = ["8181:80"];
volumes = [
"${./nginx.conf}:/etc/nginx/conf.d/default.conf:ro"
"${./index.alpha.html}:/var/www/html/index.html:ro"
];
};
docker-containers.nginx_bravo =
{
image = nginx_image.tag;
imageFile = nginx_image.image;
extraDockerOptions = [ "--network=web" ];
volumes = [
"${./nginx.conf}:/etc/nginx/conf.d/default.conf:ro"
"${./index.bravo.html}:/var/www/html/index.html:ro"
];
};
};
testScript = ''
machine.start()
machine.wait_for_unit("docker-nginx.service")
machine.wait_for_unit("docker-nginx_alpha.service")
machine.wait_for_unit("docker-nginx_bravo.service")
machine.wait_for_open_port(8181)
machine.wait_until_succeeds("curl http://localhost:8181")
machine.wait_until_succeeds("curl http://localhost:8181 | grep alpha")
machine.wait_until_succeeds("curl http://localhost:8181/bravo | grep bravo")
'';
};
}