Commit 44d3d841 authored by Profpatsch's avatar Profpatsch

containers/postgres: docker image integration test first try

Litte VM test; the connection from the client still fails (because the
authorization config of postgres is not yet included).
parent 210f516c
......@@ -40,4 +40,5 @@ in {
downloads.dockerImages = {
sangha.postgres = sanghaPostgresDockerImage;
};
tests = eval.config.tests;
}
{ lib, pkgs, config, ... }:
{ lib, pkgs, config, testing, ... }:
let
# set database connection values
......@@ -149,64 +149,92 @@ in {
};
# configuration for generating a docker image
dockerConfig = {
generated.dockerImages.sanghaPostgres =
let
dbDir = "/database";
# TODO: this is a bit long, refactor!
dockerConfig =
let
dockerImage =
let
dbDir = "/database";
uidGid = 999;
uidGidStr = toString uidGid;
description = ''
Docker image containing a minimal postgres closure
and an initialized sangha database template in a volume.
'';
image = pkgs.dockerTools.buildImage {
name = "sangha-postgres";
tag = "unstable";
# contents of the docker image
contents = [
# the complete postgresql closure with all deps
pkgs.postgresql
# needed locales (localdb)
(prependPrefix "/usr" localeFiles)
];
# docker config (see docker image spec)
config = {
User = "postgres";
Cmd = [ "/bin/postgres" ];
Env = [
"PGDATA=${dbDir}"
];
ExposedPorts."${toString connectionData.Port}/tcp" = {};
# we create a volume so the db is persistent over restarts
Volumes."${dbDir}" = {};
description = ''
Docker image containing a minimal postgres closure
and an initialized sangha database template in a volume.
'';
image = pkgs.dockerTools.buildImage {
name = "sangha-postgres";
tag = "unstable";
# contents of the docker image
contents = [
# the complete postgresql closure with all deps
pkgs.postgresql
# needed locales (localdb)
(prependPrefix "/usr" localeFiles)
];
# docker config (see docker image spec)
config = {
User = "postgres";
Cmd = [ "/bin/postgres" ];
Env = [
"PGDATA=${dbDir}"
];
ExposedPorts."${toString connectionData.Port}/tcp" = {};
# we create a volume so the db is persistent over restarts
Volumes."${dbDir}" = {};
};
runAsRoot = ''
${pkgs.stdenv.shell}
${pkgs.dockerTools.shadowSetup}
# some needed system structure
umask 000
mkdir /tmp
echo "postgres::${uidGidStr}:${uidGidStr}::::" > /etc/passwd
echo "127.0.0.1 localhost" > /etc/hosts
echo "hosts: files" > /etc/nsswitch.conf
# postgres setup
cp -r "${sanghaInitDatabase}" "./${dbDir}"
chmod --recursive u=rwX,go= "./${dbDir}"
chown --recursive ${uidGidStr}:${uidGidStr} "./${dbDir}"
'';
};
in image.overrideAttrs (_: {
meta = { inherit description; };
});
dockerTest = testing.makeTest {
name = "sangha-postgres-docker-integration-test";
nodes = {
server = {...}: {
virtualisation.docker.enable = true;
networking.firewall.enable = false;
};
client = {
# TODO
};
};
runAsRoot = ''
${pkgs.stdenv.shell}
${pkgs.dockerTools.shadowSetup}
# some needed system structure
umask 000
mkdir /tmp
echo "postgres::${uidGidStr}:${uidGidStr}::::" > /etc/passwd
echo "127.0.0.1 localhost" > /etc/hosts
echo "hosts: files" > /etc/nsswitch.conf
# postgres setup
cp -r "${sanghaInitDatabase}" "./${dbDir}"
chmod --recursive u=rwX,go= "./${dbDir}"
chown --recursive ${uidGidStr}:${uidGidStr} "./${dbDir}"
'';
testScript =
let image = config.generated.dockerImages.sanghaPostgres;
in ''
startAll;
$server->waitForUnit("docker.service");
$server->succeed("docker load -i ${image}");
$server->succeed("docker run --detach=true --network=host ${image.imageName}:${image.imageTag}");
$server->waitForOpenPort(${toString connectionData.Port});
$client->execute("echo 'trying to connect to postgres docker server'");
$client->succeed("${pkgs.telnet}/bin/telnet server");
'';
};
in image.overrideAttrs (_: {
meta = { inherit description; };
});
};
in {
generated.dockerImages.sanghaPostgres = dockerImage;
tests.dockerImages.sanghaPostgres = dockerTest;
};
in
let
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment