diff options
author | John Ericson <John.Ericson@Obsidian.Systems> | 2018-05-03 16:24:30 -0400 |
---|---|---|
committer | John Ericson <John.Ericson@Obsidian.Systems> | 2018-05-03 16:35:36 -0400 |
commit | cf06e42d1cad2732ca23264dee19bbc0d7172b3b (patch) | |
tree | 624d0854c8f07c4d3ba2eb28590076b0486684a3 /nixos/modules/services/misc | |
parent | cbe21ac614285160a18fe21b8a804f3a2f80c51b (diff) | |
parent | b45ef79b74d267891a11c1775a473c610ecebe78 (diff) | |
download | nixlib-cf06e42d1cad2732ca23264dee19bbc0d7172b3b.tar nixlib-cf06e42d1cad2732ca23264dee19bbc0d7172b3b.tar.gz nixlib-cf06e42d1cad2732ca23264dee19bbc0d7172b3b.tar.bz2 nixlib-cf06e42d1cad2732ca23264dee19bbc0d7172b3b.tar.lz nixlib-cf06e42d1cad2732ca23264dee19bbc0d7172b3b.tar.xz nixlib-cf06e42d1cad2732ca23264dee19bbc0d7172b3b.tar.zst nixlib-cf06e42d1cad2732ca23264dee19bbc0d7172b3b.zip |
Merge remote-tracking branch 'upstream/master' into staging
Diffstat (limited to 'nixos/modules/services/misc')
-rw-r--r-- | nixos/modules/services/misc/docker-registry.nix | 97 |
1 files changed, 89 insertions, 8 deletions
diff --git a/nixos/modules/services/misc/docker-registry.nix b/nixos/modules/services/misc/docker-registry.nix index 96ac2a1cf2c9..45931cb42b54 100644 --- a/nixos/modules/services/misc/docker-registry.nix +++ b/nixos/modules/services/misc/docker-registry.nix @@ -5,6 +5,45 @@ with lib; let cfg = config.services.dockerRegistry; + blobCache = if cfg.enableRedisCache + then "redis" + else "inmemory"; + + registryConfig = { + version = "0.1"; + log.fields.service = "registry"; + storage = { + cache.blobdescriptor = blobCache; + filesystem.rootdirectory = cfg.storagePath; + delete.enabled = cfg.enableDelete; + }; + http = { + addr = ":${builtins.toString cfg.port}"; + headers.X-Content-Type-Options = ["nosniff"]; + }; + health.storagedriver = { + enabled = true; + interval = "10s"; + threshold = 3; + }; + }; + + registryConfig.redis = mkIf cfg.enableRedisCache { + addr = "${cfg.redisUrl}"; + password = "${cfg.redisPassword}"; + db = 0; + dialtimeout = "10ms"; + readtimeout = "10ms"; + writetimeout = "10ms"; + pool = { + maxidle = 16; + maxactive = 64; + idletimeout = "300s"; + }; + }; + + configFile = pkgs.writeText "docker-registry-config.yml" (builtins.toJSON (registryConfig // cfg.extraConfig)); + in { options.services.dockerRegistry = { enable = mkEnableOption "Docker Registry"; @@ -27,6 +66,26 @@ in { description = "Docker registry storage path."; }; + enableDelete = mkOption { + type = types.bool; + default = false; + description = "Enable delete for manifests and blobs."; + }; + + enableRedisCache = mkEnableOption "redis as blob cache"; + + redisUrl = mkOption { + type = types.str; + default = "localhost:6379"; + description = "Set redis host and port."; + }; + + redisPassword = mkOption { + type = types.str; + default = ""; + description = "Set redis password."; + }; + extraConfig = mkOption { description = '' Docker extra registry configuration via environment variables. @@ -34,6 +93,19 @@ in { default = {}; type = types.attrsOf types.str; }; + + enableGarbageCollect = mkEnableOption "garbage collect"; + + garbageCollectDates = mkOption { + default = "daily"; + type = types.str; + description = '' + Specification (in the format described by + <citerefentry><refentrytitle>systemd.time</refentrytitle> + <manvolnum>7</manvolnum></citerefentry>) of the time at + which the garbage collect will occur. + ''; + }; }; config = mkIf cfg.enable { @@ -41,15 +113,8 @@ in { 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 + ${pkgs.docker-distribution}/bin/registry serve ${configFile} ''; serviceConfig = { @@ -58,6 +123,22 @@ in { }; }; + systemd.services.docker-registry-garbage-collect = { + description = "Run Garbage Collection for docker registry"; + + restartIfChanged = false; + unitConfig.X-StopOnRemoval = false; + + serviceConfig.Type = "oneshot"; + + script = '' + ${pkgs.docker-distribution}/bin/registry garbage-collect ${configFile} + ${pkgs.systemd}/bin/systemctl restart docker-registry.service + ''; + + startAt = optional cfg.enableGarbageCollect cfg.garbageCollectDates; + }; + users.extraUsers.docker-registry = { createHome = true; home = cfg.storagePath; |