Commit f7f893cf authored by Valentin Reis's avatar Valentin Reis
Browse files

fixed the gitlab runner. this uses adrian van putten's code.

parent 115cb97b
No preview for this file type
......@@ -232,6 +232,8 @@ in
deployment.targetEnv = "none";
deployment.targetHost = "140.221.10.9";
imports = [ ./gitlab-runner.nix];
time.timeZone = "America/Chicago";
deployment.keys."id_buildfarm" = {
......@@ -242,6 +244,14 @@ in
permissions = "600";
};
deployment.keys."gitlab.cfg" = {
destDir = "/run";
keyFile = ./gitlab.cfg.secret;
user = "fre";
group = "users";
permissions = "600";
};
systemd.services.tunnel-hydra= {
path = [pkgs.autossh];
enable= true;
......@@ -275,25 +285,34 @@ in
services.ntp.enable = false;
services.openssh.allowSFTP = false;
environment.systemPackages = [ pkgs.git ];
virtualisation.docker.enable = true;
services.gitlab-runner = {
enable = true;
configOptions = {
concurrent = 2;
runners = [ { builds_dir = "";
docker = { cache_dir = "";
disable_cache = true;
host = "";
image = "nixos/nix:2.1.3"; privileged = true;
};
executor = "docker";
name = "docker-nix-2.1.3";
token = pkgs.lib.removeSuffix "\n" (builtins.readFile ./gitlab_token.secret);
url = "https://xgitlab.cels.anl.gov/";
}];
};
};
services.gitlab-runner2.enable = true;
services.gitlab-runner2.registrationConfigFile = "/run/gitlab.cfg";
services.gitlab-runner2.packages = [pkgs.bash pkgs.docker-machine pkgs.shadow pkgs.git];
#services.gitlab-runner = {
#enable = true;
#packages = [ pkgs.bash pkgs.docker-machine pkgs.shadow];
#configFile = ./gitlab-ci.toml;
#configOptions = {
#concurrent = 2;
#runners = [ { builds_dir = "";
#docker = { cache_dir = "";
#disable_cache = true;
#host = "";
#image = "nixos/nix:2.1.3";
#privileged = true;
#};
#executor = "docker";
#name = "docker-nix-2.1.3";
#token = pkgs.lib.removeSuffix "\n" (builtins.readFile ./gitlab_token.secret);
#url = "https://xgitlab.cels.anl.gov/";
#}];
#};
#};
nix.gc = {
automatic = true;
......
/*
* An opinonated Gitlab-runner, that allows for nix builds (with caching)
* on NixOS build machines
*/
{ config, pkgs, lib, ...}:
with lib;
let
cfg = config.services.gitlab-runner2;
setupContainer = pkgs.writeScriptBin "setup-container" ''
'';
in
{
options.services.gitlab-runner2 = {
enable = lib.mkEnableOption "Gitlab Runner";
registrationConfigFile = lib.mkOption {
description = ''
Configuration file used got gitlab-runner registration.
It is a list of environment variables.
A list of all supported environment variables can be found
in
gitlab-runner register --help
One that you probably want to set is
CI_SERVER_URL=<CI server URL>
REGISTRATION_TOKEN=<registration secret>
'';
type = lib.types.path;
};
gracefulTermination = mkOption {
default = false;
type = types.bool;
description = ''
Finish all remaining jobs before stopping, restarting or reconfiguring.
If not set gitlab-runner will stop immediatly without waiting for jobs to finish,
which will lead to failed builds.
'';
};
gracefulTimeout = mkOption {
default = "infinity";
type = types.str;
example = "5min 20s";
description = ''Time to wait until a graceful shutdown is turned into a forceful one.'';
};
workDir = mkOption {
default = "/var/lib/gitlab-runner";
type = types.path;
description = "The working directory used";
};
package = mkOption {
description = "Gitlab Runner package to use";
default = pkgs.gitlab-runner;
defaultText = "pkgs.gitlab-runner";
type = types.package;
example = literalExample "pkgs.gitlab-runner_1_11";
};
packages = mkOption {
default = [ pkgs.bash pkgs.docker-machine ];
defaultText = "[ pkgs.bash pkgs.docker-machine ]";
type = types.listOf types.package;
description = ''
Packages to add to PATH for the gitlab-runner process.
'';
};
};
config = mkIf cfg.enable {
systemd.services.gitlab-runner2 = {
path = cfg.packages;
environment = config.networking.proxy.envVars;
description = "Gitlab Runner";
after = [ "network.target" "docker.service"];
requires = ["docker.service"];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
EnvironmentFile = "${cfg.registrationConfigFile}";
ExecStartPre = ''${cfg.package.bin}/bin/gitlab-runner register \
--non-interactive=true \
--name gitlab-runner \
--executor "shell" \
--env "PATH=/home/fre/bin:/run/wrappers/bin:/etc/profiles/per-user/fre/bin:/home/fre/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin" \
--pre-build-script "${setupContainer}/bin/setup-container" \
'';
ExecStart = ''${cfg.package.bin}/bin/gitlab-runner run \
--working-directory ${cfg.workDir} \
--service gitlab-runner \
'';
#--user gitlab-runner \
ExecStopPost = ''${cfg.package.bin}/bin/gitlab-runner unregister \
--name gitlab-runner
'';
} // optionalAttrs (cfg.gracefulTermination) {
TimeoutStopSec = "${cfg.gracefulTimeout}";
KillSignal = "SIGQUIT";
KillMode = "process";
};
};
virtualisation.docker.enable = true;
# Make the gitlab-runner command availabe so users can query the runner
environment.systemPackages = [ cfg.package ];
users.users.gitlab-runner = {
group = "gitlab-runner";
extraGroups = ["docker"];
uid = config.ids.uids.gitlab-runner;
home = cfg.workDir;
createHome = true;
};
users.groups.gitlab-runner.gid = config.ids.gids.gitlab-runner;
};
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment