-
Notifications
You must be signed in to change notification settings - Fork 0
WIP: Add garbage collector to docker registry #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
ca7d236
179ef9a
17d348a
db9f58b
ad71bb4
6a8194f
7c31c36
fa65288
ef2fd10
8d05940
384749a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,8 @@ let | |
| }; | ||
| }; | ||
|
|
||
| configFile = pkgs.writeText "docker-registry-config.yml" (builtins.toJSON (registryConfig // cfg.extraConfig)); | ||
|
|
||
| in { | ||
| options.services.dockerRegistry = { | ||
| enable = mkEnableOption "Docker Registry"; | ||
|
|
@@ -95,16 +97,32 @@ in { | |
| default = {}; | ||
| type = types.attrsOf types.str; | ||
| }; | ||
|
|
||
| enableGarbageCollect = mkOption { | ||
| description = "Enable run GarbageCollect automatic every given time."; | ||
| default = false; | ||
| type = types.bool; | ||
| }; | ||
|
|
||
| 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. | ||
| '' | ||
| }; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the indent and the additional closing bracket are obviously broken %) |
||
| }; | ||
| }; | ||
|
|
||
| config = mkIf cfg.enable { | ||
| systemd.services.docker-registry = { | ||
| description = "Docker Container Registry"; | ||
| wantedBy = [ "multi-user.target" ]; | ||
| after = [ "network.target" ]; | ||
| script = let | ||
| configFile = pkgs.writeText "docker-registry-config.yml" (builtins.toJSON (registryConfig // cfg.extraConfig)); | ||
| in '' | ||
| script = '' | ||
| ${pkgs.docker-distribution}/bin/registry serve ${configFile} | ||
| ''; | ||
|
|
||
|
|
@@ -114,6 +132,22 @@ in { | |
| }; | ||
| }; | ||
|
|
||
| systemd.services.docker-registry-garbage-collect = { | ||
| description = "Run Garbage Collection for docker registry"; | ||
|
|
||
| restartIfChange = false; | ||
| unitConfig.X-StopOnRemoval = false; | ||
|
|
||
| serviceConfig.Type = "oneshot"; | ||
|
|
||
| script = '' | ||
| ${pkgs.docker-distribution}/bin/registry garbage-collect ${configFile} | ||
| ${lib.optionalString enableRedisCache '${pkgs.systemd}/bin/systemctl restart docker-registry'} | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. single quotes won't work as single quotes can be part of variable names. |
||
| ''; | ||
|
|
||
| startAt = optional cfg.enableGarbageCollect cfg.garbageCollectDates; | ||
| }; | ||
|
|
||
| users.extraUsers.docker-registry = { | ||
| createHome = true; | ||
| home = cfg.storagePath; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |
| import ./make-test.nix ({ pkgs, ...} : { | ||
| name = "docker-registry"; | ||
| meta = with pkgs.stdenv.lib.maintainers; { | ||
| maintainers = [ globin ma27 ]; | ||
| maintainers = [ globin ma27 ironpinguin ]; | ||
| }; | ||
|
|
||
| nodes = { | ||
|
|
@@ -43,7 +43,15 @@ import ./make-test.nix ({ pkgs, ...} : { | |
| $client2->succeed("docker images | grep scratch"); | ||
|
|
||
| $client2->succeed( | ||
| 'curl -fsS -X DELETE registry:8080/v2/scratch/manifests/$(curl registry:8080/v2/scratch/manifests/latest | jq ".fsLayers[0].blobSum" | sed -e \'s/"//g\')' | ||
| 'curl -fsS -X DELETE registry:8080/v2/scratch/manifests/$(curl -fsS -I -H"Accept: application/vnd.docker.distribution.manifest.v2+json" registry:8080/v2/scratch/manifests/latest | grep Docker-Content | sed -e\'Docker-Content-Digest: //\' | tr -d \'\r\')' | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't remember exactly how the JSON looked like, however I think that a solution with
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a example to see it better: All 3 digests are also blobs:
|
||
| ); | ||
|
|
||
| $registry->succeed("systemctl start docker-registry-garbage-collect"); | ||
| $registry->waitForUnit("docker-registry.service"); | ||
|
|
||
| $registry->fail("ls store/docker/registry/v2/blobs/sha256/**/data"); | ||
|
|
||
| $client1->succeed("docker push registry:8080/scratch"); | ||
| $registry->succeed("ls store/docker/registry/v2/blobs/sha256/**/data"); | ||
| ''; | ||
| }) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you might want to have a look at
mkEnableOption