Merge pull request #195488 from KoviRobi/gitlab-runner-clear-docker-cache

Gitlab runner clear docker cache

authored by Pascal Bach and committed by GitHub 1ca4c178 93a795a5

+61 -1
+53
nixos/modules/services/continuous-integration/gitlab-runner.nix
··· 453 453 }; 454 454 }); 455 455 }; 456 + clear-docker-cache = { 457 + enable = mkOption { 458 + type = types.bool; 459 + default = false; 460 + description = lib.mdDoc '' 461 + Whether to periodically prune gitlab runner's Docker resources. If 462 + enabled, a systemd timer will run {command}`clear-docker-cache` as 463 + specified by the `dates` option. 464 + ''; 465 + }; 466 + 467 + flags = mkOption { 468 + type = types.listOf types.str; 469 + default = [ ]; 470 + example = [ "prune" ]; 471 + description = lib.mdDoc '' 472 + Any additional flags passed to {command}`clear-docker-cache`. 473 + ''; 474 + }; 475 + 476 + dates = mkOption { 477 + default = "weekly"; 478 + type = types.str; 479 + description = lib.mdDoc '' 480 + Specification (in the format described by 481 + {manpage}`systemd.time(7)`) of the time at 482 + which the prune will occur. 483 + ''; 484 + }; 485 + 486 + package = mkOption { 487 + default = config.virtualisation.docker.package; 488 + defaultText = literalExpression "config.virtualisation.docker.package"; 489 + example = literalExpression "pkgs.docker"; 490 + description = lib.mdDoc "Docker package to use for clearing up docker cache."; 491 + }; 492 + }; 456 493 }; 457 494 config = mkIf cfg.enable { 458 495 warnings = (mapAttrsToList ··· 496 533 KillSignal = "SIGQUIT"; 497 534 KillMode = "process"; 498 535 }; 536 + }; 537 + # Enable periodic clear-docker-cache script 538 + systemd.services.gitlab-runner-clear-docker-cache = { 539 + description = "Prune gitlab-runner docker resources"; 540 + restartIfChanged = false; 541 + unitConfig.X-StopOnRemoval = false; 542 + 543 + serviceConfig.Type = "oneshot"; 544 + 545 + path = [ cfg.clear-docker-cache.package pkgs.gawk ]; 546 + 547 + script = '' 548 + ${pkgs.gitlab-runner}/bin/clear-docker-cache ${toString cfg.clear-docker-cache.flags} 549 + ''; 550 + 551 + startAt = optional cfg.clear-docker-cache.enable cfg.clear-docker-cache.dates; 499 552 }; 500 553 # Enable docker if `docker` executor is used in any service 501 554 virtualisation.docker.enable = mkIf (
+8 -1
pkgs/development/tools/continuous-integration/gitlab-runner/default.nix
··· 1 - { lib, buildGoModule, fetchFromGitLab, fetchurl }: 1 + { lib, buildGoModule, fetchFromGitLab, fetchurl, bash }: 2 2 3 3 let 4 4 version = "15.4.0"; ··· 13 13 "-X ${commonPackagePath}.VERSION=${version}" 14 14 "-X ${commonPackagePath}.REVISION=v${version}" 15 15 ]; 16 + 17 + # For patchShebangs 18 + buildInputs = [ bash ]; 16 19 17 20 vendorSha256 = "sha256-S0x1b2ITtqMoqdssoTgnolDC6Tyq3IdkJqxwZ29qCyU="; 18 21 ··· 43 46 rm executors/docker/terminal_test.go 44 47 rm executors/docker/docker_test.go 45 48 rm helpers/docker/auth/auth_test.go 49 + ''; 50 + 51 + postInstall = '' 52 + install packaging/root/usr/share/gitlab-runner/clear-docker-cache $out/bin 46 53 ''; 47 54 48 55 preCheck = ''