Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/github-runner: init at v2.277.1 #116775

Merged
merged 21 commits into from Apr 10, 2021
Merged

nixos/github-runner: init at v2.277.1 #116775

merged 21 commits into from Apr 10, 2021

Conversation

veehaitch
Copy link
Member

Motivation for this change

#101426

Adds GitHub Actions Runner to nixpkgs. Only x86_64-linux is supported right now. The .NET tests are run in the check phase and pass (apart from some online tests).

Required quite a few source patches to make it work with Nix:

  • Tries to obtain the hash of the latest Git commit. Patched out and replaced by passing the rev from fetchFromGitHub to the property GitInfoCommitHash directly.
  • Updates itself if a new release is detected. This cannot be disabled (see Disable runner auto update聽actions/runner#485), hence, it's patched out.
  • Assumes that its root is writable which is not the case for Nix as it resolves to the read-only Nix store. Introduced an environment variable RUNNER_ROOT which allows changing the root directory.
  • Tries to install a systemd service when registering a new runner. Also patched out.
  • The original release also includes Node. Replaced by a symlink to Nix's Node.

The output derivation tries to resemble the structure of the upstream releases where it makes sense. Also, the scripts config.sh and run.sh are fully usable.

Also adds a NixOS module:

  • If any of the options name, url, runnerGroup, extraLabels, tokenFile or its content changes, a registration is triggered.
  • Relies on systemd life cycle management and isolation where possible.

Thanks @Trundle for helping out 馃檹馃徎

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@r-rmcgibbo
Copy link

Result of nixpkgs-review pr 116775 at 73456884 run on x86_64-linux 1

1 package built successfully:
1 suggestion:
  • warning: missing-phase-hooks

    checkPhase should probably contain runHook preCheck and runHook postCheck.

    Near pkgs/development/tools/continuous-integration/github-runner/default.nix:174:3:

        |
    174 |   checkPhase = ''
        |   ^
    

@zowoq zowoq requested a review from zimbatm March 18, 2021 21:45
Adds a parent directory "github-runner/" to all of the systemd lifecycle
directories StateDirectory=, RuntimeDirectory= and LogDirectory=.

Doing this has two motivations:

1. Something like this would required if we want to support multiple
   runners configurations. Please note that this is already possible
   using NixOS containers.
2. Having an additional parent directory makes it easier to remap
   any of the directories. Without a parent, systemd is going to
   complain if, for example, the given StateDirectory= is a symlink.
Changing this option triggers a new runner registration.
'';
example = "nixos";
default = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have testet your PR, work fine so far :-) But get following error if I do not set option name.

error: cannot coerce null to a string

       at /nix/store/rfxj941pv6yf3p2rikhx8wsw3y1q7m34-source/nixos/modules/services/continuous-integration/github-runner.nix:6:18:

            5|   svcName = "github-runner";
            6|   systemdUser = "${svcName}-${cfg.name}";
             |                  ^
            7|   systemdDir = "${svcName}/${cfg.name}";

Looks like hostname is not set as default as described. But maybe I have done something wrong? But after setting name it works fine for me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks! Hopefully this is fixed in 9dcd2ec.

Until now, the runner registration did not set the `--name` argument if
the configuration option was `null`, the default for the option.
According to GitHub's documentation, this instructs the registration
script to use the machine's hostname.

This commit causes the registration to always pass the `--name` argument
to the runner configuration script. The option now defaults to
`networking.hostName` which should be always set on NixOS.

This change becomes necessary as the systemd service name includes the
name of the runner since fcfa809 and, hence, expects it to be set. Thus,
an unset `name` option leads to an error.
Forcing a `name` option to comply with a pattern which could also be
used as a hostname is probably not required by GitHub.
User and group naming restrictions are a complex topic [1] that I don't
even want to touch. Let systemd figure out the username and group and
reference it in our scripts through the USER environment variable.

[1] https://systemd.io/USER_NAMES/
The escaping applied to the subdirectory paths given to StateDirectory=,
RuntimeDirectory= and LogsDirectory= apparently doesn't use the same
strategy that is used to escape unit names (cf. systemd-escape(1)). This
makes it unreasonably hard to construct reliable paths which work for
StateDirectory=/RuntimeDirectory=/LogsDirectory= and ExecStartPre=.

Against this background, I decided to (re-)apply restrictions to the
name a user might give for the GitHub runner. The pattern for
`networking.hostName` seems like a reasonable choice, also as its value
is the default if the `name` option isn't set.

This reverts commit 193ac67.
@domenkozar
Copy link
Member

@veehaitch is this ready?

@veehaitch
Copy link
Member Author

@veehaitch is this ready?

I'd say: yes! I've been using the runner without any issues since opening this PR.

Obviously, there's room for improvement. Mainly support for multiple runner definitions (currently, we can achieve this with containers) and runner registration using a personal access token. I'd suggest, however, to implement those improvements in follow-ups. This PR is pretty big already.

@zimbatm zimbatm merged commit f4af2f2 into NixOS:master Apr 10, 2021
@zimbatm
Copy link
Member

zimbatm commented Apr 10, 2021

sweet!

@mweinelt
Copy link
Member

mweinelt commented Apr 10, 2021

@zimbatm This causes an eval error, because the kerberos attribute isn't passed.

anonymous function at /var/lib/ofborg/checkout/repo/38dca4e3aa6bca43ea96d2fcc04e8229/mr-est/ofborg-evaluator-2/pkgs/development/tools/continuous-integration/github-runner/default.nix:1:1 called without required argument 'kerberos', at /var/lib/ofborg/checkout/repo/38dca4e3aa6bca43ea96d2fcc04e8229/mr-est/ofborg-evaluator-2/lib/customisation.nix:69:16

https://gist.github.com/GrahamcOfBorg/2f92163fa71808194f67a2b60974f5a3

@domenkozar
Copy link
Member

How come CI didn't catch that?

@veehaitch
Copy link
Member Author

dcb501f99325 wasn't included yet in this branch's base

@SuperSandro2000
Copy link
Member

How come CI didn't catch that?

The ofborg results are a week old I think.

@dhess
Copy link
Contributor

dhess commented Apr 10, 2021

Thanks, this is fantastic!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants