dockerRegistry module: re-init with new underlying software

This commit is contained in:
Robin Gloster 2016-09-18 20:57:01 +02:00
parent 9838b80e91
commit dabcd7d4c8
4 changed files with 112 additions and 2 deletions

View File

@ -235,6 +235,7 @@
./services/misc/dictd.nix
./services/misc/dysnomia.nix
./services/misc/disnix.nix
./services/misc/docker-registry.nix
./services/misc/emby.nix
./services/misc/errbot.nix
./services/misc/etcd.nix

View File

@ -156,7 +156,5 @@ with lib;
"See the 16.09 release notes for more information.")
(mkRemovedOptionModule [ "services" "phpfpm" "phpIni" ] "")
(mkRemovedOptionModule [ "services" "dovecot2" "package" ] "")
(mkRemovedOptionModule [ "services" "dockerRegistry" ]
"docker-registry has been deprecated upstream since a long time.")
];
}

View File

@ -0,0 +1,66 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.dockerRegistry;
in {
options.services.dockerRegistry = {
enable = mkEnableOption "Docker Registry";
listenAddress = mkOption {
description = "Docker registry host or ip to bind to.";
default = "127.0.0.1";
type = types.str;
};
port = mkOption {
description = "Docker registry port to bind to.";
default = 5000;
type = types.int;
};
storagePath = mkOption {
type = types.path;
default = "/var/lib/docker-registry";
description = "Docker registry storage path.";
};
extraConfig = mkOption {
description = ''
Docker extra registry configuration via environment variables.
'';
default = {};
type = types.attrsOf types.str;
};
};
config = mkIf cfg.enable {
systemd.services.docker-registry = {
description = "Docker Container Registry";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
environment = {
REGISTRY_HTTP_ADDR = "${cfg.listenAddress}:${toString cfg.port}";
REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY = cfg.storagePath;
} // cfg.extraConfig;
script = ''
${pkgs.docker-distribution}/bin/registry serve \
${pkgs.docker-distribution.out}/share/go/src/github.com/docker/distribution/cmd/registry/config-example.yml
'';
serviceConfig = {
User = "docker-registry";
WorkingDirectory = cfg.storagePath;
};
};
users.extraUsers.docker-registry = {
createHome = true;
home = cfg.storagePath;
};
};
}

View File

@ -0,0 +1,45 @@
# This test runs docker-registry and check if it works
import ./make-test.nix ({ pkgs, ...} : {
name = "docker-registry";
meta = with pkgs.stdenv.lib.maintainers; {
maintainers = [ globin ];
};
nodes = {
registry = { config, pkgs, ... }: {
services.dockerRegistry.enable = true;
services.dockerRegistry.port = 8080;
services.dockerRegistry.listenAddress = "0.0.0.0";
networking.firewall.allowedTCPPorts = [ 8080 ];
};
client1 = { config, pkgs, ...}: {
virtualisation.docker.enable = true;
virtualisation.docker.socketActivation = false;
virtualisation.docker.extraOptions = "--insecure-registry registry:8080";
};
client2 = { config, pkgs, ...}: {
virtualisation.docker.enable = true;
virtualisation.docker.socketActivation = false;
virtualisation.docker.extraOptions = "--insecure-registry registry:8080";
};
};
testScript = ''
$client1->start();
$client1->waitForUnit("docker.service");
$client1->succeed("tar cv --files-from /dev/null | docker import - scratch");
$client1->succeed("docker tag scratch registry:8080/scratch");
$registry->start();
$registry->waitForUnit("docker-registry.service");
$client1->succeed("docker push registry:8080/scratch");
$client2->start();
$client2->waitForUnit("docker.service");
$client2->succeed("docker pull registry:8080/scratch");
$client2->succeed("docker images | grep scratch");
'';
})