Commit bd04f830 authored by Profpatsch's avatar Profpatsch

containers: use createStandaloneDockerImage in postgres

Also sets the correct mode for `/tmp`, which should of course be world-writable.
parent 941ce9ed
......@@ -45,7 +45,7 @@ let
umask 022
# TODO: tmp should probably be a tmpfs volume of some kind
mkdir /tmp
mkdir --mode=777 /tmp
# the user our program is run as
echo "${user}::${uidGidStr}:${uidGidStr}::::" > /etc/passwd
......
......@@ -100,27 +100,26 @@ in {
# configuration for usage on NixOS / with nspawn containers
nixosConfig = {
# TODO
};
# configuration for generating a docker image
# TODO: this is a bit long, refactor!
dockerConfig =
let
dockerCmd = "/bin/postgres";
dockerCmd = "postgres";
dbDir = "/database";
dockerImage =
let
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 {
userName = "postgres";
image = pkgs.helpers.createStandaloneDockerImage {
name = "sangha-postgres";
tag = "unstable";
description = ''
Docker image containing a minimal postgres closure
and an initialized sangha database template in a volume.
'';
# contents of the docker image
contents = [
......@@ -133,7 +132,7 @@ in {
# docker config (see docker image spec)
config = {
User = "postgres";
User = userName;
Cmd = [ dockerCmd ];
Env = [
"PGDATA=${dbDir}"
......@@ -143,26 +142,13 @@ in {
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
rootSetupScript = ''
cp -r "${sanghaInitDatabase}" "./${dbDir}"
chmod --recursive u=rwX,go= "./${dbDir}"
chown --recursive ${uidGidStr}:${uidGidStr} "./${dbDir}"
chown --recursive ${userName}:${userName} "./${dbDir}"
'';
};
in image.overrideAttrs (_: {
meta = { inherit description; };
});
in image;
dockerTest = testing.makeTest {
name = "sangha-postgres-docker-integration-test";
......@@ -191,7 +177,7 @@ in {
. "-D ${dbDir} "
. "-c'data_directory=${dbDir}' "
. "-c'hba_file=/conf/pg_hba.conf' ");
$server->waitForOpenPort(${toString connectionData.Port});
$server->waitForOpenPortTimeout(${toString connectionData.Port}, 10);
$client->succeed('systemd-cat ${pkgs.postgresql}/bin/psql --host=server '
. '--username=${connectionData.User} '
. '--dbname=${connectionData.DbName} '
......
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