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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/gitea-actions-runner: init #228422

Merged
merged 1 commit into from
May 12, 2023

Conversation

mweinelt
Copy link
Member

@mweinelt mweinelt commented Apr 26, 2023

Description of changes

Module to set up gitea-action-runner instances.

https://blog.gitea.io/2023/03/hacking-on-gitea-actions/

Tested against Forgejo 1.19.1 using the token option. The runner by default wants to connect to a docker instance, but I was able to substitute that with the compatible podman socket.

Untested, but assumed maybe working:

  • tokenFile option
  • Multiple runners
  • Docker
Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 23.05 Release Notes (or backporting 22.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Apr 26, 2023
@mweinelt mweinelt force-pushed the gitea-actions-runner-module branch from 75618bc to 1023382 Compare April 26, 2023 23:48
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 labels Apr 27, 2023
@mweinelt mweinelt force-pushed the gitea-actions-runner-module branch 3 times, most recently from 4566198 to fa83a92 Compare April 27, 2023 10:53
@mweinelt mweinelt force-pushed the gitea-actions-runner-module branch from fa83a92 to f314914 Compare April 27, 2023 11:15
@mweinelt mweinelt force-pushed the gitea-actions-runner-module branch 2 times, most recently from 1b7ebc1 to fcc964e Compare April 27, 2023 20:02
@mweinelt mweinelt force-pushed the gitea-actions-runner-module branch 3 times, most recently from 95dc0a0 to ff2372e Compare April 27, 2023 22:00
@Kranzes
Copy link
Member

Kranzes commented Apr 27, 2023

Is it possible to make a NixOS VM test for this?

@mweinelt
Copy link
Member Author

mweinelt commented Apr 27, 2023

If you know how to programmatically retrieve a runner registration token from a gitea instance. Not keen on mocking the gitea API.

@Kranzes
Copy link
Member

Kranzes commented Apr 28, 2023

If you know how to programmatically retrieve a runner registration token from a gitea instance. Not keen on mocking the gitea API.

go-gitea/gitea#23762

I guess we could start by running a test that checks runner registration. A test that actually tries to build something might be more difficult as that requires networking and other weird stuff...

@Kranzes
Copy link
Member

Kranzes commented Apr 28, 2023

Apparently using docker/podman is optional.

@mweinelt
Copy link
Member Author

If you know how to programmatically retrieve a runner registration token from a gitea instance. Not keen on mocking the gitea API.

go-gitea/gitea#23762

I guess we could start by running a test that checks runner registration. A test that actually tries to build something might be more difficult as that requires networking and other weird stuff...

Only in 1.20, didn't get backported into 1.19.

@mweinelt
Copy link
Member Author

mweinelt commented Apr 28, 2023

Have a draft for the test in the linked PR, that we can look into, once 1.20 is out.

@emilylange
Copy link
Member

Looks good at first glance :)

I thought about suggesting lib.optional instead of lib.optionals, but honestly, lib.optionals looks just way better :^)

Unfortunately, I don't think I'll be able to dedicate any time to do proper in-depth tests over the next few days, as I am busy with a lot of other stuff.

But I also don't want to block this PR, so eeehhh go ahead I guess?

@Kranzes
Copy link
Member

Kranzes commented Apr 29, 2023

So when someone has docker/podman enabled in their system config this module will act differently than if they have them disabled, what if someone has docker/podman enabled but doesn't actually want to use it with gitea runner and instead use native runner? Right now what will happen is that gitea runner will be configured slightly differently and the systemd service will have to wait for docker/podman.

@mweinelt mweinelt force-pushed the gitea-actions-runner-module branch from a4b56e6 to ed1f9da Compare April 29, 2023 14:06
@mweinelt mweinelt force-pushed the gitea-actions-runner-module branch from ed1f9da to 253cb34 Compare April 30, 2023 00:42
Copy link
Member

@emilylange emilylange left a comment

Choose a reason for hiding this comment

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

Had a first proper look.
This is what I got so far.

Will try to test more later today or this week :)

@mweinelt mweinelt force-pushed the gitea-actions-runner-module branch from 253cb34 to c6e1c9c Compare May 2, 2023 16:59
@mweinelt mweinelt force-pushed the gitea-actions-runner-module branch 2 times, most recently from 406b883 to fa50c96 Compare May 2, 2023 22:57
@mweinelt
Copy link
Member Author

mweinelt commented May 2, 2023

Updating the labels against the gitea/forgejo instance requires getting a new registration token and dropping the runner config.

Guess we need to account for that.

@emilylange
Copy link
Member

Not sure how we should compare the labels and re-register based on that, as it involves state.

The .runner contains the labels from registration-time, but I feel like there is a high probability the format of it will change in the future:

$ jq .labels /var/lib/gitea-runner/test/.runner
[
  "ubuntu-latest:docker://node:16-bullseye",
  "ubuntu-22.04:docker://node:16-bullseye",
  "ubuntu-20.04:docker://node:16-bullseye",
  "ubuntu-18.04:docker://node:16-buster"
]

Additionally, there are custom labels, that can be configured in the runner registration page.
They are a bit weird, IMHO.
https://blog.gitea.io/2023/03/hacking-on-gitea-actions/#what-is-the-difference-between-agent-labels-and-custom-labels-for-a-runner
Just mentioning for reference and not because we should do anything to handle them.

@mweinelt mweinelt force-pushed the gitea-actions-runner-module branch from fa50c96 to d712216 Compare May 3, 2023 13:53
@mweinelt
Copy link
Member Author

mweinelt commented May 3, 2023

Also accounting for label changes now, in which case I purge the existing registration to make the runner fail, as a new token needs to be inserted, to apply the labels.

Lastly we should probably talk about the proper runtime environments, that users will want to have, so that actions like checkout, cachix/install-nix-action, etc. will work.

One idea was to provide an image based on https://github.com/nix-community/docker-nixpkgs, that includes e.g. bash and nodejs. Really wondering how feasible that is. There is an open issue for arm64 support, as currently all provided images are x86_64-only.

@mweinelt mweinelt force-pushed the gitea-actions-runner-module branch from d712216 to eae126b Compare May 6, 2023 13:26
@mweinelt mweinelt force-pushed the gitea-actions-runner-module branch from eae126b to 4f50fd5 Compare May 6, 2023 14:03
@mweinelt
Copy link
Member Author

mweinelt commented May 6, 2023

I think I covered all remaining issues for now.

Copy link
Member

@emilylange emilylange left a comment

Choose a reason for hiding this comment

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

Did a final test run of the current version.
Works great :)

Except native:host 😅

Not blocking.

Comment on lines 118 to 119
Many common actions require bash or nodejs, as well as a filesystem
that follows the filesystem hierarchy standard.
Copy link
Member

Choose a reason for hiding this comment

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

Just a comment/pointer for other reviewers:

An example where FHS is hardcoded is
https://gitea.com/gitea/act/src/commit/a18648ee7359dbff7a8d3f022270874b840039fa/pkg/runner/run_context.go#L306

The original act repo on GitHub, on the other hand, does not hardcode it :'(
https://github.com/nektos/act/blob/aa212773804561eaee04c3b4a7d9399dfbb9cad1/pkg/runner/run_context.go#L273

@mweinelt mweinelt force-pushed the gitea-actions-runner-module branch 2 times, most recently from ebf01cc to afee6e8 Compare May 6, 2023 15:25
@mweinelt mweinelt force-pushed the gitea-actions-runner-module branch from afee6e8 to 1c963ce Compare May 6, 2023 15:34
@mweinelt mweinelt added this to the 23.05 milestone May 6, 2023
@mweinelt mweinelt merged commit 1c80c49 into NixOS:master May 12, 2023
@mweinelt mweinelt deleted the gitea-actions-runner-module branch May 12, 2023 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: changelog 8.has: documentation 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants