nixos/gitlab-runner: add more global options (#86946)

authored by misuzu.tngl.sh and committed by GitHub fc9f994e 6e465444

+77 -6
+77 -6
nixos/modules/services/continuous-integration/gitlab-runner.nix
··· 1 1 { config, lib, pkgs, ... }: 2 + with builtins; 2 3 with lib; 3 4 let 4 5 cfg = config.services.gitlab-runner; 5 6 hasDocker = config.virtualisation.docker.enable; 6 - hashedServices = with builtins; (mapAttrs' (name: service: nameValuePair 7 - "${name}_${config.networking.hostName}_${ 7 + hashedServices = mapAttrs' 8 + (name: service: nameValuePair 9 + "${name}_${config.networking.hostName}_${ 8 10 substring 0 12 9 11 (hashString "md5" (unsafeDiscardStringContext (toJSON service)))}" 10 12 service) 11 - cfg.services); 13 + cfg.services; 12 14 configPath = "$HOME/.gitlab-runner/config.toml"; 13 15 configureScript = pkgs.writeShellScriptBin "gitlab-runner-configure" ( 14 16 if (cfg.configFile != null) then '' ··· 76 78 ++ map (v: "--docker-allowed-images ${escapeShellArg v}") service.dockerAllowedImages 77 79 ++ map (v: "--docker-allowed-services ${escapeShellArg v}") service.dockerAllowedServices 78 80 ) 79 - ))} && sleep 1 81 + ))} && sleep 1 || exit 1 80 82 fi 81 83 '') hashedServices)} 82 84 ··· 89 91 90 92 # update global options 91 93 remarshal --if toml --of json ${configPath} \ 92 - | jq -cM '.check_interval = ${toString cfg.checkInterval} | 93 - .concurrent = ${toString cfg.concurrent}' \ 94 + | jq -cM ${escapeShellArg (concatStringsSep " | " [ 95 + ".check_interval = ${toJSON cfg.checkInterval}" 96 + ".concurrent = ${toJSON cfg.concurrent}" 97 + ".sentry_dsn = ${toJSON cfg.sentryDSN}" 98 + ".listen_address = ${toJSON cfg.prometheusListenAddress}" 99 + ".session_server.listen_address = ${toJSON cfg.sessionServer.listenAddress}" 100 + ".session_server.advertise_address = ${toJSON cfg.sessionServer.advertiseAddress}" 101 + ".session_server.session_timeout = ${toJSON cfg.sessionServer.sessionTimeout}" 102 + "del(.[] | nulls)" 103 + "del(.session_server[] | nulls)" 104 + ])} \ 94 105 | remarshal --if json --of toml \ 95 106 | sponge ${configPath} 96 107 ··· 139 150 Limits how many jobs globally can be run concurrently. 140 151 The most upper limit of jobs using all defined runners. 141 152 0 does not mean unlimited. 153 + ''; 154 + }; 155 + sentryDSN = mkOption { 156 + type = types.nullOr types.str; 157 + default = null; 158 + example = "https://public:private@host:port/1"; 159 + description = '' 160 + Data Source Name for tracking of all system level errors to Sentry. 161 + ''; 162 + }; 163 + prometheusListenAddress = mkOption { 164 + type = types.nullOr types.str; 165 + default = null; 166 + example = "localhost:8080"; 167 + description = '' 168 + Address (&lt;host&gt;:&lt;port&gt;) on which the Prometheus metrics HTTP server 169 + should be listening. 170 + ''; 171 + }; 172 + sessionServer = mkOption { 173 + type = types.submodule { 174 + options = { 175 + listenAddress = mkOption { 176 + type = types.nullOr types.str; 177 + default = null; 178 + example = "0.0.0.0:8093"; 179 + description = '' 180 + An internal URL to be used for the session server. 181 + ''; 182 + }; 183 + advertiseAddress = mkOption { 184 + type = types.nullOr types.str; 185 + default = null; 186 + example = "runner-host-name.tld:8093"; 187 + description = '' 188 + The URL that the Runner will expose to GitLab to be used 189 + to access the session server. 190 + Fallbacks to <option>listenAddress</option> if not defined. 191 + ''; 192 + }; 193 + sessionTimeout = mkOption { 194 + type = types.int; 195 + default = 1800; 196 + description = '' 197 + How long in seconds the session can stay active after 198 + the job completes (which will block the job from finishing). 199 + ''; 200 + }; 201 + }; 202 + }; 203 + default = { }; 204 + example = literalExample '' 205 + { 206 + listenAddress = "0.0.0.0:8093"; 207 + } 208 + ''; 209 + description = '' 210 + The session server allows the user to interact with jobs 211 + that the Runner is responsible for. A good example of this is the 212 + <link xlink:href="https://docs.gitlab.com/ee/ci/interactive_web_terminal/index.html">interactive web terminal</link>. 142 213 ''; 143 214 }; 144 215 gracefulTermination = mkOption {